forked from api-platform/core
-
Notifications
You must be signed in to change notification settings - Fork 2
/
DoctrineContext.php
2208 lines (1863 loc) · 72.4 KB
/
DoctrineContext.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\Core\Tests\Behat;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Doctrine\Orm\EntityManager;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\AbsoluteUrlDummy as AbsoluteUrlDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\AbsoluteUrlRelationDummy as AbsoluteUrlRelationDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Address as AddressDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Answer as AnswerDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Book as BookDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\CompositeItem as CompositeItemDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\CompositeLabel as CompositeLabelDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\CompositePrimitiveItem as CompositePrimitiveItemDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\CompositeRelation as CompositeRelationDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\ConvertedBoolean as ConvertedBoolDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\ConvertedDate as ConvertedDateDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\ConvertedInteger as ConvertedIntegerDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\ConvertedOwner as ConvertedOwnerDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\ConvertedRelated as ConvertedRelatedDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\ConvertedString as ConvertedStringDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Customer as CustomerDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\CustomMultipleIdentifierDummy as CustomMultipleIdentifierDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Dummy as DummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyAggregateOffer as DummyAggregateOfferDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyCar as DummyCarDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyCarColor as DummyCarColorDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyCustomMutation as DummyCustomMutationDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyCustomQuery as DummyCustomQueryDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyDate as DummyDateDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyDifferentGraphQlSerializationGroup as DummyDifferentGraphQlSerializationGroupDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyDtoCustom as DummyDtoCustomDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyDtoNoInput as DummyDtoNoInputDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyDtoNoOutput as DummyDtoNoOutputDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyDtoOutputFallbackToSameClass as DummyDtoOutputFallbackToSameClassDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyDtoOutputSameClass as DummyDtoOutputSameClassDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyFriend as DummyFriendDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyGroup as DummyGroupDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyMercure as DummyMercureDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyOffer as DummyOfferDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyProduct as DummyProductDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyProperty as DummyPropertyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyTableInheritanceNotApiResourceChild as DummyTableInheritanceNotApiResourceChildDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\EmbeddableDummy as EmbeddableDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\EmbeddedDummy as EmbeddedDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\FileConfigDummy as FileConfigDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Foo as FooDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\FooDummy as FooDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\FourthLevel as FourthLevelDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Greeting as GreetingDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\InitializeInput as InitializeInputDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\IriOnlyDummy as IriOnlyDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\MaxDepthDummy as MaxDepthDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\NetworkPathDummy as NetworkPathDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\NetworkPathRelationDummy as NetworkPathRelationDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Order as OrderDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\PatchDummyRelation as PatchDummyRelationDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Person as PersonDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\PersonToPet as PersonToPetDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Pet as PetDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Product as ProductDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Question as QuestionDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\RelatedDummy as RelatedDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\RelatedOwnedDummy as RelatedOwnedDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\RelatedOwningDummy as RelatedOwningDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\RelatedToDummyFriend as RelatedToDummyFriendDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\RelationEmbedder as RelationEmbedderDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\SecuredDummy as SecuredDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\SoMany as SoManyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Taxon as TaxonDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\ThirdLevel as ThirdLevelDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\UrlEncodedId as UrlEncodedIdDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\User as UserDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\WithJsonDummy as WithJsonDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\AbsoluteUrlDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\AbsoluteUrlRelationDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Address;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Answer;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Book;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeItem;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeLabel;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositePrimitiveItem;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeRelation;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ConvertedBoolean;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ConvertedDate;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ConvertedInteger;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ConvertedOwner;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ConvertedRelated;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ConvertedString;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Customer;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CustomMultipleIdentifierDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyAggregateOffer;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyCar;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyCarColor;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyCustomMutation;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyCustomQuery;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDate;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDifferentGraphQlSerializationGroup;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDtoCustom;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDtoNoInput;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDtoNoOutput;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDtoOutputFallbackToSameClass;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDtoOutputSameClass;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyFriend;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyGroup;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyImmutableDate;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyMercure;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyOffer;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyProduct;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyProperty;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceNotApiResourceChild;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\EmbeddableDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\EmbeddedDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ExternalUser;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FileConfigDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Foo;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FooDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FourthLevel;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Greeting;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\InitializeInput;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\InternalUser;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\IriOnlyDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\MaxDepthDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\NetworkPathDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\NetworkPathRelationDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Order;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\PatchDummyRelation;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Person;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\PersonToPet;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Pet;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Product;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Question;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RamseyUuidDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedOwnedDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedOwningDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedToDummyFriend;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelationEmbedder;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\SecuredDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Site;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\SoMany;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Taxon;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ThirdLevel;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\UrlEncodedId;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\User;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\UuidIdentifierDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\WithJsonDummy;
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
/**
* Defines application features from the specific context.
*/
final class DoctrineContext implements Context
{
/**
* @var ObjectManager
*/
private $manager;
private $doctrine;
private $passwordEncoder;
private $schemaTool;
private $schemaManager;
private $classes;
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct(ManagerRegistry $doctrine, UserPasswordEncoderInterface $passwordEncoder)
{
$this->doctrine = $doctrine;
$this->passwordEncoder = $passwordEncoder;
$this->manager = $doctrine->getManager();
$this->schemaTool = $this->manager instanceof EntityManagerInterface ? new SchemaTool($this->manager) : null;
$this->schemaManager = $this->manager instanceof DocumentManager ? $this->manager->getSchemaManager() : null;
$this->classes = $this->manager->getMetadataFactory()->getAllMetadata();
}
/**
* @BeforeScenario @createSchema
*/
public function createDatabase()
{
if ($this->isOrm()) {
$this->schemaTool->dropSchema($this->classes);
$this->schemaTool->createSchema($this->classes);
}
if ($this->isOdm()) {
$this->schemaManager->dropDatabases();
}
$this->doctrine->getManager()->clear();
}
/**
* @Then the DQL should be equal to:
*/
public function theDqlShouldBeEqualTo(PyStringNode $dql)
{
/** @var EntityManager $manager */
$manager = $this->doctrine->getManager();
$actualDql = $manager::$dql;
$expectedDql = preg_replace('/\(\R */', '(', (string) $dql);
$expectedDql = preg_replace('/\R *\)/', ')', $expectedDql);
$expectedDql = preg_replace('/\R */', ' ', $expectedDql);
if ($expectedDql !== $actualDql) {
throw new \RuntimeException("The DQL:\n'$actualDql' is not equal to:\n'$expectedDql'");
}
}
/**
* @Given there are :nb dummy objects
*/
public function thereAreDummyObjects(int $nb)
{
$descriptions = ['Smart dummy.', 'Not so smart dummy.'];
for ($i = 1; $i <= $nb; ++$i) {
$dummy = $this->buildDummy();
$dummy->setName('Dummy #'.$i);
$dummy->setAlias('Alias #'.($nb - $i));
$dummy->setDummy('SomeDummyTest'.$i);
$dummy->setDescription($descriptions[($i - 1) % 2]);
$dummy->nameConverted = 'Converted '.$i;
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb of these so many objects
*/
public function thereAreOfTheseSoManyObjects(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummy = $this->isOrm() ? new SoMany() : new SoManyDocument();
$dummy->content = 'Many #'.$i;
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @When some dummy table inheritance data but not api resource child are created
*/
public function someDummyTableInheritanceDataButNotApiResourceChildAreCreated()
{
$dummy = $this->buildDummyTableInheritanceNotApiResourceChild();
$dummy->setName('Foobarbaz inheritance');
$this->manager->persist($dummy);
$this->manager->flush();
}
/**
* @Given there are :nb foo objects with fake names
*/
public function thereAreFooObjectsWithFakeNames(int $nb)
{
$names = ['Hawsepipe', 'Sthenelus', 'Ephesian', 'Separativeness', 'Balbo'];
$bars = ['Lorem', 'Ipsum', 'Dolor', 'Sit', 'Amet'];
for ($i = 0; $i < $nb; ++$i) {
$foo = $this->buildFoo();
$foo->setName($names[$i]);
$foo->setBar($bars[$i]);
$this->manager->persist($foo);
}
$this->manager->flush();
}
/**
* @Given there are :nb fooDummy objects with fake names
*/
public function thereAreFooDummyObjectsWithFakeNames($nb)
{
$names = ['Hawsepipe', 'Ephesian', 'Sthenelus', 'Separativeness', 'Balbo'];
$dummies = ['Lorem', 'Ipsum', 'Dolor', 'Sit', 'Amet'];
for ($i = 0; $i < $nb; ++$i) {
$dummy = $this->buildDummy();
$dummy->setName($dummies[$i]);
$foo = $this->buildFooDummy();
$foo->setName($names[$i]);
$foo->setDummy($dummy);
$this->manager->persist($foo);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy group objects
*/
public function thereAreDummyGroupObjects(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummyGroup = $this->buildDummyGroup();
foreach (['foo', 'bar', 'baz', 'qux'] as $property) {
$dummyGroup->{$property} = ucfirst($property).' #'.$i;
}
$this->manager->persist($dummyGroup);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy property objects
*/
public function thereAreDummyPropertyObjects(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummyProperty = $this->buildDummyProperty();
$dummyGroup = $this->buildDummyGroup();
foreach (['foo', 'bar', 'baz'] as $property) {
$dummyProperty->{$property} = $dummyGroup->{$property} = ucfirst($property).' #'.$i;
}
$dummyProperty->nameConverted = "NameConverted #$i";
$dummyProperty->group = $dummyGroup;
$this->manager->persist($dummyGroup);
$this->manager->persist($dummyProperty);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy property objects with a shared group
*/
public function thereAreDummyPropertyObjectsWithASharedGroup(int $nb)
{
$dummyGroup = $this->buildDummyGroup();
foreach (['foo', 'bar', 'baz'] as $property) {
$dummyGroup->{$property} = ucfirst($property).' #shared';
}
$this->manager->persist($dummyGroup);
for ($i = 1; $i <= $nb; ++$i) {
$dummyProperty = $this->buildDummyProperty();
foreach (['foo', 'bar', 'baz'] as $property) {
$dummyProperty->{$property} = ucfirst($property).' #'.$i;
}
$dummyProperty->group = $dummyGroup;
$this->manager->persist($dummyProperty);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy property objects with different number of related groups
*/
public function thereAreDummyPropertyObjectsWithADifferentNumberRelatedGroups(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummyGroup = $this->buildDummyGroup();
$dummyProperty = $this->buildDummyProperty();
foreach (['foo', 'bar', 'baz'] as $property) {
$dummyProperty->{$property} = $dummyGroup->{$property} = ucfirst($property).' #'.$i;
}
$this->manager->persist($dummyGroup);
$dummyGroups[$i] = $dummyGroup;
for ($j = 1; $j <= $i; ++$j) {
$dummyProperty->groups[] = $dummyGroups[$j];
}
$this->manager->persist($dummyProperty);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy property objects with :nb2 groups
*/
public function thereAreDummyPropertyObjectsWithGroups(int $nb, int $nb2)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummyProperty = $this->buildDummyProperty();
$dummyGroup = $this->buildDummyGroup();
foreach (['foo', 'bar', 'baz'] as $property) {
$dummyProperty->{$property} = $dummyGroup->{$property} = ucfirst($property).' #'.$i;
}
$dummyProperty->group = $dummyGroup;
$this->manager->persist($dummyGroup);
for ($j = 1; $j <= $nb2; ++$j) {
$dummyGroup = $this->buildDummyGroup();
foreach (['foo', 'bar', 'baz'] as $property) {
$dummyGroup->{$property} = ucfirst($property).' #'.$i.$j;
}
$dummyProperty->groups[] = $dummyGroup;
$this->manager->persist($dummyGroup);
}
$this->manager->persist($dummyProperty);
}
$this->manager->flush();
}
/**
* @Given there are :nb embedded dummy objects
*/
public function thereAreEmbeddedDummyObjects(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummy = $this->buildEmbeddedDummy();
$dummy->setName('Dummy #'.$i);
$embeddableDummy = $this->buildEmbeddableDummy();
$embeddableDummy->setDummyName('Dummy #'.$i);
$dummy->setEmbeddedDummy($embeddableDummy);
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy objects with relatedDummy
*/
public function thereAreDummyObjectsWithRelatedDummy(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$relatedDummy = $this->buildRelatedDummy();
$relatedDummy->setName('RelatedDummy #'.$i);
$dummy = $this->buildDummy();
$dummy->setName('Dummy #'.$i);
$dummy->setAlias('Alias #'.($nb - $i));
$dummy->nameConverted = "Converted $i";
$dummy->setRelatedDummy($relatedDummy);
$this->manager->persist($relatedDummy);
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are dummies with similar properties
*/
public function thereAreDummiesWithSimilarProperties()
{
$dummy1 = $this->buildDummy();
$dummy1->setName('foo');
$dummy1->setDescription('bar');
$dummy2 = $this->buildDummy();
$dummy2->setName('baz');
$dummy2->setDescription('qux');
$dummy3 = $this->buildDummy();
$dummy3->setName('foo');
$dummy3->setDescription('qux');
$dummy4 = $this->buildDummy();
$dummy4->setName('baz');
$dummy4->setDescription('bar');
$this->manager->persist($dummy1);
$this->manager->persist($dummy2);
$this->manager->persist($dummy3);
$this->manager->persist($dummy4);
$this->manager->flush();
}
/**
* @Given there are :nb dummyDtoNoInput objects
*/
public function thereAreDummyDtoNoInputObjects(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummyDto = $this->buildDummyDtoNoInput();
$dummyDto->lorem = 'DummyDtoNoInput foo #'.$i;
$dummyDto->ipsum = round($i / 3, 2);
$this->manager->persist($dummyDto);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummyDtoNoOutput objects
*/
public function thereAreDummyDtoNoOutputObjects(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummyDto = $this->buildDummyDtoNoOutput();
$dummyDto->lorem = 'DummyDtoNoOutput foo #'.$i;
$dummyDto->ipsum = (string) ($i / 3);
$this->manager->persist($dummyDto);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummyCustomQuery objects
*/
public function thereAreDummyCustomQueryObjects(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummyCustomQuery = $this->buildDummyCustomQuery();
$this->manager->persist($dummyCustomQuery);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummyCustomMutation objects
*/
public function thereAreDummyCustomMutationObjects(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$customMutationDummy = $this->buildDummyCustomMutation();
$customMutationDummy->setOperandA(3);
$this->manager->persist($customMutationDummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy objects with JSON and array data
*/
public function thereAreDummyObjectsWithJsonData(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummy = $this->buildDummy();
$dummy->setName('Dummy #'.$i);
$dummy->setAlias('Alias #'.($nb - $i));
$dummy->setJsonData(['foo' => ['bar', 'baz'], 'bar' => 5]);
$dummy->setArrayData(['foo', 'bar', 'baz']);
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy with null JSON objects
*/
public function thereAreDummyWithNullJsonObjects(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummy = $this->buildWithJsonDummy();
$dummy->json = null;
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy objects with relatedDummy and its thirdLevel
* @Given there is :nb dummy object with relatedDummy and its thirdLevel
*/
public function thereAreDummyObjectsWithRelatedDummyAndItsThirdLevel(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$thirdLevel = $this->buildThirdLevel();
$relatedDummy = $this->buildRelatedDummy();
$relatedDummy->setName('RelatedDummy #'.$i);
$relatedDummy->setThirdLevel($thirdLevel);
$dummy = $this->buildDummy();
$dummy->setName('Dummy #'.$i);
$dummy->setAlias('Alias #'.($nb - $i));
$dummy->setRelatedDummy($relatedDummy);
$this->manager->persist($thirdLevel);
$this->manager->persist($relatedDummy);
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy objects with embeddedDummy
*/
public function thereAreDummyObjectsWithEmbeddedDummy(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$embeddableDummy = $this->buildEmbeddableDummy();
$embeddableDummy->setDummyName('EmbeddedDummy #'.$i);
$dummy = $this->buildEmbeddedDummy();
$dummy->setName('Dummy #'.$i);
$dummy->setEmbeddedDummy($embeddableDummy);
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy objects having each :nbrelated relatedDummies
*/
public function thereAreDummyObjectsWithRelatedDummies(int $nb, int $nbrelated)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummy = $this->buildDummy();
$dummy->setName('Dummy #'.$i);
$dummy->setAlias('Alias #'.($nb - $i));
for ($j = 1; $j <= $nbrelated; ++$j) {
$relatedDummy = $this->buildRelatedDummy();
$relatedDummy->setName('RelatedDummy'.$j.$i);
$this->manager->persist($relatedDummy);
$dummy->addRelatedDummy($relatedDummy);
}
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy objects with dummyDate
* @Given there is :nb dummy object with dummyDate
*/
public function thereAreDummyObjectsWithDummyDate(int $nb)
{
$descriptions = ['Smart dummy.', 'Not so smart dummy.'];
for ($i = 1; $i <= $nb; ++$i) {
$date = new \DateTime(sprintf('2015-04-%d', $i), new \DateTimeZone('UTC'));
$dummy = $this->buildDummy();
$dummy->setName('Dummy #'.$i);
$dummy->setAlias('Alias #'.($nb - $i));
$dummy->setDescription($descriptions[($i - 1) % 2]);
// Last Dummy has a null date
if ($nb !== $i) {
$dummy->setDummyDate($date);
}
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy objects with dummyDate and dummyBoolean :bool
*/
public function thereAreDummyObjectsWithDummyDateAndDummyBoolean(int $nb, string $bool)
{
$descriptions = ['Smart dummy.', 'Not so smart dummy.'];
if (\in_array($bool, ['true', '1', 1], true)) {
$bool = true;
} elseif (\in_array($bool, ['false', '0', 0], true)) {
$bool = false;
} else {
$expected = ['true', 'false', '1', '0'];
throw new \InvalidArgumentException(sprintf('Invalid boolean value for "%s" property, expected one of ( "%s" )', $bool, implode('" | "', $expected)));
}
for ($i = 1; $i <= $nb; ++$i) {
$date = new \DateTime(sprintf('2015-04-%d', $i), new \DateTimeZone('UTC'));
$dummy = $this->buildDummy();
$dummy->setName('Dummy #'.$i);
$dummy->setAlias('Alias #'.($nb - $i));
$dummy->setDescription($descriptions[($i - 1) % 2]);
$dummy->setDummyBoolean($bool);
// Last Dummy has a null date
if ($nb !== $i) {
$dummy->setDummyDate($date);
}
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy objects with dummyDate and relatedDummy
*/
public function thereAreDummyObjectsWithDummyDateAndRelatedDummy(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$date = new \DateTime(sprintf('2015-04-%d', $i), new \DateTimeZone('UTC'));
$relatedDummy = $this->buildRelatedDummy();
$relatedDummy->setName('RelatedDummy #'.$i);
$relatedDummy->setDummyDate($date);
$dummy = $this->buildDummy();
$dummy->setName('Dummy #'.$i);
$dummy->setAlias('Alias #'.($nb - $i));
$dummy->setRelatedDummy($relatedDummy);
// Last Dummy has a null date
if ($nb !== $i) {
$dummy->setDummyDate($date);
}
$this->manager->persist($relatedDummy);
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb embedded dummy objects with dummyDate and embeddedDummy
*/
public function thereAreDummyObjectsWithDummyDateAndEmbeddedDummy(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$date = new \DateTime(sprintf('2015-04-%d', $i), new \DateTimeZone('UTC'));
$embeddableDummy = $this->buildEmbeddableDummy();
$embeddableDummy->setDummyName('Embeddable #'.$i);
$embeddableDummy->setDummyDate($date);
$dummy = $this->buildEmbeddedDummy();
$dummy->setName('Dummy #'.$i);
$dummy->setEmbeddedDummy($embeddableDummy);
// Last Dummy has a null date
if ($nb !== $i) {
$dummy->setDummyDate($date);
}
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb convertedDate objects
*/
public function thereAreconvertedDateObjectsWith(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$convertedDate = $this->buildConvertedDate();
$convertedDate->nameConverted = new \DateTime(sprintf('2015-04-%d', $i), new \DateTimeZone('UTC'));
$this->manager->persist($convertedDate);
}
$this->manager->flush();
}
/**
* @Given there are :nb convertedString objects
*/
public function thereAreconvertedStringObjectsWith(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$convertedString = $this->buildConvertedString();
$convertedString->nameConverted = ($i % 2) ? "name#$i" : null;
$this->manager->persist($convertedString);
}
$this->manager->flush();
}
/**
* @Given there are :nb convertedBoolean objects
*/
public function thereAreconvertedBooleanObjectsWith(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$convertedBoolean = $this->buildConvertedBoolean();
$convertedBoolean->nameConverted = (bool) ($i % 2);
$this->manager->persist($convertedBoolean);
}
$this->manager->flush();
}
/**
* @Given there are :nb convertedInteger objects
*/
public function thereAreconvertedIntegerObjectsWith(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$convertedInteger = $this->buildConvertedInteger();
$convertedInteger->nameConverted = $i;
$this->manager->persist($convertedInteger);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy objects with dummyPrice
*/
public function thereAreDummyObjectsWithDummyPrice(int $nb)
{
$descriptions = ['Smart dummy.', 'Not so smart dummy.'];
$prices = ['9.99', '12.99', '15.99', '19.99'];
for ($i = 1; $i <= $nb; ++$i) {
$dummy = $this->buildDummy();
$dummy->setName('Dummy #'.$i);
$dummy->setAlias('Alias #'.($nb - $i));
$dummy->setDescription($descriptions[($i - 1) % 2]);
$dummy->setDummyPrice($prices[($i - 1) % 4]);
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb dummy objects with dummyBoolean :bool
* @Given there is :nb dummy object with dummyBoolean :bool
*/
public function thereAreDummyObjectsWithDummyBoolean(int $nb, string $bool)
{
if (\in_array($bool, ['true', '1', 1], true)) {
$bool = true;
} elseif (\in_array($bool, ['false', '0', 0], true)) {
$bool = false;
} else {
$expected = ['true', 'false', '1', '0'];
throw new \InvalidArgumentException(sprintf('Invalid boolean value for "%s" property, expected one of ( "%s" )', $bool, implode('" | "', $expected)));
}
$descriptions = ['Smart dummy.', 'Not so smart dummy.'];
for ($i = 1; $i <= $nb; ++$i) {
$dummy = $this->buildDummy();
$dummy->setName('Dummy #'.$i);
$dummy->setAlias('Alias #'.($nb - $i));
$dummy->setDescription($descriptions[($i - 1) % 2]);
$dummy->setDummyBoolean($bool);
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb embedded dummy objects with embeddedDummy.dummyBoolean :bool
*/
public function thereAreDummyObjectsWithEmbeddedDummyBoolean(int $nb, string $bool)
{
if (\in_array($bool, ['true', '1', 1], true)) {
$bool = true;
} elseif (\in_array($bool, ['false', '0', 0], true)) {
$bool = false;
} else {
$expected = ['true', 'false', '1', '0'];
throw new \InvalidArgumentException(sprintf('Invalid boolean value for "%s" property, expected one of ( "%s" )', $bool, implode('" | "', $expected)));
}
for ($i = 1; $i <= $nb; ++$i) {
$dummy = $this->buildEmbeddedDummy();
$dummy->setName('Embedded Dummy #'.$i);
$embeddableDummy = $this->buildEmbeddableDummy();
$embeddableDummy->setDummyName('Embedded Dummy #'.$i);
$embeddableDummy->setDummyBoolean($bool);
$dummy->setEmbeddedDummy($embeddableDummy);
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb embedded dummy objects with relatedDummy.embeddedDummy.dummyBoolean :bool
*/
public function thereAreDummyObjectsWithRelationEmbeddedDummyBoolean(int $nb, string $bool)
{
if (\in_array($bool, ['true', '1', 1], true)) {
$bool = true;
} elseif (\in_array($bool, ['false', '0', 0], true)) {
$bool = false;
} else {
$expected = ['true', 'false', '1', '0'];
throw new \InvalidArgumentException(sprintf('Invalid boolean value for "%s" property, expected one of ( "%s" )', $bool, implode('" | "', $expected)));
}
for ($i = 1; $i <= $nb; ++$i) {
$dummy = $this->buildEmbeddedDummy();
$dummy->setName('Embedded Dummy #'.$i);
$embeddableDummy = $this->buildEmbeddableDummy();
$embeddableDummy->setDummyName('Embedded Dummy #'.$i);
$embeddableDummy->setDummyBoolean($bool);
$relationDummy = $this->buildRelatedDummy();
$relationDummy->setEmbeddedDummy($embeddableDummy);
$dummy->setRelatedDummy($relationDummy);
$this->manager->persist($relationDummy);
$this->manager->persist($dummy);
}
$this->manager->flush();
}
/**
* @Given there are :nb SecuredDummy objects
*/
public function thereAreSecuredDummyObjects(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$securedDummy = $this->buildSecuredDummy();
$securedDummy->setTitle("#$i");
$securedDummy->setDescription("Hello #$i");
$securedDummy->setOwner('notexist');
$this->manager->persist($securedDummy);
}
$this->manager->flush();
}
/**
* @Given there is a RelationEmbedder object
*/
public function thereIsARelationEmbedderObject()
{
$relationEmbedder = $this->buildRelationEmbedder();
$this->manager->persist($relationEmbedder);
$this->manager->flush();
}
/**
* @Given there is a Dummy Object mapped by UUID
*/
public function thereIsADummyObjectMappedByUUID()