1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-07 05:36:45 +02:00

Undo this LocalSocket fiasco, fix tests for latest phpunit

This commit is contained in:
Jordi Boggiano
2016-09-25 16:07:01 +02:00
parent 3dc7a79a3e
commit 28742b656f
17 changed files with 456 additions and 459 deletions

View File

@@ -14,7 +14,6 @@ namespace Monolog\Handler;
use Monolog\Formatter\FlowdockFormatter;
use Monolog\Test\TestCase;
use Monolog\Logger;
use Monolog\Util\LocalSocket;
/**
* @author Dominik Liebler <liebler.dominik@gmail.com>
@@ -41,9 +40,10 @@ class FlowdockHandlerTest extends TestCase
public function testWriteHeader()
{
$this->initHandlerAndSocket();
$this->createHandler();
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
$content = $this->socket->getOutput();
fseek($this->res, 0);
$content = fread($this->res, 1024);
$this->assertRegexp('/POST \/v1\/messages\/team_inbox\/.* HTTP\/1.1\\r\\nHost: api.flowdock.com\\r\\nContent-Type: application\/json\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content);
@@ -53,27 +53,35 @@ class FlowdockHandlerTest extends TestCase
/**
* @depends testWriteHeader
*/
public function testWriteContent(string $content)
public function testWriteContent($content)
{
$this->assertRegexp('/"source":"test_source"/', $content);
$this->assertRegexp('/"from_address":"source@test\.com"/', $content);
}
private function initHandlerAndSocket($token = 'myToken')
private function createHandler($token = 'myToken')
{
$this->socket = LocalSocket::initSocket();
$this->handler = new FlowdockHandler($token);
$constructorArgs = [$token, Logger::DEBUG];
$this->res = fopen('php://memory', 'a');
$this->handler = $this->getMockBuilder('Monolog\Handler\FlowdockHandler')
->setConstructorArgs($constructorArgs)
->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket'])
->getMock();
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, '127.0.0.1:51984');
$reflectionProperty->setValue($this->handler, 'localhost:1234');
$this->handler->expects($this->any())
->method('fsockopen')
->will($this->returnValue($this->res));
$this->handler->expects($this->any())
->method('streamSetTimeout')
->will($this->returnValue(true));
$this->handler->expects($this->any())
->method('closeSocket')
->will($this->returnValue(true));
$this->handler->setFormatter(new FlowdockFormatter('test_source', 'source@test.com'));
}
public function tearDown()
{
unset($this->socket, $this->handler);
}
}