summaryrefslogtreecommitdiffstats
path: root/tests/Monolog/Handler/StreamHandlerTest.php
diff options
context:
space:
mode:
authorJordi Boggiano <j.boggiano@seld.be>2016-05-26 21:13:52 +0100
committerJordi Boggiano <j.boggiano@seld.be>2016-05-26 21:13:52 +0100
commitaf7c0a7bda396ed83dcfcf28cda8133d687a7b9c (patch)
tree3187bb4ce2041b5f3e6da0ff33d725d5519232c4 /tests/Monolog/Handler/StreamHandlerTest.php
parent017aa2cb75ea6f64e2812a93ca48156b6780c502 (diff)
downloadmonolog-af7c0a7bda396ed83dcfcf28cda8133d687a7b9c.zip
monolog-af7c0a7bda396ed83dcfcf28cda8133d687a7b9c.tar.gz
monolog-af7c0a7bda396ed83dcfcf28cda8133d687a7b9c.tar.bz2
Make handlers more serializable by default by having them close() before sleeping, fixes #365
Diffstat (limited to 'tests/Monolog/Handler/StreamHandlerTest.php')
-rw-r--r--tests/Monolog/Handler/StreamHandlerTest.php35
1 files changed, 30 insertions, 5 deletions
diff --git a/tests/Monolog/Handler/StreamHandlerTest.php b/tests/Monolog/Handler/StreamHandlerTest.php
index d5234ee..b0d7d7f 100644
--- a/tests/Monolog/Handler/StreamHandlerTest.php
+++ b/tests/Monolog/Handler/StreamHandlerTest.php
@@ -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);
}
/**