@@ -13,32 +13,77 @@ use Tests\Fixtures\Mapping\Validator\SimpleEntity;
13
13
Toolkit::test (function (): void {
14
14
$ validator = new SymfonyValidator (new AnnotationReader ());
15
15
16
- $ entity = (new SimpleEntity ())->factory (['id ' => 1 , 'typedId ' => 1 ]);
17
- $ validator ->validate ($ entity );
16
+ $ entity = (new SimpleEntity ())->factory ([
17
+ 'id ' => 1 ,
18
+ 'typedId1 ' => 1 ,
19
+ 'typedId2 ' => 1 ,
20
+ 'typedId3 ' => 1 ,
21
+ 'typedId4 ' => 1 ,
22
+ ]);
23
+
24
+ try {
25
+ $ validator ->validate ($ entity );
26
+ Assert::true (true );
27
+ } catch (ValidationException $ e ) {
28
+ Assert::fail ('Validation should pass ' , null , null , $ e );
29
+ }
18
30
});
19
31
20
32
// Invalid value
21
33
Toolkit::test (function (): void {
22
34
$ validator = new SymfonyValidator (new AnnotationReader ());
23
35
24
- $ entity = (new SimpleEntity ())->factory (['id ' => 1 , 'typedId ' => 'foo ' ]);
36
+ $ entity = (new SimpleEntity ())->factory ([
37
+ 'id ' => 1 ,
38
+ 'typedId1 ' => 'foo ' ,
39
+ 'typedId2 ' => 'foo ' ,
40
+ 'typedId3 ' => 1 ,
41
+ 'typedId4 ' => 1 ,
42
+ ]);
25
43
26
- Assert:: exception ( static function () use ( $ entity , $ validator ): void {
44
+ try {
27
45
$ validator ->validate ($ entity );
28
- }, ValidationException::class);
46
+ Assert::fail ('Validation should fail ' );
47
+ } catch (ValidationException $ e ) {
48
+ Assert::equal ([
49
+ 'validation ' => [
50
+ 'typedId1 ' => ['This value should be of type integer. ' ],
51
+ 'typedId2 ' => ['This value should not be null. ' ],
52
+ ],
53
+ ], $ e ->getContext ());
54
+ }
29
55
});
30
56
31
57
// Without annotation reader
32
58
Toolkit::test (function (): void {
33
59
$ validator = new SymfonyValidator ();
34
60
35
- $ entity = (new SimpleEntity ())->factory (['id ' => null , 'typedId ' => 'foo ' ]);
61
+ $ entity = (new SimpleEntity ())->factory ([
62
+ 'id ' => null ,
63
+ 'typedId1 ' => 1 ,
64
+ 'typedId2 ' => 'foo ' ,
65
+ 'typedId3 ' => 1 ,
66
+ 'typedId4 ' => 1 ,
67
+ ]);
36
68
37
- Assert:: exception ( static function () use ( $ entity , $ validator ): void {
69
+ try {
38
70
$ validator ->validate ($ entity );
39
- }, ValidationException::class);
71
+ Assert::fail ('Validation should fail ' );
72
+ } catch (ValidationException $ e ) {
73
+ Assert::equal ([
74
+ 'validation ' => [
75
+ 'typedId2 ' => ['This value should not be null. ' ],
76
+ ],
77
+ ], $ e ->getContext ());
78
+ }
40
79
41
- $ entity = (new SimpleEntity ())->factory (['id ' => null , 'typedId ' => 1 ]);
80
+ $ entity = (new SimpleEntity ())->factory ([
81
+ 'id ' => null ,
82
+ 'typedId1 ' => 1 ,
83
+ 'typedId2 ' => 1 ,
84
+ 'typedId3 ' => 1 ,
85
+ 'typedId4 ' => 1 ,
86
+ ]);
42
87
43
88
Assert::noError (static function () use ($ entity , $ validator ): void {
44
89
$ validator ->validate ($ entity );
0 commit comments