@@ -13,32 +13,77 @@ use Tests\Fixtures\Mapping\Validator\SimpleEntity;
1313Toolkit::test (function (): void {
1414 $ validator = new SymfonyValidator (new AnnotationReader ());
1515
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+ }
1830});
1931
2032// Invalid value
2133Toolkit::test (function (): void {
2234 $ validator = new SymfonyValidator (new AnnotationReader ());
2335
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+ ]);
2543
26- Assert:: exception ( static function () use ( $ entity , $ validator ): void {
44+ try {
2745 $ 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+ }
2955});
3056
3157// Without annotation reader
3258Toolkit::test (function (): void {
3359 $ validator = new SymfonyValidator ();
3460
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+ ]);
3668
37- Assert:: exception ( static function () use ( $ entity , $ validator ): void {
69+ try {
3870 $ 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+ }
4079
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+ ]);
4287
4388 Assert::noError (static function () use ($ entity , $ validator ): void {
4489 $ validator ->validate ($ entity );
0 commit comments