Skip to content

Commit 802a8d4

Browse files
Merge branch '4.4' into 5.0
* 4.4: 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 [DI] fix parsing of argument type=binary in xml fix guessing form types for DateTime types fix handling typed properties as constraint options Use the driverConnection executeUpdate method
2 parents a70795e + d7d79aa commit 802a8d4

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
@@ -108,7 +108,7 @@ public function __construct($options = null)
108108
$defaultOption = $this->getDefaultOption();
109109
$invalidOptions = [];
110110
$missingOptions = array_flip((array) $this->getRequiredOptions());
111-
$knownOptions = get_object_vars($this);
111+
$knownOptions = get_class_vars(static::class);
112112

113113
// The "groups" option is added to the object lazily
114114
$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)