Skip to content

Commit

Permalink
Merge branch '5.0' into 5.1
Browse files Browse the repository at this point in the history
* 5.0:
  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
  Fix the 'supports' method argument type of the security voter
  Use the driverConnection executeUpdate method
  • Loading branch information
nicolas-grekas committed Jun 28, 2020
2 parents dba9d9d + 802a8d4 commit 3ce9311
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected function normalizeOptions($options): array
$defaultOption = $this->getDefaultOption();
$invalidOptions = [];
$missingOptions = array_flip((array) $this->getRequiredOptions());
$knownOptions = get_object_vars($this);
$knownOptions = get_class_vars(static::class);

// The "groups" option is added to the object lazily
$knownOptions['groups'] = true;
Expand Down
24 changes: 24 additions & 0 deletions Tests/ConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\InvalidOptionsException;
use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint;
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
use Symfony\Component\Validator\Tests\Fixtures\ConstraintC;
use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithStaticProperty;
use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithTypedProperty;
use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithValue;
use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithValueAsDefault;

Expand Down Expand Up @@ -245,4 +248,25 @@ public function testAnnotationSetUndefinedDefaultOption()
$this->expectExceptionMessage('No default option is configured for constraint "Symfony\Component\Validator\Tests\Fixtures\ConstraintB".');
new ConstraintB(['value' => 1]);
}

public function testStaticPropertiesAreNoOptions()
{
$this->expectException(InvalidOptionsException::class);

new ConstraintWithStaticProperty([
'foo' => 'bar',
]);
}

/**
* @requires PHP 7.4
*/
public function testSetTypedProperty()
{
$constraint = new ConstraintWithTypedProperty([
'foo' => 'bar',
]);

$this->assertSame('bar', $constraint->foo);
}
}
10 changes: 10 additions & 0 deletions Tests/Fixtures/ConstraintWithStaticProperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Symfony\Component\Validator\Tests\Fixtures;

use Symfony\Component\Validator\Constraint;

class ConstraintWithStaticProperty extends Constraint
{
public static $foo;
}
10 changes: 10 additions & 0 deletions Tests/Fixtures/ConstraintWithTypedProperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Symfony\Component\Validator\Tests\Fixtures;

use Symfony\Component\Validator\Constraint;

class ConstraintWithTypedProperty extends Constraint
{
public string $foo;
}

0 comments on commit 3ce9311

Please sign in to comment.