PHP Classes

File: tests/logger-tests/ExtendedLoggerTest.php

Recommend this page to a friend!
  Classes of Maik Greubel   PHP Generics   tests/logger-tests/ExtendedLoggerTest.php   Download  
File: tests/logger-tests/ExtendedLoggerTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test for extended logger
Class: PHP Generics
Framework for accessing streams, sockets and logs
Author: By
Last change: Update of tests/logger-tests/ExtendedLoggerTest.php
Date: 6 months ago
Size: 2,001 bytes
 

Contents

Class file image Download
<?php
namespace Generics\Tests;

use
Generics\Logger\ExtendedLogger;
use
Generics\GenericsException;
use
Generics\Streams\FileInputStream;

class
ExtendedLoggerTest extends \PHPUnit\Framework\TestCase
{

    private
$logFileName = "test-logger.log";

    public function
setUp()
    {
        if (
file_exists($this->logFileName)) {
           
unlink($this->logFileName);
        }
    }

    public function
tearDown()
    {
        if (
file_exists($this->logFileName)) {
           
unlink($this->logFileName);
        }
    }

    public function
testException()
    {
       
$logger = new ExtendedLogger($this->logFileName);

       
$logger->logException(new GenericsException("Some exception"));

       
$fis = new FileInputStream($logger->getFile());
       
$content = $fis->read(1024);
       
$fis->close();

       
$this->assertContains('[ alert]: (0): Some exception', $content);
    }

    public function
testErrorException()
    {
       
$logger = new ExtendedLogger($this->logFileName);

       
$logger->logException(new \ErrorException("Some exception", 255));

       
$fis = new FileInputStream($logger->getFile());
       
$content = $fis->read(1024);
       
$fis->close();

       
$this->assertContains('[ error]: (255): Some exception', $content);
    }

    public function
testRuntimeException()
    {
       
$logger = new ExtendedLogger($this->logFileName);

       
$logger->logException(new \RuntimeException("Some exception", 127));

       
$fis = new FileInputStream($logger->getFile());
       
$content = $fis->read(1024);
       
$fis->close();

       
$this->assertContains('[emerge]: (127): Some exception', $content);
    }

    public function
testDump()
    {
       
$logger = new ExtendedLogger($this->logFileName);
       
$o = new \stdClass();
       
$logger->dump($o);

       
$fis = new FileInputStream($logger->getFile());
       
$content = $fis->read(1024);
       
$fis->close();

       
$this->assertContains('stdClass', $content);
    }
}