mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-07 05:36:45 +02:00
Fixing the socket mess, maybe.
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Monolog\Handler;
|
||||
|
||||
use Monolog\Test\TestCase;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Util\LocalSocket;
|
||||
|
||||
/**
|
||||
* @author Julien Breux <julien.breux@gmail.com>
|
||||
@@ -34,7 +35,7 @@ class LogmaticHandlerTest extends TestCase
|
||||
$this->initHandlerAndSocket();
|
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'Critical write test'));
|
||||
|
||||
$content = $this->closeSocket();
|
||||
$content = $this->socket->getOutput();
|
||||
|
||||
$this->assertRegexp('/testToken {"message":"Critical write test","context":\[\],"level":500,"level_name":"CRITICAL","channel":"test","datetime":"(.*)","extra":\[\],"hostname":"testHostname","appname":"testAppname"}/', $content);
|
||||
}
|
||||
@@ -49,34 +50,14 @@ class LogmaticHandlerTest extends TestCase
|
||||
$this->initHandlerAndSocket();
|
||||
$this->handler->handleBatch($records);
|
||||
|
||||
$content = $this->closeSocket();
|
||||
$content = $this->socket->getOutput();
|
||||
|
||||
$this->assertRegexp('/testToken {"message":"test","context":\[\],"level":300,"level_name":"WARNING","channel":"test","datetime":"(.*)","extra":\[\],"hostname":"testHostname","appname":"testAppname"}/', $content);
|
||||
}
|
||||
|
||||
private function initHandlerAndSocket()
|
||||
{
|
||||
$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();
|
||||
|
||||
$useSSL = extension_loaded('openssl');
|
||||
$this->handler = new LogmaticHandler('testToken', 'testHostname', 'testAppname', $useSSL, Logger::DEBUG, true);
|
||||
@@ -86,18 +67,8 @@ SCRIPT
|
||||
$reflectionProperty->setValue($this->handler, '127.0.0.1:51984');
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user