mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-11 09:24:01 +02:00
refactored Decorator pattern
This commit is contained in:
@@ -2,32 +2,37 @@
|
||||
|
||||
namespace DesignPatterns\Structural\Decorator\Tests;
|
||||
|
||||
use DesignPatterns\Structural\Decorator;
|
||||
use DesignPatterns\Structural\Decorator\DoubleRoomBooking;
|
||||
use DesignPatterns\Structural\Decorator\ExtraBed;
|
||||
use DesignPatterns\Structural\Decorator\WiFi;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DecoratorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Decorator\Webservice
|
||||
*/
|
||||
private $service;
|
||||
|
||||
protected function setUp()
|
||||
public function testCanCalculatePriceForBasicDoubleRoomBooking()
|
||||
{
|
||||
$this->service = new Decorator\Webservice('foobar');
|
||||
$booking = new DoubleRoomBooking();
|
||||
|
||||
$this->assertEquals(40, $booking->calculatePrice());
|
||||
$this->assertEquals('double room', $booking->getDescription());
|
||||
}
|
||||
|
||||
public function testJsonDecorator()
|
||||
public function testCanCalculatePriceForDoubleRoomBookingWithWiFi()
|
||||
{
|
||||
$service = new Decorator\JsonRenderer($this->service);
|
||||
$booking = new DoubleRoomBooking();
|
||||
$booking = new WiFi($booking);
|
||||
|
||||
$this->assertEquals('"foobar"', $service->renderData());
|
||||
$this->assertEquals(42, $booking->calculatePrice());
|
||||
$this->assertEquals('double room with wifi', $booking->getDescription());
|
||||
}
|
||||
|
||||
public function testXmlDecorator()
|
||||
public function testCanCalculatePriceForDoubleRoomBookingWithWiFiAndExtraBed()
|
||||
{
|
||||
$service = new Decorator\XmlRenderer($this->service);
|
||||
$booking = new DoubleRoomBooking();
|
||||
$booking = new WiFi($booking);
|
||||
$booking = new ExtraBed($booking);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString('<?xml version="1.0"?><content>foobar</content>', $service->renderData());
|
||||
$this->assertEquals(72, $booking->calculatePrice());
|
||||
$this->assertEquals('double room with wifi with extra bed', $booking->getDescription());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user