1 | <?php |
||
24 | final class ContactContext implements Context |
||
25 | { |
||
26 | /** |
||
27 | * @var ContactPageInterface |
||
28 | */ |
||
29 | private $contactPage; |
||
30 | |||
31 | /** |
||
32 | * @var NotificationCheckerInterface |
||
33 | */ |
||
34 | private $notificationChecker; |
||
35 | |||
36 | /** |
||
37 | * @param ContactPageInterface $contactPage |
||
38 | * @param NotificationCheckerInterface $notificationChecker |
||
39 | */ |
||
40 | public function __construct( |
||
47 | |||
48 | /** |
||
49 | * @When I want to request contact |
||
50 | */ |
||
51 | public function iWantToRequestContact() |
||
55 | |||
56 | /** |
||
57 | * @When I specify the email as :email |
||
58 | * @When I do not specify the email |
||
59 | */ |
||
60 | public function iSpecifyTheEmail($email = null) |
||
64 | |||
65 | /** |
||
66 | * @When I specify the message as :message |
||
67 | * @When I do not specify the message |
||
68 | */ |
||
69 | public function iSpecifyTheMessage($message = null) |
||
73 | |||
74 | /** |
||
75 | * @When I send it |
||
76 | * @When I try to send it |
||
77 | */ |
||
78 | public function iSendIt() |
||
82 | |||
83 | /** |
||
84 | * @Then I should be notified that the contact request has been submitted successfully |
||
85 | */ |
||
86 | public function iShouldBeNotifiedThatTheContactRequestHasBeenSubmittedSuccessfully() |
||
93 | |||
94 | /** |
||
95 | * @Then /^I should be notified that the (email|message) is required$/ |
||
96 | */ |
||
97 | public function iShouldBeNotifiedThatElementIsRequired($element) |
||
105 | |||
106 | /** |
||
107 | * @Then I should be notified that the email is invalid |
||
108 | */ |
||
109 | public function iShouldBeNotifiedThatEmailIsInvalid() |
||
117 | |||
118 | /** |
||
119 | * @Then I should be notified that a problem occured while sending the contact request |
||
120 | */ |
||
121 | public function iShouldBeNotifiedThatAProblemOccuredWhileSendingTheContactRequest() |
||
128 | |||
129 | /** |
||
130 | * @param PageInterface $page |
||
131 | * @param string $element |
||
132 | * @param string $expectedMessage |
||
133 | */ |
||
134 | private function assertFieldValidationMessage(PageInterface $page, $element, $expectedMessage) |
||
144 | } |
||
145 |
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: