1 | <?php |
||
19 | trait CommonContextTrait |
||
20 | { |
||
21 | /** |
||
22 | * @var MinkContext |
||
23 | */ |
||
24 | protected $minkContext; |
||
25 | |||
26 | /** |
||
27 | * @var CoreContext |
||
28 | */ |
||
29 | protected $coreContext; |
||
30 | |||
31 | /** |
||
32 | * @var UserContext |
||
33 | */ |
||
34 | protected $userContext; |
||
35 | |||
36 | /** |
||
37 | * @var SummaryFormContext |
||
38 | */ |
||
39 | protected $summaryFormContext; |
||
40 | |||
41 | /** |
||
42 | * @BeforeScenario |
||
43 | * |
||
44 | * @param BeforeScenarioScope $scope |
||
45 | */ |
||
46 | public function gatherContexts(BeforeScenarioScope $scope) |
||
53 | |||
54 | public function generateUrl($name,array $params=array(),array $options=array()) |
||
67 | |||
68 | public function visit($url) |
||
72 | |||
73 | /** |
||
74 | * @param $id |
||
75 | * @return mixed|object |
||
76 | */ |
||
77 | public function getService($id) |
||
81 | |||
82 | /** |
||
83 | * @param $id |
||
84 | * |
||
85 | * @return RepositoryInterface |
||
86 | */ |
||
87 | public function getRepository($id) |
||
91 | |||
92 | /** |
||
93 | * @return UserContext |
||
94 | */ |
||
95 | public function getUserContext() |
||
99 | } |
||
100 |
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: