Created
February 26, 2014 20:51
-
-
Save awei01/9238255 to your computer and use it in GitHub Desktop.
some fake testing code that is not dry because i'm faking methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // class definitions | |
| abstract class AbstractFactory { | |
| protected function makeWidget() | |
| { | |
| return new Widget; | |
| } | |
| } | |
| class FactoryOne extends AbstractFactory { | |
| function doFooOnWidget() | |
| { | |
| $widget = $this->makeWidget(); | |
| $widget->doFoo(); | |
| } | |
| } | |
| class FactoryTwo extends AbstractFactory { | |
| function doBarOnWidget() | |
| { | |
| $widget = $this->makeWidget(); | |
| $widget->doBar(); | |
| } | |
| } | |
| ?> | |
| <?php | |
| // testing file | |
| class FactoryOneTest extends TestCase { | |
| function test_doFooOnWidget_NoParams_CallsDoFooOnWidgetInstance { | |
| $factory = new FakeFactoryOne(); | |
| $factory->fakeWidget = $fakeWidget; | |
| $fakeWidget->shouldReceive('doFoo')->once(); | |
| $factory->doFooOnWidget(); | |
| } | |
| } | |
| class FakeFactoryOne extends FactoryOne { | |
| public $fakeWidget; | |
| // how can i abstract the following function? | |
| protected function makeWidget() | |
| { | |
| if ($fakeWidget) | |
| { | |
| return $fakeWidget; | |
| } | |
| return parent::makeWidget(); | |
| } | |
| } | |
| class FactoryTwoTest extends TestCase { | |
| function test_doBarOnWidget_NoParams_CallsDoFooOnWidgetInstance { | |
| $factory = new FakeFactoryTwo(); | |
| $factory->fakeWidget = $fakeWidget; | |
| $fakeWidget->shouldReceive('doBar')->once(); | |
| $factory->doBarOnWidget(); | |
| } | |
| } | |
| class FakeFactoryTwo extends FactoryTwo { | |
| public $fakeWidget; | |
| // how can i abstract the following function? | |
| protected function makeWidget() | |
| { | |
| if ($fakeWidget) | |
| { | |
| return $fakeWidget; | |
| } | |
| return parent::makeWidget(); | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment