These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Sylius package. |
||
5 | * |
||
6 | * (c) Paweł Jędrzejewski |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace Sylius\Behat\Context\Ui\Shop; |
||
15 | |||
16 | use Behat\Behat\Context\Context; |
||
17 | use Sylius\Behat\NotificationType; |
||
18 | use Sylius\Behat\Page\PageInterface; |
||
19 | use Sylius\Behat\Page\Shop\Contact\ContactPageInterface; |
||
20 | use Sylius\Behat\Service\NotificationCheckerInterface; |
||
21 | use Webmozart\Assert\Assert; |
||
22 | |||
23 | final class ContactContext implements Context |
||
24 | { |
||
25 | /** |
||
26 | * @var ContactPageInterface |
||
27 | */ |
||
28 | private $contactPage; |
||
29 | |||
30 | /** |
||
31 | * @var NotificationCheckerInterface |
||
32 | */ |
||
33 | private $notificationChecker; |
||
34 | |||
35 | /** |
||
36 | * @param ContactPageInterface $contactPage |
||
37 | * @param NotificationCheckerInterface $notificationChecker |
||
38 | */ |
||
39 | public function __construct( |
||
40 | ContactPageInterface $contactPage, |
||
41 | NotificationCheckerInterface $notificationChecker |
||
42 | ) { |
||
43 | $this->contactPage = $contactPage; |
||
44 | $this->notificationChecker = $notificationChecker; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @When I want to request contact |
||
49 | */ |
||
50 | public function iWantToRequestContact() |
||
51 | { |
||
52 | $this->contactPage->open(); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @When I specify the email as :email |
||
57 | * @When I do not specify the email |
||
58 | */ |
||
59 | public function iSpecifyTheEmail($email = null) |
||
60 | { |
||
61 | $this->contactPage->specifyEmail($email); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @When I specify the message as :message |
||
66 | * @When I do not specify the message |
||
67 | */ |
||
68 | public function iSpecifyTheMessage($message = null) |
||
69 | { |
||
70 | $this->contactPage->specifyMessage($message); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @When I send it |
||
75 | * @When I try to send it |
||
76 | */ |
||
77 | public function iSendIt() |
||
78 | { |
||
79 | $this->contactPage->send(); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @Then I should be notified that the contact request has been submitted successfully |
||
84 | */ |
||
85 | public function iShouldBeNotifiedThatTheContactRequestHasBeenSubmittedSuccessfully() |
||
86 | { |
||
87 | $this->notificationChecker->checkNotification( |
||
88 | 'Your contact request has been submitted successfully.', |
||
89 | NotificationType::success() |
||
90 | ); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @Then /^I should be notified that the (email|message) is required$/ |
||
95 | */ |
||
96 | public function iShouldBeNotifiedThatElementIsRequired($element) |
||
97 | { |
||
98 | $this->assertFieldValidationMessage( |
||
99 | $this->contactPage, |
||
100 | $element, |
||
101 | sprintf('Please enter your %s.', $element) |
||
102 | ); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @Then I should be notified that the email is invalid |
||
107 | */ |
||
108 | public function iShouldBeNotifiedThatEmailIsInvalid() |
||
109 | { |
||
110 | $this->assertFieldValidationMessage( |
||
111 | $this->contactPage, |
||
112 | 'email', |
||
113 | 'This email is invalid.' |
||
114 | ); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @Then I should be notified that a problem occurred while sending the contact request |
||
119 | */ |
||
120 | public function iShouldBeNotifiedThatAProblemOccurredWhileSendingTheContactRequest() |
||
121 | { |
||
122 | $this->notificationChecker->checkNotification( |
||
123 | 'A problem occurred while sending the contact request. Please try again later.', |
||
124 | NotificationType::failure() |
||
125 | ); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @param PageInterface $page |
||
130 | * @param string $element |
||
131 | * @param string $expectedMessage |
||
132 | */ |
||
133 | private function assertFieldValidationMessage(PageInterface $page, $element, $expectedMessage) |
||
134 | { |
||
135 | Assert::same($page->getValidationMessageFor($element), $expectedMessage); |
||
0 ignored issues
–
show
|
|||
136 | } |
||
137 | } |
||
138 |
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: