File tree Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ public function __construct($options = null)
108
108
$ defaultOption = $ this ->getDefaultOption ();
109
109
$ invalidOptions = [];
110
110
$ missingOptions = array_flip ((array ) $ this ->getRequiredOptions ());
111
- $ knownOptions = get_object_vars ( $ this );
111
+ $ knownOptions = get_class_vars ( static ::class );
112
112
113
113
// The "groups" option is added to the object lazily
114
114
$ knownOptions ['groups ' ] = true ;
Original file line number Diff line number Diff line change 13
13
14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Component \Validator \Constraint ;
16
+ use Symfony \Component \Validator \Exception \InvalidOptionsException ;
16
17
use Symfony \Component \Validator \Tests \Fixtures \ClassConstraint ;
17
18
use Symfony \Component \Validator \Tests \Fixtures \ConstraintA ;
18
19
use Symfony \Component \Validator \Tests \Fixtures \ConstraintB ;
19
20
use Symfony \Component \Validator \Tests \Fixtures \ConstraintC ;
21
+ use Symfony \Component \Validator \Tests \Fixtures \ConstraintWithStaticProperty ;
22
+ use Symfony \Component \Validator \Tests \Fixtures \ConstraintWithTypedProperty ;
20
23
use Symfony \Component \Validator \Tests \Fixtures \ConstraintWithValue ;
21
24
use Symfony \Component \Validator \Tests \Fixtures \ConstraintWithValueAsDefault ;
22
25
@@ -245,4 +248,25 @@ public function testAnnotationSetUndefinedDefaultOption()
245
248
$ this ->expectExceptionMessage ('No default option is configured for constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintB". ' );
246
249
new ConstraintB (['value ' => 1 ]);
247
250
}
251
+
252
+ public function testStaticPropertiesAreNoOptions ()
253
+ {
254
+ $ this ->expectException (InvalidOptionsException::class);
255
+
256
+ new ConstraintWithStaticProperty ([
257
+ 'foo ' => 'bar ' ,
258
+ ]);
259
+ }
260
+
261
+ /**
262
+ * @requires PHP 7.4
263
+ */
264
+ public function testSetTypedProperty ()
265
+ {
266
+ $ constraint = new ConstraintWithTypedProperty ([
267
+ 'foo ' => 'bar ' ,
268
+ ]);
269
+
270
+ $ this ->assertSame ('bar ' , $ constraint ->foo );
271
+ }
248
272
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Component \Validator \Tests \Fixtures ;
4
+
5
+ use Symfony \Component \Validator \Constraint ;
6
+
7
+ class ConstraintWithStaticProperty extends Constraint
8
+ {
9
+ public static $ foo ;
10
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Component \Validator \Tests \Fixtures ;
4
+
5
+ use Symfony \Component \Validator \Constraint ;
6
+
7
+ class ConstraintWithTypedProperty extends Constraint
8
+ {
9
+ public string $ foo ;
10
+ }
You can’t perform that action at this time.
0 commit comments