merged branch fabpot/validator-xml-loader (PR #8831)
This PR was merged into the 2.2 branch.
Discussion
----------
[Validator] fixed Boolean handling in XML constraint mappings
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #5603
| License | MIT
| Doc PR | n/a
ping @bschussek
Commits
-------
33b0a17
[Validator] fixed Boolean handling in XML constraint mappings (closes #5603)
This commit is contained in:
commit
c3301dde87
@ -166,7 +166,10 @@ class XmlFileLoader extends FileLoader
|
|||||||
$value = array();
|
$value = array();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$value = trim($node);
|
$value = XmlUtils::phpize($node);
|
||||||
|
if (is_string($value)) {
|
||||||
|
$value = trim($value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$options[(string) $node['name']] = $value;
|
$options[(string) $node['name']] = $value;
|
||||||
|
@ -16,6 +16,7 @@ use Symfony\Component\Validator\Constraints\Collection;
|
|||||||
use Symfony\Component\Validator\Constraints\NotNull;
|
use Symfony\Component\Validator\Constraints\NotNull;
|
||||||
use Symfony\Component\Validator\Constraints\Range;
|
use Symfony\Component\Validator\Constraints\Range;
|
||||||
use Symfony\Component\Validator\Constraints\Choice;
|
use Symfony\Component\Validator\Constraints\Choice;
|
||||||
|
use Symfony\Component\Validator\Constraints\Regex;
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||||
use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader;
|
use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader;
|
||||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||||
@ -68,6 +69,22 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expected, $metadata);
|
$this->assertEquals($expected, $metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLoadClassMetadataWithNonStrings()
|
||||||
|
{
|
||||||
|
$loader = new XmlFileLoader(__DIR__.'/constraint-mapping-non-strings.xml');
|
||||||
|
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||||
|
|
||||||
|
$loader->loadClassMetadata($metadata);
|
||||||
|
|
||||||
|
$expected = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||||
|
$expected->addPropertyConstraint('firstName', new Regex(array('pattern' => '/^1/', 'match' => false)));
|
||||||
|
|
||||||
|
$properties = $metadata->getPropertyMetadata('firstName');
|
||||||
|
$constraints = $properties[0]->getConstraints();
|
||||||
|
|
||||||
|
$this->assertFalse($constraints[0]->match);
|
||||||
|
}
|
||||||
|
|
||||||
public function testLoadGroupSequenceProvider()
|
public function testLoadGroupSequenceProvider()
|
||||||
{
|
{
|
||||||
$loader = new XmlFileLoader(__DIR__.'/constraint-mapping.xml');
|
$loader = new XmlFileLoader(__DIR__.'/constraint-mapping.xml');
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
|
||||||
|
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
|
||||||
|
|
||||||
|
<namespace prefix="custom">Symfony\Component\Validator\Tests\Fixtures\</namespace>
|
||||||
|
|
||||||
|
<class name="Symfony\Component\Validator\Tests\Fixtures\Entity">
|
||||||
|
<property name="firstName">
|
||||||
|
<!-- Constraint with a Boolean -->
|
||||||
|
<constraint name="Regex">
|
||||||
|
<option name="pattern">/^1/</option>
|
||||||
|
<option name="match">false</option>
|
||||||
|
</constraint>
|
||||||
|
</property>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
</constraint-mapping>
|
Reference in New Issue
Block a user