mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-07 05:36:45 +02:00
Fix lower tests
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.0",
|
"php": "^7.0",
|
||||||
"psr/log": "^1.0"
|
"psr/log": "^1.0.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^5.5",
|
"phpunit/phpunit": "^5.5",
|
||||||
@@ -28,7 +28,8 @@
|
|||||||
"php-console/php-console": "^3.1.3",
|
"php-console/php-console": "^3.1.3",
|
||||||
"jakub-onderka/php-parallel-lint": "^0.9",
|
"jakub-onderka/php-parallel-lint": "^0.9",
|
||||||
"symfony/process": "^3.1",
|
"symfony/process": "^3.1",
|
||||||
"predis/predis": "^1.1"
|
"predis/predis": "^1.1",
|
||||||
|
"phpspec/prophecy": "^1.6.1"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
|
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
|
||||||
|
@@ -40,10 +40,9 @@ class FlowdockHandlerTest extends TestCase
|
|||||||
|
|
||||||
public function testWriteHeader()
|
public function testWriteHeader()
|
||||||
{
|
{
|
||||||
$this->createHandler();
|
$this->initHandlerAndSocket();
|
||||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
|
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
|
||||||
fseek($this->res, 0);
|
$content = $this->closeSocket();
|
||||||
$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);
|
$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);
|
||||||
|
|
||||||
@@ -59,29 +58,52 @@ class FlowdockHandlerTest extends TestCase
|
|||||||
$this->assertRegexp('/"from_address":"source@test\.com"/', $content);
|
$this->assertRegexp('/"from_address":"source@test\.com"/', $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createHandler($token = 'myToken')
|
|
||||||
|
private function initHandlerAndSocket($token = 'myToken')
|
||||||
{
|
{
|
||||||
$this->res = fopen('php://memory', 'a');
|
$tmpFile = sys_get_temp_dir().'/monolog-test-socket.php';
|
||||||
$this->handler = $this->prophesize('Monolog\Handler\FlowdockHandler');
|
file_put_contents($tmpFile, <<<'SCRIPT'
|
||||||
|
<?php
|
||||||
|
|
||||||
$this->handler = new class($token, Logger::DEBUG) extends FlowdockHandler {
|
$sock = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
|
||||||
public function fsockopen() {
|
socket_bind($sock, '127.0.0.1', 51984);
|
||||||
return $this->mockedResource;
|
socket_listen($sock);
|
||||||
}
|
|
||||||
public function streamSetTimeout() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public function closeSocket() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$this->handler->mockedResource = $this->res;
|
while (true) {
|
||||||
|
$res = socket_accept($sock);
|
||||||
|
socket_set_option($res, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 0, "usec" => 500));
|
||||||
|
while ($read = socket_read($res, 1024)) {
|
||||||
|
echo $read;
|
||||||
|
}
|
||||||
|
socket_close($res);
|
||||||
|
}
|
||||||
|
SCRIPT
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->socket = new \Symfony\Component\Process\Process(escapeshellarg(PHP_BINARY).' '.escapeshellarg($tmpFile));
|
||||||
|
$this->socket->start();
|
||||||
|
|
||||||
|
$this->handler = new FlowdockHandler($token);
|
||||||
|
|
||||||
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
|
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
|
||||||
$reflectionProperty->setAccessible(true);
|
$reflectionProperty->setAccessible(true);
|
||||||
$reflectionProperty->setValue($this->handler, 'localhost:1234');
|
$reflectionProperty->setValue($this->handler, '127.0.0.1:51984');
|
||||||
|
|
||||||
$this->handler->setFormatter(new FlowdockFormatter('test_source', 'source@test.com'));
|
$this->handler->setFormatter(new FlowdockFormatter('test_source', 'source@test.com'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function closeSocket()
|
||||||
|
{
|
||||||
|
$this->socket->stop();
|
||||||
|
|
||||||
|
return $this->socket->getOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
if (isset($this->socket)) {
|
||||||
|
$this->closeSocket();
|
||||||
|
unset($this->socket);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user