mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-14 03:46:25 +02:00
add test for null object
This commit is contained in:
35
Tests/NullObject/LoggerTest.php
Normal file
35
Tests/NullObject/LoggerTest.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* DesignPatternPHP
|
||||
*/
|
||||
|
||||
namespace DesignPatterns\Tests\NullObject;
|
||||
|
||||
use DesignPatterns\NullObject\NullLogger;
|
||||
use DesignPatterns\NullObject\Service;
|
||||
use DesignPatterns\NullObject\PrintLogger;
|
||||
|
||||
/**
|
||||
* LoggerTest tests for different loggers
|
||||
*/
|
||||
class LoggerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testNullObject()
|
||||
{
|
||||
// one can use a singleton for NullObjet : I don't think it's a good idea
|
||||
// because the purpose behind null object is to "avoid special case".
|
||||
$service = new Service(new NullLogger());
|
||||
$this->expectOutputString(null); // no output
|
||||
$service->doSomething();
|
||||
}
|
||||
|
||||
public function testStandardLogger()
|
||||
{
|
||||
$service = new Service(new PrintLogger());
|
||||
$this->expectOutputString('We are in DesignPatterns\NullObject\Service::doSomething');
|
||||
$service->doSomething();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user