PHP7 TemplateMethod

This commit is contained in:
Dominik Liebler
2016-09-22 11:13:47 +02:00
parent 36f3df8fbb
commit 19fff0aed9
7 changed files with 734 additions and 360 deletions

View File

@@ -4,40 +4,33 @@ namespace DesignPatterns\Behavioral\TemplateMethod\Tests;
use DesignPatterns\Behavioral\TemplateMethod;
/**
* JourneyTest tests all journeys.
*/
class JourneyTest extends \PHPUnit_Framework_TestCase
{
public function testBeach()
public function testCanGetOnVacationOnTheBeach()
{
$journey = new TemplateMethod\BeachJourney();
$this->expectOutputRegex('#sun-bathing#');
$journey->takeATrip();
$beachJourney = new TemplateMethod\BeachJourney();
$beachJourney->takeATrip();
$this->assertEquals(
['Buy a flight ticket', 'Taking the plane', 'Swimming and sun-bathing', 'Taking the plane'],
$beachJourney->getThingsToDo()
);
}
public function testCity()
public function testCanGetOnAJourneyToACity()
{
$journey = new TemplateMethod\CityJourney();
$this->expectOutputRegex('#drink#');
$journey->takeATrip();
}
$beachJourney = new TemplateMethod\CityJourney();
$beachJourney->takeATrip();
/**
* How to test an abstract template method with PHPUnit.
*/
public function testLasVegas()
{
$journey = $this->getMockForAbstractClass('DesignPatterns\Behavioral\TemplateMethod\Journey');
$journey->expects($this->once())
->method('enjoyVacation')
->will($this->returnCallback(array($this, 'mockUpVacation')));
$this->expectOutputRegex('#Las Vegas#');
$journey->takeATrip();
}
public function mockUpVacation()
{
echo "Fear and loathing in Las Vegas\n";
$this->assertEquals(
[
'Buy a flight ticket',
'Taking the plane',
'Eat, drink, take photos and sleep',
'Buy a gift',
'Taking the plane'
],
$beachJourney->getThingsToDo()
);
}
}