diff options
author | Jordi Boggiano <j.boggiano@seld.be> | 2016-09-19 22:01:19 +0200 |
---|---|---|
committer | Jordi Boggiano <j.boggiano@seld.be> | 2016-09-19 23:14:24 +0200 |
commit | 3dc7a79a3e88ee543f2f032d39b2354548898034 (patch) | |
tree | 9b614bbf93b0ddb8df727c56b5eb476de1741bce /tests/Monolog/Handler/LogEntriesHandlerTest.php | |
parent | a0f59df992f83c4b8c19cfcb891ae247fd7a3872 (diff) | |
download | monolog-3dc7a79a3e88ee543f2f032d39b2354548898034.zip monolog-3dc7a79a3e88ee543f2f032d39b2354548898034.tar.gz monolog-3dc7a79a3e88ee543f2f032d39b2354548898034.tar.bz2 |
Fixing the socket mess, maybe.
Diffstat (limited to 'tests/Monolog/Handler/LogEntriesHandlerTest.php')
-rw-r--r-- | tests/Monolog/Handler/LogEntriesHandlerTest.php | 39 |
1 files changed, 5 insertions, 34 deletions
diff --git a/tests/Monolog/Handler/LogEntriesHandlerTest.php b/tests/Monolog/Handler/LogEntriesHandlerTest.php index 56c25dc..ce0df94 100644 --- a/tests/Monolog/Handler/LogEntriesHandlerTest.php +++ b/tests/Monolog/Handler/LogEntriesHandlerTest.php @@ -13,6 +13,7 @@ namespace Monolog\Handler; use Monolog\Test\TestCase; use Monolog\Logger; +use Monolog\Util\LocalSocket; /** * @author Robert Kaufmann III <rok3@rok3.me> @@ -34,7 +35,7 @@ class LogEntriesHandlerTest extends TestCase $this->initHandlerAndSocket(); $this->handler->handle($this->getRecord(Logger::CRITICAL, 'Critical write test')); - $content = $this->closeSocket(); + $content = $this->socket->getOutput(); $this->assertRegexp('/testToken \[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}\+00:00\] test.CRITICAL: Critical write test/', $content); } @@ -48,33 +49,13 @@ class LogEntriesHandlerTest extends TestCase $this->initHandlerAndSocket(); $this->handler->handleBatch($records); - $content = $this->closeSocket(); + $content = $this->socket->getOutput(); $this->assertRegexp('/(testToken \[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}\+00:00\] .* \[\] \[\]\n){3}/', $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 LogEntriesHandler('testToken', $useSSL, Logger::DEBUG, true); @@ -84,18 +65,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); } } |