Conditions | 2 |
Paths | 2 |
Total Lines | 18 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
32 | 2 | public function endTest(\PHPUnit_Framework_Test $test, $time) |
|
33 | { |
||
34 | try { |
||
35 | // The self() call is used as a sentinel. Anything that throws if |
||
36 | // the container is closed already will do. |
||
37 | 2 | \Mockery::self(); |
|
38 | 2 | } catch (\LogicException $_) { |
|
39 | 1 | return; |
|
40 | } |
||
41 | |||
42 | 1 | $e = new \PHPUnit_Framework_ExpectationFailedException(sprintf( |
|
43 | 1 | "Mockery's expectations have not been verified. Make sure that \Mockery::close() is called at the end of the test. Consider using %s\MockeryPHPUnitIntegration or extending %s\MockeryTestCase.", |
|
44 | 1 | __NAMESPACE__, |
|
45 | __NAMESPACE__ |
||
46 | 1 | )); |
|
47 | 1 | $result = $test->getTestResultObject(); |
|
|
|||
48 | 1 | $result->addFailure($test, $e, $time); |
|
49 | 1 | } |
|
50 | } |
||
51 |
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: