mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-10 17:04:01 +02:00
PHP7 TemplateMethod
This commit is contained in:
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user