mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-04 05:57:25 +02:00
add tests for this pattern
This commit is contained in:
49
Tests/TemplateMethod/JourneyTest.php
Normal file
49
Tests/TemplateMethod/JourneyTest.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DesignPatternPHP
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace DesignPatterns\Tests\TemplateMethod;
|
||||||
|
|
||||||
|
use DesignPatterns\TemplateMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JourneyTest tests all journeys
|
||||||
|
*/
|
||||||
|
class JourneyTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testBeach()
|
||||||
|
{
|
||||||
|
$journey = new TemplateMethod\BeachJourney();
|
||||||
|
$this->expectOutputRegex('#sun-bathing#');
|
||||||
|
$journey->takeATrip();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCity()
|
||||||
|
{
|
||||||
|
$journey = new TemplateMethod\CityJouney();
|
||||||
|
$this->expectOutputRegex('#drink#');
|
||||||
|
$journey->takeATrip();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How to test an abstract template method with PHPUnit
|
||||||
|
*/
|
||||||
|
public function testLasVegas()
|
||||||
|
{
|
||||||
|
$journey = $this->getMockForAbstractClass('DesignPatterns\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";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user