12
12
use Symfony \Component \Validator \Validator \ValidatorInterface ;
13
13
use Zenstruck \Foundry \Test \Factories ;
14
14
15
- class FieldTest extends KernelTestCase
15
+ class FieldUnitTest extends KernelTestCase
16
16
{
17
17
use Factories;
18
18
@@ -25,23 +25,23 @@ protected function setUp(): void
25
25
26
26
public function testDefineCommunityOrPlace (): void
27
27
{
28
- $ field = DummyFieldFactory::createOne ([
29
- 'community ' => DummyCommunityFactory::createOne (),
28
+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
29
+ 'community ' => DummyCommunityFactory::new ()-> withoutPersisting ()-> create (),
30
30
'name ' => FieldCommunity::NAME ->value ,
31
31
]);
32
32
$ violations = $ this ->validator ->validate ($ field );
33
33
static ::assertCount (0 , $ violations );
34
34
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 (),
38
38
'name ' => FieldCommunity::NAME ->value ,
39
39
]);
40
40
$ violations = $ this ->validator ->validate ($ field );
41
41
static ::assertCount (1 , $ violations );
42
42
static ::assertEquals ('Field must be attached to a community or a place, not none, not both ' , $ violations ->get (0 )->getMessage ());
43
43
44
- $ field = DummyFieldFactory::createOne ([
44
+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
45
45
'name ' => FieldCommunity::NAME ->value ,
46
46
]);
47
47
static ::assertCount (1 , $ violations );
@@ -50,16 +50,16 @@ public function testDefineCommunityOrPlace(): void
50
50
51
51
public function testDefineWrongType (): void
52
52
{
53
- $ field = DummyFieldFactory::createOne ([
54
- 'community ' => DummyCommunityFactory::createOne (),
53
+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
54
+ 'community ' => DummyCommunityFactory::new ()-> withoutPersisting ()-> create (),
55
55
'name ' => 'toto ' ,
56
56
]);
57
57
$ violations = $ this ->validator ->validate ($ field );
58
58
static ::assertCount (1 , $ violations );
59
59
static ::assertEquals ('Field toto is not acceptable ' , $ violations ->get (0 )->getMessage ());
60
60
61
- $ field = DummyFieldFactory::createOne ([
62
- 'place ' => DummyPlaceFactory::createOne (),
61
+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
62
+ 'place ' => DummyPlaceFactory::new ()-> withoutPersisting ()-> create (),
63
63
'name ' => 'toto ' ,
64
64
]);
65
65
$ violations = $ this ->validator ->validate ($ field );
@@ -69,50 +69,50 @@ public function testDefineWrongType(): void
69
69
70
70
public function testNotInsertCommunitiesInReplacesField (): void
71
71
{
72
- $ field = DummyFieldFactory::createOne ([
73
- 'community ' => DummyCommunityFactory::createOne (),
72
+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
73
+ 'community ' => DummyCommunityFactory::new ()-> withoutPersisting ()-> create (),
74
74
'name ' => FieldCommunity::REPLACES ->value ,
75
- 'value ' => DummyCommunityFactory::createOne ()->_real (),
75
+ 'value ' => DummyCommunityFactory::new ()-> withoutPersisting ()-> create ()->_real (),
76
76
]);
77
77
$ violations = $ this ->validator ->validate ($ field );
78
78
79
79
static ::assertCount (1 , $ violations );
80
80
static ::assertEquals ('Field replaces expected value of type Community[] ' , $ violations ->get (0 )->getMessage ());
81
81
82
- $ field = DummyFieldFactory::createOne ([
83
- 'community ' => DummyCommunityFactory::createOne (),
82
+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
83
+ 'community ' => DummyCommunityFactory::new ()-> withoutPersisting ()-> create (),
84
84
'name ' => FieldCommunity::REPLACES ->value ,
85
- 'value ' => [DummyPlaceFactory::createOne ()->_real ()],
85
+ 'value ' => [DummyPlaceFactory::new ()-> withoutPersisting ()-> create ()->_real ()],
86
86
]);
87
87
$ violations = $ this ->validator ->validate ($ field );
88
88
static ::assertEquals ('Field replaces expected value of type Community[] ' , $ violations ->get (0 )->getMessage ());
89
89
}
90
90
91
91
public function testNotInsertPlacesInReplacesField (): void
92
92
{
93
- $ field = DummyFieldFactory::createOne ([
94
- 'place ' => DummyPlaceFactory::createOne (),
93
+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
94
+ 'place ' => DummyPlaceFactory::new ()-> withoutPersisting ()-> create (),
95
95
'name ' => FieldPlace::REPLACES ->value ,
96
- 'value ' => DummyPlaceFactory::createOne ()->_real (),
96
+ 'value ' => DummyPlaceFactory::new ()-> withoutPersisting ()-> create ()->_real (),
97
97
]);
98
98
$ violations = $ this ->validator ->validate ($ field );
99
99
100
100
static ::assertCount (1 , $ violations );
101
101
static ::assertEquals ('Field replaces expected value of type Place[] ' , $ violations ->get (0 )->getMessage ());
102
102
103
- $ field = DummyFieldFactory::createOne ([
104
- 'place ' => DummyPlaceFactory::createOne (),
103
+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
104
+ 'place ' => DummyPlaceFactory::new ()-> withoutPersisting ()-> create (),
105
105
'name ' => FieldPlace::REPLACES ->value ,
106
- 'value ' => [DummyCommunityFactory::createOne ()->_real ()],
106
+ 'value ' => [DummyCommunityFactory::new ()-> withoutPersisting ()-> create ()->_real ()],
107
107
]);
108
108
$ violations = $ this ->validator ->validate ($ field );
109
109
static ::assertEquals ('Field replaces expected value of type Place[] ' , $ violations ->get (0 )->getMessage ());
110
110
}
111
111
112
112
public function testShouldFailIfValueNotInArray (): void
113
113
{
114
- $ field = DummyFieldFactory::createOne ([
115
- 'place ' => DummyPlaceFactory::createOne (),
114
+ $ field = DummyFieldFactory::new ()-> withoutPersisting ()-> create ([
115
+ 'place ' => DummyPlaceFactory::new ()-> withoutPersisting ()-> create (),
116
116
'name ' => FieldPlace::TYPE ->value ,
117
117
'value ' => 'toto ' ,
118
118
]);
0 commit comments