<?php
require_once 'EasyLogger/Handler/HandlerTestCase.php';
require_once 'EasyLogger/Handler/StreamHandler.php';
class EasyLogger_Handler_StreamHandlerTest extends EasyLogger_Handler_HandlerTestCase
{
/**
* @expectedException RuntimeException
*/
public function testExceptionWhenStreamCanNotBeOpened()
{
$handler = new EasyLogger_Handler_StreamHandler('/invalid/stream');
$handler->handle($this->_getRecord());
}
public function testHandlingRecords()
{
$stream = fopen('php://memory', 'a+');
$handler = new EasyLogger_Handler_StreamHandler($stream);
$record1 = $this->_getRecord(EasyLogger::LEVEL_WARNING, 'foo');
$record2 = $this->_getRecord(EasyLogger::LEVEL_INFO, 'bar');
$handler->handle($record1);
$handler->handle($record2);
fseek($stream, 0);
$content = fread($stream, 300);
$this->assertRegExp('/\d+\-\d+-\d+\s\d+:\d+:\d+/', $content);
$this->assertRegExp('#' . preg_quote($record1['levelName'], '#') . '#', $content);
$this->assertRegExp('#' . preg_quote($record2['levelName'], '#') . '#', $content);
$this->assertRegExp('#' . preg_quote($record1['message'], '#') . '#', $content);
$this->assertRegExp('#' . preg_quote($record2['message'], '#') . '#', $content);
}
public function testHandlingWhenStreamIsUrl()
{
$handler = new EasyLogger_Handler_StreamHandler('php://memory');
$handler->handle($this->_getRecord());
}
}
|