File tree 1 file changed +32
-0
lines changed
src/Symfony/Component/Validator/Tests/Constraints
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 13
13
14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Component \Validator \Constraints \Valid ;
16
+ use Symfony \Component \Validator \Mapping \ClassMetadata ;
17
+ use Symfony \Component \Validator \Mapping \Loader \AnnotationLoader ;
16
18
17
19
/**
18
20
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -32,4 +34,34 @@ public function testGroupsAreNullByDefault()
32
34
33
35
$ this ->assertNull ($ constraint ->groups );
34
36
}
37
+
38
+ /**
39
+ * @requires PHP 8
40
+ */
41
+ public function testAttributes ()
42
+ {
43
+ $ metadata = new ClassMetaData (ValidDummy::class);
44
+ $ loader = new AnnotationLoader ();
45
+ self ::assertTrue ($ loader ->loadClassMetadata ($ metadata ));
46
+
47
+ [$ bConstraint ] = $ metadata ->properties ['b ' ]->getConstraints ();
48
+ self ::assertFalse ($ bConstraint ->traverse );
49
+ self ::assertSame (['traverse_group ' ], $ bConstraint ->groups );
50
+
51
+ [$ cConstraint ] = $ metadata ->properties ['c ' ]->getConstraints ();
52
+ self ::assertSame (['my_group ' ], $ cConstraint ->groups );
53
+ self ::assertSame ('some attached data ' , $ cConstraint ->payload );
54
+ }
55
+ }
56
+
57
+ class ValidDummy
58
+ {
59
+ #[Valid]
60
+ private $ a ;
61
+
62
+ #[Valid(groups: ['traverse_group ' ], traverse: false )] // Needs a group to work at all for this test
63
+ private $ b ;
64
+
65
+ #[Valid(groups: ['my_group ' ], payload: 'some attached data ' )]
66
+ private $ c ;
35
67
}
You can’t perform that action at this time.
0 commit comments