diff options
Diffstat (limited to 'tests/Monolog/Handler/SocketHandlerTest.php')
-rw-r--r-- | tests/Monolog/Handler/SocketHandlerTest.php | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/tests/Monolog/Handler/SocketHandlerTest.php b/tests/Monolog/Handler/SocketHandlerTest.php index 1f9c1f2..c0080e8 100644 --- a/tests/Monolog/Handler/SocketHandlerTest.php +++ b/tests/Monolog/Handler/SocketHandlerTest.php @@ -1,4 +1,4 @@ -<?php +<?php declare(strict_types=1); /* * This file is part of the Monolog package. @@ -11,7 +11,7 @@ namespace Monolog\Handler; -use Monolog\TestCase; +use Monolog\Test\TestCase; use Monolog\Logger; /** @@ -88,7 +88,7 @@ class SocketHandlerTest extends TestCase */ public function testExceptionIsThrownOnFsockopenError() { - $this->setMockHandler(array('fsockopen')); + $this->setMockHandler(['fsockopen']); $this->handler->expects($this->once()) ->method('fsockopen') ->will($this->returnValue(false)); @@ -100,7 +100,7 @@ class SocketHandlerTest extends TestCase */ public function testExceptionIsThrownOnPfsockopenError() { - $this->setMockHandler(array('pfsockopen')); + $this->setMockHandler(['pfsockopen']); $this->handler->expects($this->once()) ->method('pfsockopen') ->will($this->returnValue(false)); @@ -113,7 +113,7 @@ class SocketHandlerTest extends TestCase */ public function testExceptionIsThrownIfCannotSetTimeout() { - $this->setMockHandler(array('streamSetTimeout')); + $this->setMockHandler(['streamSetTimeout']); $this->handler->expects($this->once()) ->method('streamSetTimeout') ->will($this->returnValue(false)); @@ -125,13 +125,13 @@ class SocketHandlerTest extends TestCase */ public function testWriteFailsOnIfFwriteReturnsFalse() { - $this->setMockHandler(array('fwrite')); + $this->setMockHandler(['fwrite']); $callback = function ($arg) { - $map = array( + $map = [ 'Hello world' => 6, 'world' => false, - ); + ]; return $map[$arg]; }; @@ -148,13 +148,13 @@ class SocketHandlerTest extends TestCase */ public function testWriteFailsIfStreamTimesOut() { - $this->setMockHandler(array('fwrite', 'streamGetMetadata')); + $this->setMockHandler(['fwrite', 'streamGetMetadata']); $callback = function ($arg) { - $map = array( + $map = [ 'Hello world' => 6, 'world' => 5, - ); + ]; return $map[$arg]; }; @@ -164,7 +164,7 @@ class SocketHandlerTest extends TestCase ->will($this->returnCallback($callback)); $this->handler->expects($this->exactly(1)) ->method('streamGetMetadata') - ->will($this->returnValue(array('timed_out' => true))); + ->will($this->returnValue(['timed_out' => true])); $this->writeRecord('Hello world'); } @@ -174,7 +174,7 @@ class SocketHandlerTest extends TestCase */ public function testWriteFailsOnIncompleteWrite() { - $this->setMockHandler(array('fwrite', 'streamGetMetadata')); + $this->setMockHandler(['fwrite', 'streamGetMetadata']); $res = $this->res; $callback = function ($string) use ($res) { @@ -188,7 +188,7 @@ class SocketHandlerTest extends TestCase ->will($this->returnCallback($callback)); $this->handler->expects($this->exactly(1)) ->method('streamGetMetadata') - ->will($this->returnValue(array('timed_out' => false))); + ->will($this->returnValue(['timed_out' => false])); $this->writeRecord('Hello world'); } @@ -205,13 +205,13 @@ class SocketHandlerTest extends TestCase public function testWriteWithMock() { - $this->setMockHandler(array('fwrite')); + $this->setMockHandler(['fwrite']); $callback = function ($arg) { - $map = array( + $map = [ 'Hello world' => 6, 'world' => 5, - ); + ]; return $map[$arg]; }; @@ -247,7 +247,7 @@ class SocketHandlerTest extends TestCase */ public function testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds() { - $this->setMockHandler(array('fwrite', 'streamGetMetadata')); + $this->setMockHandler(['fwrite', 'streamGetMetadata']); $this->handler->expects($this->any()) ->method('fwrite') @@ -255,7 +255,7 @@ class SocketHandlerTest extends TestCase $this->handler->expects($this->any()) ->method('streamGetMetadata') - ->will($this->returnValue(array('timed_out' => false))); + ->will($this->returnValue(['timed_out' => false])); $this->handler->setWritingTimeout(1); @@ -273,18 +273,19 @@ class SocketHandlerTest extends TestCase $this->handler->handle($this->getRecord(Logger::WARNING, $string)); } - private function setMockHandler(array $methods = array()) + private function setMockHandler(array $methods = []) { $this->res = fopen('php://memory', 'a'); - $defaultMethods = array('fsockopen', 'pfsockopen', 'streamSetTimeout'); + $defaultMethods = ['fsockopen', 'pfsockopen', 'streamSetTimeout']; $newMethods = array_diff($methods, $defaultMethods); $finalMethods = array_merge($defaultMethods, $newMethods); - $this->handler = $this->getMock( - '\Monolog\Handler\SocketHandler', $finalMethods, array('localhost:1234') - ); + $this->handler = $this->getMockBuilder('Monolog\Handler\SocketHandler') + ->setMethods($finalMethods) + ->setConstructorArgs(['localhost:1234']) + ->getMock(); if (!in_array('fsockopen', $methods)) { $this->handler->expects($this->any()) |