mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-09-25 13:59:08 +02:00
it was created the Structural namespace and append its patterns
This commit is contained in:
63
Structural/Decorator/DecoratorTest.php
Normal file
63
Structural/Decorator/DecoratorTest.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Structural\Decorator;
|
||||
|
||||
use DesignPatterns\Structural\Decorator;
|
||||
|
||||
/**
|
||||
* DecoratorTest tests the decorator pattern
|
||||
*/
|
||||
class DecoratorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected $service;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->service = new Decorator\Webservice(array('foo' => 'bar'));
|
||||
}
|
||||
|
||||
public function testJsonDecorator()
|
||||
{
|
||||
// Wrap service with a JSON decorator for renderers
|
||||
$service = new Decorator\RenderInJson($this->service);
|
||||
// Our Renderer will now output JSON instead of an array
|
||||
$this->assertEquals('{"foo":"bar"}', $service->renderData());
|
||||
}
|
||||
|
||||
public function testXmlDecorator()
|
||||
{
|
||||
// Wrap service with a JSON decorator for renderers
|
||||
$service = new Decorator\RenderInXml($this->service);
|
||||
// Our Renderer will now output XML instead of an array
|
||||
$this->assertXmlStringEqualsXmlString('<?xml version="1.0"?><foo>bar</foo>', $service->renderData());
|
||||
}
|
||||
|
||||
/**
|
||||
* The first key-point of this pattern :
|
||||
*/
|
||||
public function testDecoratorMustImplementsRenderer()
|
||||
{
|
||||
$this->assertTrue(is_subclass_of('DesignPatterns\Structural\Decorator\Decorator', 'DesignPatterns\Structural\Decorator\RendererInterface'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Second key-point of this pattern : the decorator is type-hinted
|
||||
*
|
||||
* @expectedException \PHPUnit_Framework_Error
|
||||
*/
|
||||
public function testDecoratorTypeHinted()
|
||||
{
|
||||
$this->getMockForAbstractClass('DesignPatterns\Structural\Decorator\Decorator', array(new \stdClass()));
|
||||
}
|
||||
|
||||
/**
|
||||
* The decorator implements and wraps the same interface
|
||||
*/
|
||||
public function testDecoratorOnlyAcceptRenderer()
|
||||
{
|
||||
$mock = $this->getMock('DesignPatterns\Structural\Decorator\RendererInterface');
|
||||
$dec = $this->getMockForAbstractClass('DesignPatterns\Structural\Decorator\Decorator', array($mock));
|
||||
$this->assertNotNull($dec);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user