PHP Classes

File: tests/EasyLogger/Handler/StreamHandlerTest.php

Recommend this page to a friend!
  Classes of Nikola Posa   EasyLogger   tests/EasyLogger/Handler/StreamHandlerTest.php   Download  
File: tests/EasyLogger/Handler/StreamHandlerTest.php
Role: Unit test script
Content type: text/plain
Description: Stream handler tests
Class: EasyLogger
Log events to files
Author: By
Last change:
Date: 11 years ago
Size: 1,564 bytes
 

Contents

Class file image Download
<?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());
    }
}