Skip to content

Commit f165d70

Browse files
Merge branch '5.1'
* 5.1: Fix test that fails on old distros Fix: compatibility with phpunit 9.3 [DoctrineBridge] work around Connection::ping() deprecation [MimeType] Duplicated MimeType due to PHP Bug [HttpClient] fix casting TraceableResponse to php streams [DI] fix parsing of argument type=binary in xml fix guessing form types for DateTime types fix handling typed properties as constraint options Fix the 'supports' method argument type of the security voter Use the driverConnection executeUpdate method
2 parents 6e06f53 + 3ce9311 commit f165d70

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

Constraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function normalizeOptions($options): array
116116
$defaultOption = $this->getDefaultOption();
117117
$invalidOptions = [];
118118
$missingOptions = array_flip((array) $this->getRequiredOptions());
119-
$knownOptions = get_object_vars($this);
119+
$knownOptions = get_class_vars(static::class);
120120

121121
// The "groups" option is added to the object lazily
122122
$knownOptions['groups'] = true;

Tests/ConstraintTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Validator\Constraint;
16+
use Symfony\Component\Validator\Exception\InvalidOptionsException;
1617
use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint;
1718
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
1819
use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
1920
use Symfony\Component\Validator\Tests\Fixtures\ConstraintC;
21+
use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithStaticProperty;
22+
use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithTypedProperty;
2023
use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithValue;
2124
use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithValueAsDefault;
2225

@@ -245,4 +248,25 @@ public function testAnnotationSetUndefinedDefaultOption()
245248
$this->expectExceptionMessage('No default option is configured for constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintB".');
246249
new ConstraintB(['value' => 1]);
247250
}
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+
}
248272
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

0 commit comments

Comments
 (0)