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
|
|
|
namespace Sylius\Behat\Context\Ui\Shop; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Sylius\Behat\NotificationType; |
16
|
|
|
use Sylius\Behat\Page\PageInterface; |
17
|
|
|
use Sylius\Behat\Page\Shop\Contact\ContactPageInterface; |
18
|
|
|
use Sylius\Behat\Service\NotificationCheckerInterface; |
19
|
|
|
use Webmozart\Assert\Assert; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
23
|
|
|
*/ |
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( |
41
|
|
|
ContactPageInterface $contactPage, |
42
|
|
|
NotificationCheckerInterface $notificationChecker |
43
|
|
|
) { |
44
|
|
|
$this->contactPage = $contactPage; |
45
|
|
|
$this->notificationChecker = $notificationChecker; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @When I want to request contact |
50
|
|
|
*/ |
51
|
|
|
public function iWantToRequestContact() |
52
|
|
|
{ |
53
|
|
|
$this->contactPage->open(); |
54
|
|
|
} |
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) |
61
|
|
|
{ |
62
|
|
|
$this->contactPage->specifyEmail($email); |
63
|
|
|
} |
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) |
70
|
|
|
{ |
71
|
|
|
$this->contactPage->specifyMessage($message); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @When I send it |
76
|
|
|
* @When I try to send it |
77
|
|
|
*/ |
78
|
|
|
public function iSendIt() |
79
|
|
|
{ |
80
|
|
|
$this->contactPage->send(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @Then I should be notified that the contact request has been submitted successfully |
85
|
|
|
*/ |
86
|
|
|
public function iShouldBeNotifiedThatTheContactRequestHasBeenSubmittedSuccessfully() |
87
|
|
|
{ |
88
|
|
|
$this->notificationChecker->checkNotification( |
89
|
|
|
'Your contact request has been submitted successfully.', |
90
|
|
|
NotificationType::success() |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @Then /^I should be notified that the (email|message) is required$/ |
96
|
|
|
*/ |
97
|
|
|
public function iShouldBeNotifiedThatElementIsRequired($element) |
98
|
|
|
{ |
99
|
|
|
$this->assertFieldValidationMessage( |
100
|
|
|
$this->contactPage, |
101
|
|
|
$element, |
102
|
|
|
sprintf('Please enter your %s.', $element) |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @Then I should be notified that the email is invalid |
108
|
|
|
*/ |
109
|
|
|
public function iShouldBeNotifiedThatEmailIsInvalid() |
110
|
|
|
{ |
111
|
|
|
$this->assertFieldValidationMessage( |
112
|
|
|
$this->contactPage, |
113
|
|
|
'email', |
114
|
|
|
'This email is invalid.' |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @Then I should be notified that a problem occured while sending the contact request |
120
|
|
|
*/ |
121
|
|
|
public function iShouldBeNotifiedThatAProblemOccuredWhileSendingTheContactRequest() |
122
|
|
|
{ |
123
|
|
|
$this->notificationChecker->checkNotification( |
124
|
|
|
'A problem occurred while sending the contact request. Please try again later.', |
125
|
|
|
NotificationType::failure() |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param PageInterface $page |
131
|
|
|
* @param string $element |
132
|
|
|
* @param string $expectedMessage |
133
|
|
|
*/ |
134
|
|
|
private function assertFieldValidationMessage(PageInterface $page, $element, $expectedMessage) |
135
|
|
|
{ |
136
|
|
|
$currentMessage = $page->getValidationMessageFor($element); |
|
|
|
|
137
|
|
|
|
138
|
|
|
Assert::same( |
139
|
|
|
$currentMessage, |
140
|
|
|
$expectedMessage, |
141
|
|
|
'There is a message: "%s", but should be: "%s".' |
142
|
|
|
); |
143
|
|
|
} |
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: