28
28
use Behat \Behat \Context \SnippetAcceptingContext ;
29
29
use Behatch \HttpCall \Request ;
30
30
use Doctrine \Common \Persistence \ManagerRegistry ;
31
+ use Doctrine \ORM \EntityManagerInterface ;
31
32
use Doctrine \ORM \Tools \SchemaTool ;
32
33
33
34
/**
34
35
* Defines application features from the specific context.
35
36
*/
36
- class FeatureContext implements Context, SnippetAcceptingContext
37
+ final class FeatureContext implements Context, SnippetAcceptingContext
37
38
{
38
- private $ doctrine ;
39
-
40
39
/**
41
- * @var \Doctrine\Common\Persistence\ObjectManager
40
+ * @var EntityManagerInterface
42
41
*/
43
42
private $ manager ;
44
-
45
- /**
46
- * @var SchemaTool
47
- */
43
+ private $ doctrine ;
48
44
private $ schemaTool ;
49
-
50
- /**
51
- * @var array
52
- */
53
45
private $ classes ;
54
-
55
- /**
56
- * @var Request
57
- */
58
46
private $ request ;
59
47
60
48
/**
@@ -103,7 +91,7 @@ public function dropDatabase()
103
91
/**
104
92
* @Given there is :nb dummy objects
105
93
*/
106
- public function thereIsDummyObjects ($ nb )
94
+ public function thereIsDummyObjects (int $ nb )
107
95
{
108
96
$ descriptions = ['Smart dummy. ' , 'Not so smart dummy. ' ];
109
97
@@ -123,7 +111,7 @@ public function thereIsDummyObjects($nb)
123
111
/**
124
112
* @Given there is :nb dummy objects with relatedDummy
125
113
*/
126
- public function thereIsDummyObjectsWithRelatedDummy ($ nb )
114
+ public function thereIsDummyObjectsWithRelatedDummy (int $ nb )
127
115
{
128
116
for ($ i = 1 ; $ i <= $ nb ; ++$ i ) {
129
117
$ relatedDummy = new RelatedDummy ();
@@ -144,7 +132,7 @@ public function thereIsDummyObjectsWithRelatedDummy($nb)
144
132
/**
145
133
* @Given there is :nb dummy objects having each :nbrelated relatedDummies
146
134
*/
147
- public function thereIsDummyObjectsWithRelatedDummies ($ nb , $ nbrelated )
135
+ public function thereIsDummyObjectsWithRelatedDummies (int $ nb , int $ nbrelated )
148
136
{
149
137
for ($ i = 1 ; $ i <= $ nb ; ++$ i ) {
150
138
$ dummy = new Dummy ();
@@ -154,11 +142,12 @@ public function thereIsDummyObjectsWithRelatedDummies($nb, $nbrelated)
154
142
for ($ j = 1 ; $ j <= $ nbrelated ; ++$ j ) {
155
143
$ relatedDummy = new RelatedDummy ();
156
144
$ relatedDummy ->setName ('RelatedDummy ' .$ j .$ i );
145
+
157
146
$ this ->manager ->persist ($ relatedDummy );
147
+
158
148
$ dummy ->addRelatedDummy ($ relatedDummy );
159
149
}
160
150
161
- $ this ->manager ->persist ($ relatedDummy );
162
151
$ this ->manager ->persist ($ dummy );
163
152
}
164
153
@@ -168,7 +157,7 @@ public function thereIsDummyObjectsWithRelatedDummies($nb, $nbrelated)
168
157
/**
169
158
* @Given there is :nb dummy objects with dummyDate
170
159
*/
171
- public function thereIsDummyObjectsWithDummyDate ($ nb )
160
+ public function thereIsDummyObjectsWithDummyDate (int $ nb )
172
161
{
173
162
$ descriptions = ['Smart dummy. ' , 'Not so smart dummy. ' ];
174
163
@@ -194,7 +183,7 @@ public function thereIsDummyObjectsWithDummyDate($nb)
194
183
/**
195
184
* @Given there is :nb dummy objects with dummyDate and dummyBoolean :bool
196
185
*/
197
- public function thereIsDummyObjectsWithDummyDateAndDummyBoolean ($ nb , $ bool )
186
+ public function thereIsDummyObjectsWithDummyDateAndDummyBoolean (int $ nb , string $ bool )
198
187
{
199
188
$ descriptions = ['Smart dummy. ' , 'Not so smart dummy. ' ];
200
189
@@ -230,7 +219,7 @@ public function thereIsDummyObjectsWithDummyDateAndDummyBoolean($nb, $bool)
230
219
/**
231
220
* @Given there is :nb dummy objects with dummyDate and relatedDummy
232
221
*/
233
- public function thereIsDummyObjectsWithDummyDateAndRelatedDummy ($ nb )
222
+ public function thereIsDummyObjectsWithDummyDateAndRelatedDummy (int $ nb )
234
223
{
235
224
for ($ i = 1 ; $ i <= $ nb ; ++$ i ) {
236
225
$ date = new \DateTime (sprintf ('2015-04-%d ' , $ i ), new \DateTimeZone ('UTC ' ));
@@ -258,7 +247,7 @@ public function thereIsDummyObjectsWithDummyDateAndRelatedDummy($nb)
258
247
/**
259
248
* @Given there is :nb dummy objects with dummyPrice
260
249
*/
261
- public function thereIsDummyObjectsWithDummyPrice ($ nb )
250
+ public function thereIsDummyObjectsWithDummyPrice (int $ nb )
262
251
{
263
252
$ descriptions = ['Smart dummy. ' , 'Not so smart dummy. ' ];
264
253
$ prices = ['9.99 ' , '12.99 ' , '15.99 ' , '19.99 ' ];
@@ -279,7 +268,7 @@ public function thereIsDummyObjectsWithDummyPrice($nb)
279
268
/**
280
269
* @Given there is :nb dummy objects with dummyBoolean :bool
281
270
*/
282
- public function thereIsDummyObjectsWithDummyBoolean ($ nb , $ bool )
271
+ public function thereIsDummyObjectsWithDummyBoolean (int $ nb , string $ bool )
283
272
{
284
273
if (in_array ($ bool , ['true ' , '1 ' , 1 ], true )) {
285
274
$ bool = true ;
@@ -394,7 +383,7 @@ public function thereIsAFooEntityWithRelatedBars()
394
383
/**
395
384
* @Given there is a RelatedDummy with :nb friends
396
385
*/
397
- public function thereIsARelatedDummyWithFriends ($ nb )
386
+ public function thereIsARelatedDummyWithFriends (int $ nb )
398
387
{
399
388
$ relatedDummy = new RelatedDummy ();
400
389
$ relatedDummy ->setName ('RelatedDummy with friends ' );
@@ -426,10 +415,9 @@ public function thereIsARelatedDummyWithFriends($nb)
426
415
/**
427
416
* @Then the password :password for user :user should be hashed
428
417
*/
429
- public function thePasswordForUserShouldBeHashed ($ password , $ user )
418
+ public function thePasswordForUserShouldBeHashed (string $ password , string $ user )
430
419
{
431
- $ repository = $ this ->doctrine ->getRepository (User::class);
432
- $ user = $ repository ->find ($ user );
420
+ $ user = $ this ->doctrine ->getRepository (User::class)->find ($ user );
433
421
434
422
if (!password_verify ($ password , $ user ->getPassword ())) {
435
423
throw new \Exception ('User password mismatch ' );
0 commit comments