Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/EasyLogger/Handler/StreamHandlerTest.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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: 1 year 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($stream0);
        
$content fread($stream300);
        
        
$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());
    }
}