From 8eb06265300e671476364cb53b258388d83433e3 Mon Sep 17 00:00:00 2001 From: Trismegiste Date: Sun, 12 May 2013 11:13:56 +0200 Subject: [PATCH] add tests for this pattern --- Tests/TemplateMethod/JourneyTest.php | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Tests/TemplateMethod/JourneyTest.php diff --git a/Tests/TemplateMethod/JourneyTest.php b/Tests/TemplateMethod/JourneyTest.php new file mode 100644 index 0000000..fcfc4e6 --- /dev/null +++ b/Tests/TemplateMethod/JourneyTest.php @@ -0,0 +1,49 @@ +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"; + } + +} \ No newline at end of file