1 | <?php |
||
12 | class CacheTest extends \PHPUnit_Framework_TestCase |
||
13 | { |
||
14 | private $context; |
||
15 | private $object; |
||
16 | private $mock; |
||
17 | private $cache; |
||
18 | |||
19 | |||
20 | protected function setUp() |
||
21 | { |
||
22 | $this->cache = $this->getMockBuilder( 'Aimeos\MW\Cache\None' ) |
||
23 | ->setMethods( array( 'deleteByTags' ) ) |
||
24 | ->disableOriginalConstructor() |
||
25 | ->getMock(); |
||
26 | |||
27 | $this->mock = $this->getMockBuilder( 'Aimeos\Admin\JQAdm\Product\Standard' ) |
||
28 | ->setMethods( array( 'delete', 'save' ) ) |
||
29 | ->disableOriginalConstructor() |
||
30 | ->getMock(); |
||
31 | |||
32 | $templatePaths = \TestHelperJqadm::getTemplatePaths(); |
||
33 | $this->context = \TestHelperJqadm::getContext(); |
||
34 | $this->context->setCache( $this->cache ); |
||
35 | |||
36 | $this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Cache( $this->mock, $this->context, $templatePaths ); |
||
37 | } |
||
38 | |||
39 | |||
40 | protected function tearDown() |
||
44 | |||
45 | |||
46 | public function testDelete() |
||
61 | |||
62 | |||
63 | public function testSave() |
||
79 | } |
||
80 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: