13
13
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \CompositeLabel ;
14
14
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \CompositeRelation ;
15
15
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \Dummy ;
16
+ use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \EmbeddableDummy ;
17
+ use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \EmbeddedDummy ;
16
18
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \FileConfigDummy ;
17
19
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \RelatedDummy ;
18
20
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \RelationEmbedder ;
@@ -113,6 +115,25 @@ public function thereIsDummyObjects($nb)
113
115
$ this ->manager ->flush ();
114
116
}
115
117
118
+ /**
119
+ * @Given there is :nb embedded dummy objects
120
+ */
121
+ public function thereIsEmbeddedDummyObjects ($ nb )
122
+ {
123
+ for ($ i = 1 ; $ i <= $ nb ; ++$ i ) {
124
+ $ dummy = new EmbeddedDummy ();
125
+ $ dummy ->setName ('Dummy # ' .$ i );
126
+
127
+ $ embeddableDummy = new EmbeddableDummy ();
128
+ $ embeddableDummy ->setDummyName ('Dummy # ' .$ i );
129
+ $ dummy ->setEmbeddedDummy ($ embeddableDummy );
130
+
131
+ $ this ->manager ->persist ($ dummy );
132
+ }
133
+
134
+ $ this ->manager ->flush ();
135
+ }
136
+
116
137
/**
117
138
* @Given there is :nb dummy objects with relatedDummy
118
139
*/
@@ -134,6 +155,25 @@ public function thereIsDummyObjectsWithRelatedDummy($nb)
134
155
$ this ->manager ->flush ();
135
156
}
136
157
158
+ /**
159
+ * @Given there is :nb dummy objects with embeddedDummy
160
+ */
161
+ public function thereIsDummyObjectsWithEmbeddedDummy ($ nb )
162
+ {
163
+ for ($ i = 1 ; $ i <= $ nb ; ++$ i ) {
164
+ $ embeddableDummy = new EmbeddableDummy ();
165
+ $ embeddableDummy ->setDummyName ('EmbeddedDummy # ' .$ i );
166
+
167
+ $ dummy = new EmbeddedDummy ();
168
+ $ dummy ->setName ('Dummy # ' .$ i );
169
+ $ dummy ->setEmbeddedDummy ($ embeddableDummy );
170
+
171
+ $ this ->manager ->persist ($ dummy );
172
+ }
173
+
174
+ $ this ->manager ->flush ();
175
+ }
176
+
137
177
/**
138
178
* @Given there is :nb dummy objects with relatedDummies
139
179
*/
@@ -209,6 +249,32 @@ public function thereIsDummyObjectsWithDummyDateAndRelatedDummy($nb)
209
249
$ this ->manager ->flush ();
210
250
}
211
251
252
+ /**
253
+ * @Given there is :nb embedded dummy objects with dummyDate and embeddedDummy
254
+ */
255
+ public function thereIsDummyObjectsWithDummyDateAndEmbeddedDummy ($ nb )
256
+ {
257
+ for ($ i = 1 ; $ i <= $ nb ; ++$ i ) {
258
+ $ date = new \DateTime (sprintf ('2015-04-%d ' , $ i ), new \DateTimeZone ('UTC ' ));
259
+
260
+ $ embeddableDummy = new EmbeddableDummy ();
261
+ $ embeddableDummy ->setDummyName ('Embeddable # ' .$ i );
262
+ $ embeddableDummy ->setDummyDate ($ date );
263
+
264
+ $ dummy = new EmbeddedDummy ();
265
+ $ dummy ->setName ('Dummy # ' .$ i );
266
+ $ dummy ->setEmbeddedDummy ($ embeddableDummy );
267
+ // Last Dummy has a null date
268
+ if ($ nb !== $ i ) {
269
+ $ dummy ->setDummyDate ($ date );
270
+ }
271
+
272
+ $ this ->manager ->persist ($ dummy );
273
+ }
274
+
275
+ $ this ->manager ->flush ();
276
+ }
277
+
212
278
/**
213
279
* @Given there is :nb dummy objects with dummyPrice
214
280
*/
@@ -258,6 +324,66 @@ public function thereIsDummyObjectsWithDummyBoolean($nb, $bool)
258
324
$ this ->manager ->flush ();
259
325
}
260
326
327
+ /**
328
+ * @Given there is :nb embedded dummy objects with embeddedDummy.dummyBoolean :bool
329
+ */
330
+ public function thereIsDummyObjectsWithEmbeddedDummyBoolean ($ nb , $ bool )
331
+ {
332
+ if (in_array ($ bool , ['true ' , '1 ' , 1 ], true )) {
333
+ $ bool = true ;
334
+ } elseif (in_array ($ bool , ['false ' , '0 ' , 0 ], true )) {
335
+ $ bool = false ;
336
+ } else {
337
+ $ expected = ['true ' , 'false ' , '1 ' , '0 ' ];
338
+ throw new InvalidArgumentException (sprintf ('Invalid boolean value for "%s" property, expected one of ( "%s" ) ' , $ bool , implode ('" | " ' , $ expected )));
339
+ }
340
+
341
+ for ($ i = 1 ; $ i <= $ nb ; ++$ i ) {
342
+ $ dummy = new EmbeddedDummy ();
343
+ $ dummy ->setName ('Embedded Dummy # ' .$ i );
344
+ $ embeddableDummy = new EmbeddableDummy ();
345
+ $ embeddableDummy ->setDummyName ('Embedded Dummy # ' .$ i );
346
+ $ embeddableDummy ->setDummyBoolean ($ bool );
347
+ $ dummy ->setEmbeddedDummy ($ embeddableDummy );
348
+ $ this ->manager ->persist ($ dummy );
349
+ }
350
+
351
+ $ this ->manager ->flush ();
352
+ }
353
+
354
+ /**
355
+ * @Given there is :nb embedded dummy objects with relatedDummy.embeddedDummy.dummyBoolean :bool
356
+ */
357
+ public function thereIsDummyObjectsWithRelationEmbeddedDummyBoolean ($ nb , $ bool )
358
+ {
359
+ if (in_array ($ bool , ['true ' , '1 ' , 1 ], true )) {
360
+ $ bool = true ;
361
+ } elseif (in_array ($ bool , ['false ' , '0 ' , 0 ], true )) {
362
+ $ bool = false ;
363
+ } else {
364
+ $ expected = ['true ' , 'false ' , '1 ' , '0 ' ];
365
+ throw new InvalidArgumentException (sprintf ('Invalid boolean value for "%s" property, expected one of ( "%s" ) ' , $ bool , implode ('" | " ' , $ expected )));
366
+ }
367
+
368
+ for ($ i = 1 ; $ i <= $ nb ; ++$ i ) {
369
+ $ dummy = new EmbeddedDummy ();
370
+ $ dummy ->setName ('Embedded Dummy # ' .$ i );
371
+ $ embeddableDummy = new EmbeddableDummy ();
372
+ $ embeddableDummy ->setDummyName ('Embedded Dummy # ' .$ i );
373
+ $ embeddableDummy ->setDummyBoolean ($ bool );
374
+
375
+ $ relationDummy = new RelatedDummy ();
376
+ $ relationDummy ->setEmbeddedDummy ($ embeddableDummy );
377
+
378
+ $ dummy ->setRelatedDummy ($ relationDummy );
379
+
380
+ $ this ->manager ->persist ($ relationDummy );
381
+ $ this ->manager ->persist ($ dummy );
382
+ }
383
+
384
+ $ this ->manager ->flush ();
385
+ }
386
+
261
387
/**
262
388
* @Given there is a RelationEmbedder object
263
389
*/
0 commit comments