1212use Symfony \Component \Validator \Validator \ValidatorInterface ;
1313use Zenstruck \Foundry \Test \Factories ;
1414
15- class FieldTest extends KernelTestCase
15+ class FieldUnitTest extends KernelTestCase
1616{
1717 use Factories;
1818
@@ -25,23 +25,23 @@ protected function setUp(): void
2525
2626 public function testDefineCommunityOrPlace (): void
2727 {
28- $ field = DummyFieldFactory::createOne ([
29- 'community ' => DummyCommunityFactory::createOne (),
28+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
29+ 'community ' => DummyCommunityFactory::new ()-> withoutPersisting ()-> create (),
3030 'name ' => FieldCommunity::NAME ->value ,
3131 ]);
3232 $ violations = $ this ->validator ->validate ($ field );
3333 static ::assertCount (0 , $ violations );
3434
35- $ field = DummyFieldFactory::createOne ([
36- 'community ' => DummyCommunityFactory::createOne (),
37- 'place ' => DummyPlaceFactory::createOne (),
35+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
36+ 'community ' => DummyCommunityFactory::new ()-> withoutPersisting ()-> create (),
37+ 'place ' => DummyPlaceFactory::new ()-> withoutPersisting ()-> create (),
3838 'name ' => FieldCommunity::NAME ->value ,
3939 ]);
4040 $ violations = $ this ->validator ->validate ($ field );
4141 static ::assertCount (1 , $ violations );
4242 static ::assertEquals ('Field must be attached to a community or a place, not none, not both ' , $ violations ->get (0 )->getMessage ());
4343
44- $ field = DummyFieldFactory::createOne ([
44+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
4545 'name ' => FieldCommunity::NAME ->value ,
4646 ]);
4747 static ::assertCount (1 , $ violations );
@@ -50,16 +50,16 @@ public function testDefineCommunityOrPlace(): void
5050
5151 public function testDefineWrongType (): void
5252 {
53- $ field = DummyFieldFactory::createOne ([
54- 'community ' => DummyCommunityFactory::createOne (),
53+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
54+ 'community ' => DummyCommunityFactory::new ()-> withoutPersisting ()-> create (),
5555 'name ' => 'toto ' ,
5656 ]);
5757 $ violations = $ this ->validator ->validate ($ field );
5858 static ::assertCount (1 , $ violations );
5959 static ::assertEquals ('Field toto is not acceptable ' , $ violations ->get (0 )->getMessage ());
6060
61- $ field = DummyFieldFactory::createOne ([
62- 'place ' => DummyPlaceFactory::createOne (),
61+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
62+ 'place ' => DummyPlaceFactory::new ()-> withoutPersisting ()-> create (),
6363 'name ' => 'toto ' ,
6464 ]);
6565 $ violations = $ this ->validator ->validate ($ field );
@@ -69,50 +69,50 @@ public function testDefineWrongType(): void
6969
7070 public function testNotInsertCommunitiesInReplacesField (): void
7171 {
72- $ field = DummyFieldFactory::createOne ([
73- 'community ' => DummyCommunityFactory::createOne (),
72+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
73+ 'community ' => DummyCommunityFactory::new ()-> withoutPersisting ()-> create (),
7474 'name ' => FieldCommunity::REPLACES ->value ,
75- 'value ' => DummyCommunityFactory::createOne ()->_real (),
75+ 'value ' => DummyCommunityFactory::new ()-> withoutPersisting ()-> create ()->_real (),
7676 ]);
7777 $ violations = $ this ->validator ->validate ($ field );
7878
7979 static ::assertCount (1 , $ violations );
8080 static ::assertEquals ('Field replaces expected value of type Community[] ' , $ violations ->get (0 )->getMessage ());
8181
82- $ field = DummyFieldFactory::createOne ([
83- 'community ' => DummyCommunityFactory::createOne (),
82+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
83+ 'community ' => DummyCommunityFactory::new ()-> withoutPersisting ()-> create (),
8484 'name ' => FieldCommunity::REPLACES ->value ,
85- 'value ' => [DummyPlaceFactory::createOne ()->_real ()],
85+ 'value ' => [DummyPlaceFactory::new ()-> withoutPersisting ()-> create ()->_real ()],
8686 ]);
8787 $ violations = $ this ->validator ->validate ($ field );
8888 static ::assertEquals ('Field replaces expected value of type Community[] ' , $ violations ->get (0 )->getMessage ());
8989 }
9090
9191 public function testNotInsertPlacesInReplacesField (): void
9292 {
93- $ field = DummyFieldFactory::createOne ([
94- 'place ' => DummyPlaceFactory::createOne (),
93+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
94+ 'place ' => DummyPlaceFactory::new ()-> withoutPersisting ()-> create (),
9595 'name ' => FieldPlace::REPLACES ->value ,
96- 'value ' => DummyPlaceFactory::createOne ()->_real (),
96+ 'value ' => DummyPlaceFactory::new ()-> withoutPersisting ()-> create ()->_real (),
9797 ]);
9898 $ violations = $ this ->validator ->validate ($ field );
9999
100100 static ::assertCount (1 , $ violations );
101101 static ::assertEquals ('Field replaces expected value of type Place[] ' , $ violations ->get (0 )->getMessage ());
102102
103- $ field = DummyFieldFactory::createOne ([
104- 'place ' => DummyPlaceFactory::createOne (),
103+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
104+ 'place ' => DummyPlaceFactory::new ()-> withoutPersisting ()-> create (),
105105 'name ' => FieldPlace::REPLACES ->value ,
106- 'value ' => [DummyCommunityFactory::createOne ()->_real ()],
106+ 'value ' => [DummyCommunityFactory::new ()-> withoutPersisting ()-> create ()->_real ()],
107107 ]);
108108 $ violations = $ this ->validator ->validate ($ field );
109109 static ::assertEquals ('Field replaces expected value of type Place[] ' , $ violations ->get (0 )->getMessage ());
110110 }
111111
112112 public function testShouldFailIfValueNotInArray (): void
113113 {
114- $ field = DummyFieldFactory::createOne ([
115- 'place ' => DummyPlaceFactory::createOne (),
114+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
115+ 'place ' => DummyPlaceFactory::new ()-> withoutPersisting ()-> create (),
116116 'name ' => FieldPlace::TYPE ->value ,
117117 'value ' => 'toto ' ,
118118 ]);
0 commit comments