1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-31 10:20:14 +02:00

Fixing the socket mess, maybe.

This commit is contained in:
Jordi Boggiano
2016-09-19 22:01:19 +02:00
parent a0f59df992
commit 3dc7a79a3e
9 changed files with 311 additions and 353 deletions

View File

@@ -14,6 +14,7 @@ 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>
@@ -42,7 +43,7 @@ class FlowdockHandlerTest extends TestCase
{
$this->initHandlerAndSocket();
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
$content = $this->closeSocket();
$content = $this->socket->getOutput();
$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);
@@ -61,28 +62,7 @@ class FlowdockHandlerTest extends TestCase
private function initHandlerAndSocket($token = 'myToken')
{
$tmpFile = sys_get_temp_dir().'/monolog-test-socket.php';
file_put_contents($tmpFile, <<<'SCRIPT'
<?php
$sock = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
socket_bind($sock, '127.0.0.1', 51984);
socket_listen($sock);
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->socket = LocalSocket::initSocket();
$this->handler = new FlowdockHandler($token);
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
@@ -92,18 +72,8 @@ SCRIPT
$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);
}
unset($this->socket, $this->handler);
}
}