diff options
Diffstat (limited to 'tests/Monolog/Handler/StreamHandlerTest.php')
-rw-r--r-- | tests/Monolog/Handler/StreamHandlerTest.php | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/tests/Monolog/Handler/StreamHandlerTest.php b/tests/Monolog/Handler/StreamHandlerTest.php index 487030f..377e296 100644 --- a/tests/Monolog/Handler/StreamHandlerTest.php +++ b/tests/Monolog/Handler/StreamHandlerTest.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; class StreamHandlerTest extends TestCase @@ -51,13 +51,38 @@ class StreamHandlerTest extends TestCase { $handler = new StreamHandler('php://memory'); $handler->handle($this->getRecord(Logger::WARNING, 'test')); - $streamProp = new \ReflectionProperty('Monolog\Handler\StreamHandler', 'stream'); - $streamProp->setAccessible(true); - $handle = $streamProp->getValue($handler); + $stream = $handler->getStream(); - $this->assertTrue(is_resource($handle)); + $this->assertTrue(is_resource($stream)); $handler->close(); - $this->assertFalse(is_resource($handle)); + $this->assertFalse(is_resource($stream)); + } + + /** + * @covers Monolog\Handler\StreamHandler::close + * @covers Monolog\Handler\Handler::__sleep + */ + public function testSerialization() + { + $handler = new StreamHandler('php://memory'); + $handler->handle($this->getRecord(Logger::WARNING, 'testfoo')); + $stream = $handler->getStream(); + + $this->assertTrue(is_resource($stream)); + fseek($stream, 0); + $this->assertContains('testfoo', stream_get_contents($stream)); + $serialized = serialize($handler); + $this->assertFalse(is_resource($stream)); + + $handler = unserialize($serialized); + $handler->handle($this->getRecord(Logger::WARNING, 'testbar')); + $stream = $handler->getStream(); + + $this->assertTrue(is_resource($stream)); + fseek($stream, 0); + $contents = stream_get_contents($stream); + $this->assertNotContains('testfoo', $contents); + $this->assertContains('testbar', $contents); } /** @@ -93,11 +118,11 @@ class StreamHandlerTest extends TestCase public function invalidArgumentProvider() { - return array( - array(1), - array(array()), - array(array('bogus://url')), - ); + return [ + [1], + [[]], + [['bogus://url']], + ]; } /** |