1 | <?php |
||
26 | final class InstallerContext implements Context |
||
27 | { |
||
28 | /** |
||
29 | * @var KernelInterface |
||
30 | */ |
||
31 | private $kernel; |
||
32 | |||
33 | /** |
||
34 | * @var Application |
||
35 | */ |
||
36 | private $application; |
||
37 | |||
38 | /** |
||
39 | * @var CommandTester |
||
40 | */ |
||
41 | private $tester; |
||
42 | |||
43 | /** |
||
44 | * @var QuestionHelper |
||
45 | */ |
||
46 | private $questionHelper; |
||
47 | |||
48 | /** |
||
49 | * @var SetupCommand |
||
50 | */ |
||
51 | private $command; |
||
52 | |||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | private $inputChoices = [ |
||
57 | 'e-mail' => '[email protected]', |
||
58 | 'password' => 'pswd', |
||
59 | 'confirmation' => 'pswd', |
||
60 | ]; |
||
61 | |||
62 | /** |
||
63 | * @param KernelInterface $kernel |
||
64 | */ |
||
65 | public function __construct(KernelInterface $kernel) |
||
69 | |||
70 | /** |
||
71 | * @When I run Sylius CLI installer |
||
72 | */ |
||
73 | public function iRunSyliusCommandLineInstaller() |
||
83 | |||
84 | /** |
||
85 | * @Given I run Sylius Install Load Sample Data command |
||
86 | */ |
||
87 | public function iRunSyliusInstallSampleDataCommand() |
||
94 | |||
95 | /** |
||
96 | * @Given I confirm loading sample data |
||
97 | */ |
||
98 | public function iConfirmLoadingData() |
||
102 | |||
103 | /** |
||
104 | * @Then the command should finish successfully |
||
105 | */ |
||
106 | public function commandSuccess() |
||
110 | |||
111 | /** |
||
112 | * @Then I should see output :text |
||
113 | */ |
||
114 | public function iShouldSeeOutput($text) |
||
118 | |||
119 | /** |
||
120 | * @Given I do not provide an email |
||
121 | */ |
||
122 | public function iDoNotProvideEmail() |
||
126 | |||
127 | /** |
||
128 | * @Given I do not provide a correct email |
||
129 | */ |
||
130 | public function iDoNotProvideCorrectEmail() |
||
134 | |||
135 | /** |
||
136 | * @Given I provide full administrator data |
||
137 | */ |
||
138 | public function iProvideFullAdministratorData() |
||
147 | |||
148 | /** |
||
149 | * @param string $input |
||
150 | * |
||
151 | * @return resource |
||
152 | */ |
||
153 | protected function getInputStream($input) |
||
161 | |||
162 | /** |
||
163 | * @param string $name |
||
164 | */ |
||
165 | private function iExecuteCommandWithInputChoices($name) |
||
173 | |||
174 | /** |
||
175 | * @param string $name |
||
176 | */ |
||
177 | private function iExecuteCommandAndConfirm($name) |
||
185 | } |
||
186 |
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: