Update to drupal-org-drupal 8.0.0-rc2. For more information, see https://www.drupal.org/node/2598668
This commit is contained in:
parent
f32e58e4b1
commit
8e18df8c36
3062 changed files with 15044 additions and 172506 deletions
|
@ -1,84 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping\Cache;
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Symfony\Component\Validator\Mapping\Cache\DoctrineCache;
|
||||
|
||||
class DoctrineCacheTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $cache;
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getClassName'))
|
||||
->getMock();
|
||||
|
||||
$meta->expects($this->once())
|
||||
->method('getClassName')
|
||||
->will($this->returnValue('bar'));
|
||||
|
||||
$this->cache->write($meta);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Symfony\\Component\\Validator\\Mapping\\ClassMetadata',
|
||||
$this->cache->read('bar'),
|
||||
'write() stores metadata'
|
||||
);
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getClassName'))
|
||||
->getMock();
|
||||
|
||||
$meta->expects($this->once())
|
||||
->method('getClassName')
|
||||
->will($this->returnValue('bar'));
|
||||
|
||||
$this->assertFalse($this->cache->has('bar'), 'has() returns false when there is no entry');
|
||||
|
||||
$this->cache->write($meta);
|
||||
$this->assertTrue($this->cache->has('bar'), 'has() returns true when the is an entry');
|
||||
}
|
||||
|
||||
public function testRead()
|
||||
{
|
||||
$meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getClassName'))
|
||||
->getMock();
|
||||
|
||||
$meta->expects($this->once())
|
||||
->method('getClassName')
|
||||
->will($this->returnValue('bar'));
|
||||
|
||||
$this->assertFalse($this->cache->read('bar'), 'read() returns false when there is no entry');
|
||||
|
||||
$this->cache->write($meta);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Symfony\\Component\\Validator\\Mapping\\ClassMetadata',
|
||||
$this->cache->read('bar'),
|
||||
'read() returns metadata'
|
||||
);
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->cache = new DoctrineCache(new ArrayCache());
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping\Cache;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\Cache\ApcCache;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class LegacyApcCacheTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!extension_loaded('apc') || !ini_get('apc.enable_cli')) {
|
||||
$this->markTestSkipped('APC is not loaded.');
|
||||
}
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getClassName'))
|
||||
->getMock();
|
||||
|
||||
$meta->expects($this->once())
|
||||
->method('getClassName')
|
||||
->will($this->returnValue('bar'));
|
||||
|
||||
$cache = new ApcCache('foo');
|
||||
$cache->write($meta);
|
||||
|
||||
$this->assertInstanceOf('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', apc_fetch('foobar'), '->write() stores metadata in APC');
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getClassName'))
|
||||
->getMock();
|
||||
|
||||
$meta->expects($this->once())
|
||||
->method('getClassName')
|
||||
->will($this->returnValue('bar'));
|
||||
|
||||
apc_delete('foobar');
|
||||
|
||||
$cache = new ApcCache('foo');
|
||||
$this->assertFalse($cache->has('bar'), '->has() returns false when there is no entry');
|
||||
|
||||
$cache->write($meta);
|
||||
$this->assertTrue($cache->has('bar'), '->has() returns true when the is an entry');
|
||||
}
|
||||
|
||||
public function testRead()
|
||||
{
|
||||
$meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('getClassName'))
|
||||
->getMock();
|
||||
|
||||
$meta->expects($this->once())
|
||||
->method('getClassName')
|
||||
->will($this->returnValue('bar'));
|
||||
|
||||
$cache = new ApcCache('foo');
|
||||
$cache->write($meta);
|
||||
|
||||
$this->assertInstanceOf('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', $cache->read('bar'), '->read() returns metadata');
|
||||
}
|
||||
}
|
|
@ -1,280 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Constraints\Valid;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\PropertyConstraint;
|
||||
|
||||
class ClassMetadataTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
|
||||
const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
|
||||
const PROVIDERCLASS = 'Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity';
|
||||
|
||||
protected $metadata;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->metadata = new ClassMetadata(self::CLASSNAME);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->metadata = null;
|
||||
}
|
||||
|
||||
public function testAddConstraintDoesNotAcceptValid()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
||||
|
||||
$this->metadata->addConstraint(new Valid());
|
||||
}
|
||||
|
||||
public function testAddConstraintRequiresClassConstraints()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
||||
|
||||
$this->metadata->addConstraint(new PropertyConstraint());
|
||||
}
|
||||
|
||||
public function testAddPropertyConstraints()
|
||||
{
|
||||
$this->metadata->addPropertyConstraint('firstName', new ConstraintA());
|
||||
$this->metadata->addPropertyConstraint('lastName', new ConstraintB());
|
||||
|
||||
$this->assertEquals(array('firstName', 'lastName'), $this->metadata->getConstrainedProperties());
|
||||
}
|
||||
|
||||
public function testAddMultiplePropertyConstraints()
|
||||
{
|
||||
$this->metadata->addPropertyConstraints('lastName', array(new ConstraintA(), new ConstraintB()));
|
||||
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array('Default', 'Entity'))),
|
||||
new ConstraintB(array('groups' => array('Default', 'Entity'))),
|
||||
);
|
||||
|
||||
$properties = $this->metadata->getPropertyMetadata('lastName');
|
||||
|
||||
$this->assertCount(1, $properties);
|
||||
$this->assertEquals('lastName', $properties[0]->getName());
|
||||
$this->assertEquals($constraints, $properties[0]->getConstraints());
|
||||
}
|
||||
|
||||
public function testAddGetterConstraints()
|
||||
{
|
||||
$this->metadata->addGetterConstraint('lastName', new ConstraintA());
|
||||
$this->metadata->addGetterConstraint('lastName', new ConstraintB());
|
||||
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array('Default', 'Entity'))),
|
||||
new ConstraintB(array('groups' => array('Default', 'Entity'))),
|
||||
);
|
||||
|
||||
$properties = $this->metadata->getPropertyMetadata('lastName');
|
||||
|
||||
$this->assertCount(1, $properties);
|
||||
$this->assertEquals('getLastName', $properties[0]->getName());
|
||||
$this->assertEquals($constraints, $properties[0]->getConstraints());
|
||||
}
|
||||
|
||||
public function testAddMultipleGetterConstraints()
|
||||
{
|
||||
$this->metadata->addGetterConstraints('lastName', array(new ConstraintA(), new ConstraintB()));
|
||||
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array('Default', 'Entity'))),
|
||||
new ConstraintB(array('groups' => array('Default', 'Entity'))),
|
||||
);
|
||||
|
||||
$properties = $this->metadata->getPropertyMetadata('lastName');
|
||||
|
||||
$this->assertCount(1, $properties);
|
||||
$this->assertEquals('getLastName', $properties[0]->getName());
|
||||
$this->assertEquals($constraints, $properties[0]->getConstraints());
|
||||
}
|
||||
|
||||
public function testMergeConstraintsMergesClassConstraints()
|
||||
{
|
||||
$parent = new ClassMetadata(self::PARENTCLASS);
|
||||
$parent->addConstraint(new ConstraintA());
|
||||
|
||||
$this->metadata->mergeConstraints($parent);
|
||||
$this->metadata->addConstraint(new ConstraintA());
|
||||
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array(
|
||||
'Default',
|
||||
'EntityParent',
|
||||
'Entity',
|
||||
))),
|
||||
new ConstraintA(array('groups' => array(
|
||||
'Default',
|
||||
'Entity',
|
||||
))),
|
||||
);
|
||||
|
||||
$this->assertEquals($constraints, $this->metadata->getConstraints());
|
||||
}
|
||||
|
||||
public function testMergeConstraintsMergesMemberConstraints()
|
||||
{
|
||||
$parent = new ClassMetadata(self::PARENTCLASS);
|
||||
$parent->addPropertyConstraint('firstName', new ConstraintA());
|
||||
|
||||
$this->metadata->mergeConstraints($parent);
|
||||
$this->metadata->addPropertyConstraint('firstName', new ConstraintA());
|
||||
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array(
|
||||
'Default',
|
||||
'EntityParent',
|
||||
'Entity',
|
||||
))),
|
||||
new ConstraintA(array('groups' => array(
|
||||
'Default',
|
||||
'Entity',
|
||||
))),
|
||||
);
|
||||
|
||||
$members = $this->metadata->getPropertyMetadata('firstName');
|
||||
|
||||
$this->assertCount(1, $members);
|
||||
$this->assertEquals(self::PARENTCLASS, $members[0]->getClassName());
|
||||
$this->assertEquals($constraints, $members[0]->getConstraints());
|
||||
}
|
||||
|
||||
public function testMemberMetadatas()
|
||||
{
|
||||
$this->metadata->addPropertyConstraint('firstName', new ConstraintA());
|
||||
|
||||
$this->assertTrue($this->metadata->hasPropertyMetadata('firstName'));
|
||||
$this->assertFalse($this->metadata->hasPropertyMetadata('non_existent_field'));
|
||||
}
|
||||
|
||||
public function testMergeConstraintsKeepsPrivateMembersSeparate()
|
||||
{
|
||||
$parent = new ClassMetadata(self::PARENTCLASS);
|
||||
$parent->addPropertyConstraint('internal', new ConstraintA());
|
||||
|
||||
$this->metadata->mergeConstraints($parent);
|
||||
$this->metadata->addPropertyConstraint('internal', new ConstraintA());
|
||||
|
||||
$parentConstraints = array(
|
||||
new ConstraintA(array('groups' => array(
|
||||
'Default',
|
||||
'EntityParent',
|
||||
'Entity',
|
||||
))),
|
||||
);
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array(
|
||||
'Default',
|
||||
'Entity',
|
||||
))),
|
||||
);
|
||||
|
||||
$members = $this->metadata->getPropertyMetadata('internal');
|
||||
|
||||
$this->assertCount(2, $members);
|
||||
$this->assertEquals(self::PARENTCLASS, $members[0]->getClassName());
|
||||
$this->assertEquals($parentConstraints, $members[0]->getConstraints());
|
||||
$this->assertEquals(self::CLASSNAME, $members[1]->getClassName());
|
||||
$this->assertEquals($constraints, $members[1]->getConstraints());
|
||||
}
|
||||
|
||||
public function testGetReflectionClass()
|
||||
{
|
||||
$reflClass = new \ReflectionClass(self::CLASSNAME);
|
||||
|
||||
$this->assertEquals($reflClass, $this->metadata->getReflectionClass());
|
||||
}
|
||||
|
||||
public function testSerialize()
|
||||
{
|
||||
$this->metadata->addConstraint(new ConstraintA(array('property1' => 'A')));
|
||||
$this->metadata->addConstraint(new ConstraintB(array('groups' => 'TestGroup')));
|
||||
$this->metadata->addPropertyConstraint('firstName', new ConstraintA());
|
||||
$this->metadata->addGetterConstraint('lastName', new ConstraintB());
|
||||
|
||||
$metadata = unserialize(serialize($this->metadata));
|
||||
|
||||
$this->assertEquals($this->metadata, $metadata);
|
||||
}
|
||||
|
||||
public function testGroupSequencesWorkIfContainingDefaultGroup()
|
||||
{
|
||||
$this->metadata->setGroupSequence(array('Foo', $this->metadata->getDefaultGroup()));
|
||||
}
|
||||
|
||||
public function testGroupSequencesFailIfNotContainingDefaultGroup()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\Validator\Exception\GroupDefinitionException');
|
||||
|
||||
$this->metadata->setGroupSequence(array('Foo', 'Bar'));
|
||||
}
|
||||
|
||||
public function testGroupSequencesFailIfContainingDefault()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\Validator\Exception\GroupDefinitionException');
|
||||
|
||||
$this->metadata->setGroupSequence(array('Foo', $this->metadata->getDefaultGroup(), Constraint::DEFAULT_GROUP));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Validator\Exception\GroupDefinitionException
|
||||
*/
|
||||
public function testGroupSequenceFailsIfGroupSequenceProviderIsSet()
|
||||
{
|
||||
$metadata = new ClassMetadata(self::PROVIDERCLASS);
|
||||
$metadata->setGroupSequenceProvider(true);
|
||||
$metadata->setGroupSequence(array('GroupSequenceProviderEntity', 'Foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Validator\Exception\GroupDefinitionException
|
||||
*/
|
||||
public function testGroupSequenceProviderFailsIfGroupSequenceIsSet()
|
||||
{
|
||||
$metadata = new ClassMetadata(self::PROVIDERCLASS);
|
||||
$metadata->setGroupSequence(array('GroupSequenceProviderEntity', 'Foo'));
|
||||
$metadata->setGroupSequenceProvider(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Validator\Exception\GroupDefinitionException
|
||||
*/
|
||||
public function testGroupSequenceProviderFailsIfDomainClassIsInvalid()
|
||||
{
|
||||
$metadata = new ClassMetadata('stdClass');
|
||||
$metadata->setGroupSequenceProvider(true);
|
||||
}
|
||||
|
||||
public function testGroupSequenceProvider()
|
||||
{
|
||||
$metadata = new ClassMetadata(self::PROVIDERCLASS);
|
||||
$metadata->setGroupSequenceProvider(true);
|
||||
$this->assertTrue($metadata->isGroupSequenceProvider());
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/symfony/symfony/issues/11604.
|
||||
*/
|
||||
public function testGetPropertyMetadataReturnsEmptyArrayWithoutConfiguredMetadata()
|
||||
{
|
||||
$this->assertCount(0, $this->metadata->getPropertyMetadata('foo'), '->getPropertyMetadata() returns an empty collection if no metadata is configured for the given property');
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping\Factory;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\Factory\BlackHoleMetadataFactory;
|
||||
|
||||
class BlackHoleMetadataFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testGetMetadataForThrowsALogicException()
|
||||
{
|
||||
$metadataFactory = new BlackHoleMetadataFactory();
|
||||
$metadataFactory->getMetadataFor('foo');
|
||||
}
|
||||
|
||||
public function testHasMetadataForReturnsFalse()
|
||||
{
|
||||
$metadataFactory = new BlackHoleMetadataFactory();
|
||||
|
||||
$this->assertFalse($metadataFactory->hasMetadataFor('foo'));
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping\Factory;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
|
||||
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||
|
||||
class LazyLoadingMetadataFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
|
||||
const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
|
||||
|
||||
public function testLoadClassMetadata()
|
||||
{
|
||||
$factory = new LazyLoadingMetadataFactory(new TestLoader());
|
||||
$metadata = $factory->getMetadataFor(self::PARENTCLASS);
|
||||
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array('Default', 'EntityParent'))),
|
||||
);
|
||||
|
||||
$this->assertEquals($constraints, $metadata->getConstraints());
|
||||
}
|
||||
|
||||
public function testMergeParentConstraints()
|
||||
{
|
||||
$factory = new LazyLoadingMetadataFactory(new TestLoader());
|
||||
$metadata = $factory->getMetadataFor(self::CLASSNAME);
|
||||
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array(
|
||||
'Default',
|
||||
'EntityParent',
|
||||
'Entity',
|
||||
))),
|
||||
new ConstraintA(array('groups' => array(
|
||||
'Default',
|
||||
'EntityInterface',
|
||||
'Entity',
|
||||
))),
|
||||
new ConstraintA(array('groups' => array(
|
||||
'Default',
|
||||
'Entity',
|
||||
))),
|
||||
);
|
||||
|
||||
$this->assertEquals($constraints, $metadata->getConstraints());
|
||||
}
|
||||
|
||||
public function testWriteMetadataToCache()
|
||||
{
|
||||
$cache = $this->getMock('Symfony\Component\Validator\Mapping\Cache\CacheInterface');
|
||||
$factory = new LazyLoadingMetadataFactory(new TestLoader(), $cache);
|
||||
|
||||
$tester = $this;
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array('Default', 'EntityParent'))),
|
||||
);
|
||||
|
||||
$cache->expects($this->never())
|
||||
->method('has');
|
||||
$cache->expects($this->once())
|
||||
->method('read')
|
||||
->with($this->equalTo(self::PARENTCLASS))
|
||||
->will($this->returnValue(false));
|
||||
$cache->expects($this->once())
|
||||
->method('write')
|
||||
->will($this->returnCallback(function ($metadata) use ($tester, $constraints) {
|
||||
$tester->assertEquals($constraints, $metadata->getConstraints());
|
||||
}));
|
||||
|
||||
$metadata = $factory->getMetadataFor(self::PARENTCLASS);
|
||||
|
||||
$this->assertEquals(self::PARENTCLASS, $metadata->getClassName());
|
||||
$this->assertEquals($constraints, $metadata->getConstraints());
|
||||
}
|
||||
|
||||
public function testReadMetadataFromCache()
|
||||
{
|
||||
$loader = $this->getMock('Symfony\Component\Validator\Mapping\Loader\LoaderInterface');
|
||||
$cache = $this->getMock('Symfony\Component\Validator\Mapping\Cache\CacheInterface');
|
||||
$factory = new LazyLoadingMetadataFactory($loader, $cache);
|
||||
|
||||
$tester = $this;
|
||||
$metadata = new ClassMetadata(self::PARENTCLASS);
|
||||
$metadata->addConstraint(new ConstraintA());
|
||||
|
||||
$loader->expects($this->never())
|
||||
->method('loadClassMetadata');
|
||||
|
||||
$cache->expects($this->never())
|
||||
->method('has');
|
||||
$cache->expects($this->once())
|
||||
->method('read')
|
||||
->will($this->returnValue($metadata));
|
||||
|
||||
$this->assertEquals($metadata, $factory->getMetadataFor(self::PARENTCLASS));
|
||||
}
|
||||
}
|
||||
|
||||
class TestLoader implements LoaderInterface
|
||||
{
|
||||
public function loadClassMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$metadata->addConstraint(new ConstraintA());
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\GetterMetadata;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\Entity;
|
||||
|
||||
class GetterMetadataTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
|
||||
|
||||
public function testInvalidPropertyName()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException');
|
||||
|
||||
new GetterMetadata(self::CLASSNAME, 'foobar');
|
||||
}
|
||||
|
||||
public function testGetPropertyValueFromPublicGetter()
|
||||
{
|
||||
// private getters don't work yet because ReflectionMethod::setAccessible()
|
||||
// does not exist yet in a stable PHP release
|
||||
|
||||
$entity = new Entity('foobar');
|
||||
$metadata = new GetterMetadata(self::CLASSNAME, 'internal');
|
||||
|
||||
$this->assertEquals('foobar from getter', $metadata->getPropertyValue($entity));
|
||||
}
|
||||
|
||||
public function testGetPropertyValueFromOverriddenPublicGetter()
|
||||
{
|
||||
$entity = new Entity();
|
||||
$metadata = new GetterMetadata(self::CLASSNAME, 'data');
|
||||
|
||||
$this->assertEquals('Overridden data', $metadata->getPropertyValue($entity));
|
||||
}
|
||||
|
||||
public function testGetPropertyValueFromIsser()
|
||||
{
|
||||
$entity = new Entity();
|
||||
$metadata = new GetterMetadata(self::CLASSNAME, 'valid');
|
||||
|
||||
$this->assertEquals('valid', $metadata->getPropertyValue($entity));
|
||||
}
|
||||
|
||||
public function testGetPropertyValueFromHasser()
|
||||
{
|
||||
$entity = new Entity();
|
||||
$metadata = new GetterMetadata(self::CLASSNAME, 'permissions');
|
||||
|
||||
$this->assertEquals('permissions', $metadata->getPropertyValue($entity));
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\ElementMetadata;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class LegacyElementMetadataTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $metadata;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->metadata = new TestElementMetadata();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->metadata = null;
|
||||
}
|
||||
|
||||
public function testAddConstraints()
|
||||
{
|
||||
$this->metadata->addConstraint($constraint1 = new ConstraintA());
|
||||
$this->metadata->addConstraint($constraint2 = new ConstraintA());
|
||||
|
||||
$this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
|
||||
}
|
||||
|
||||
public function testMultipleConstraintsOfTheSameType()
|
||||
{
|
||||
$constraint1 = new ConstraintA(array('property1' => 'A'));
|
||||
$constraint2 = new ConstraintA(array('property1' => 'B'));
|
||||
|
||||
$this->metadata->addConstraint($constraint1);
|
||||
$this->metadata->addConstraint($constraint2);
|
||||
|
||||
$this->assertEquals(array($constraint1, $constraint2), $this->metadata->getConstraints());
|
||||
}
|
||||
|
||||
public function testFindConstraintsByGroup()
|
||||
{
|
||||
$constraint1 = new ConstraintA(array('groups' => 'TestGroup'));
|
||||
$constraint2 = new ConstraintB();
|
||||
|
||||
$this->metadata->addConstraint($constraint1);
|
||||
$this->metadata->addConstraint($constraint2);
|
||||
|
||||
$this->assertEquals(array($constraint1), $this->metadata->findConstraints('TestGroup'));
|
||||
}
|
||||
|
||||
public function testSerialize()
|
||||
{
|
||||
$this->metadata->addConstraint(new ConstraintA(array('property1' => 'A')));
|
||||
$this->metadata->addConstraint(new ConstraintB(array('groups' => 'TestGroup')));
|
||||
|
||||
$metadata = unserialize(serialize($this->metadata));
|
||||
|
||||
$this->assertEquals($this->metadata, $metadata);
|
||||
}
|
||||
}
|
||||
|
||||
class TestElementMetadata extends ElementMetadata
|
||||
{
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
|
||||
abstract class AbstractStaticMethodLoader
|
||||
{
|
||||
abstract public static function loadMetadata(ClassMetadata $metadata);
|
||||
}
|
|
@ -1,162 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping\Loader;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Symfony\Component\Validator\Constraints\All;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
use Symfony\Component\Validator\Constraints\Collection;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
use Symfony\Component\Validator\Constraints\Range;
|
||||
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||
|
||||
class AnnotationLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testLoadClassMetadataReturnsTrueIfSuccessful()
|
||||
{
|
||||
$reader = new AnnotationReader();
|
||||
$loader = new AnnotationLoader($reader);
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
|
||||
$this->assertTrue($loader->loadClassMetadata($metadata));
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataReturnsFalseIfNotSuccessful()
|
||||
{
|
||||
$loader = new AnnotationLoader(new AnnotationReader());
|
||||
$metadata = new ClassMetadata('\stdClass');
|
||||
|
||||
$this->assertFalse($loader->loadClassMetadata($metadata));
|
||||
}
|
||||
|
||||
public function testLoadClassMetadata()
|
||||
{
|
||||
$loader = new AnnotationLoader(new AnnotationReader());
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$expected = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
$expected->setGroupSequence(array('Foo', 'Entity'));
|
||||
$expected->addConstraint(new ConstraintA());
|
||||
$expected->addConstraint(new Callback(array('Symfony\Component\Validator\Tests\Fixtures\CallbackClass', 'callback')));
|
||||
$expected->addConstraint(new Callback('validateMe'));
|
||||
$expected->addConstraint(new Callback('validateMeStatic'));
|
||||
$expected->addPropertyConstraint('firstName', new NotNull());
|
||||
$expected->addPropertyConstraint('firstName', new Range(array('min' => 3)));
|
||||
$expected->addPropertyConstraint('firstName', new All(array(new NotNull(), new Range(array('min' => 3)))));
|
||||
$expected->addPropertyConstraint('firstName', new All(array('constraints' => array(new NotNull(), new Range(array('min' => 3))))));
|
||||
$expected->addPropertyConstraint('firstName', new Collection(array('fields' => array(
|
||||
'foo' => array(new NotNull(), new Range(array('min' => 3))),
|
||||
'bar' => new Range(array('min' => 5)),
|
||||
))));
|
||||
$expected->addPropertyConstraint('firstName', new Choice(array(
|
||||
'message' => 'Must be one of %choices%',
|
||||
'choices' => array('A', 'B'),
|
||||
)));
|
||||
$expected->addGetterConstraint('lastName', new NotNull());
|
||||
$expected->addGetterConstraint('valid', new IsTrue());
|
||||
$expected->addGetterConstraint('permissions', new IsTrue());
|
||||
|
||||
// load reflection class so that the comparison passes
|
||||
$expected->getReflectionClass();
|
||||
|
||||
$this->assertEquals($expected, $metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test MetaData merge with parent annotation.
|
||||
*/
|
||||
public function testLoadParentClassMetadata()
|
||||
{
|
||||
$loader = new AnnotationLoader(new AnnotationReader());
|
||||
|
||||
// Load Parent MetaData
|
||||
$parent_metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\EntityParent');
|
||||
$loader->loadClassMetadata($parent_metadata);
|
||||
|
||||
$expected_parent = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\EntityParent');
|
||||
$expected_parent->addPropertyConstraint('other', new NotNull());
|
||||
$expected_parent->getReflectionClass();
|
||||
|
||||
$this->assertEquals($expected_parent, $parent_metadata);
|
||||
}
|
||||
/**
|
||||
* Test MetaData merge with parent annotation.
|
||||
*/
|
||||
public function testLoadClassMetadataAndMerge()
|
||||
{
|
||||
$loader = new AnnotationLoader(new AnnotationReader());
|
||||
|
||||
// Load Parent MetaData
|
||||
$parent_metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\EntityParent');
|
||||
$loader->loadClassMetadata($parent_metadata);
|
||||
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
|
||||
// Merge parent metaData.
|
||||
$metadata->mergeConstraints($parent_metadata);
|
||||
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$expected_parent = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\EntityParent');
|
||||
$expected_parent->addPropertyConstraint('other', new NotNull());
|
||||
$expected_parent->getReflectionClass();
|
||||
|
||||
$expected = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
$expected->mergeConstraints($expected_parent);
|
||||
|
||||
$expected->setGroupSequence(array('Foo', 'Entity'));
|
||||
$expected->addConstraint(new ConstraintA());
|
||||
$expected->addConstraint(new Callback(array('Symfony\Component\Validator\Tests\Fixtures\CallbackClass', 'callback')));
|
||||
$expected->addConstraint(new Callback('validateMe'));
|
||||
$expected->addConstraint(new Callback('validateMeStatic'));
|
||||
$expected->addPropertyConstraint('firstName', new NotNull());
|
||||
$expected->addPropertyConstraint('firstName', new Range(array('min' => 3)));
|
||||
$expected->addPropertyConstraint('firstName', new All(array(new NotNull(), new Range(array('min' => 3)))));
|
||||
$expected->addPropertyConstraint('firstName', new All(array('constraints' => array(new NotNull(), new Range(array('min' => 3))))));
|
||||
$expected->addPropertyConstraint('firstName', new Collection(array('fields' => array(
|
||||
'foo' => array(new NotNull(), new Range(array('min' => 3))),
|
||||
'bar' => new Range(array('min' => 5)),
|
||||
))));
|
||||
$expected->addPropertyConstraint('firstName', new Choice(array(
|
||||
'message' => 'Must be one of %choices%',
|
||||
'choices' => array('A', 'B'),
|
||||
)));
|
||||
$expected->addGetterConstraint('lastName', new NotNull());
|
||||
$expected->addGetterConstraint('valid', new IsTrue());
|
||||
$expected->addGetterConstraint('permissions', new IsTrue());
|
||||
|
||||
// load reflection class so that the comparison passes
|
||||
$expected->getReflectionClass();
|
||||
|
||||
$this->assertEquals($expected, $metadata);
|
||||
}
|
||||
|
||||
public function testLoadGroupSequenceProviderAnnotation()
|
||||
{
|
||||
$loader = new AnnotationLoader(new AnnotationReader());
|
||||
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$expected = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity');
|
||||
$expected->setGroupSequenceProvider(true);
|
||||
$expected->getReflectionClass();
|
||||
|
||||
$this->assertEquals($expected, $metadata);
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
|
||||
|
||||
class FilesLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCallsGetFileLoaderInstanceForeachPath()
|
||||
{
|
||||
$loader = $this->getFilesLoader($this->getFileLoader());
|
||||
$this->assertEquals(4, $loader->getTimesCalled());
|
||||
}
|
||||
|
||||
public function testCallsActualFileLoaderForMetadata()
|
||||
{
|
||||
$fileLoader = $this->getFileLoader();
|
||||
$fileLoader->expects($this->exactly(4))
|
||||
->method('loadClassMetadata');
|
||||
$loader = $this->getFilesLoader($fileLoader);
|
||||
$loader->loadClassMetadata(new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity'));
|
||||
}
|
||||
|
||||
public function getFilesLoader(LoaderInterface $loader)
|
||||
{
|
||||
return $this->getMockForAbstractClass('Symfony\Component\Validator\Tests\Fixtures\FilesLoader', array(array(
|
||||
__DIR__.'/constraint-mapping.xml',
|
||||
__DIR__.'/constraint-mapping.yaml',
|
||||
__DIR__.'/constraint-mapping.test',
|
||||
__DIR__.'/constraint-mapping.txt',
|
||||
), $loader));
|
||||
}
|
||||
|
||||
public function getFileLoader()
|
||||
{
|
||||
return $this->getMock('Symfony\Component\Validator\Mapping\Loader\LoaderInterface');
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Mapping\Loader\LoaderChain;
|
||||
|
||||
class LoaderChainTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAllLoadersAreCalled()
|
||||
{
|
||||
$metadata = new ClassMetadata('\stdClass');
|
||||
|
||||
$loader1 = $this->getMock('Symfony\Component\Validator\Mapping\Loader\LoaderInterface');
|
||||
$loader1->expects($this->once())
|
||||
->method('loadClassMetadata')
|
||||
->with($this->equalTo($metadata));
|
||||
|
||||
$loader2 = $this->getMock('Symfony\Component\Validator\Mapping\Loader\LoaderInterface');
|
||||
$loader2->expects($this->once())
|
||||
->method('loadClassMetadata')
|
||||
->with($this->equalTo($metadata));
|
||||
|
||||
$chain = new LoaderChain(array(
|
||||
$loader1,
|
||||
$loader2,
|
||||
));
|
||||
|
||||
$chain->loadClassMetadata($metadata);
|
||||
}
|
||||
|
||||
public function testReturnsTrueIfAnyLoaderReturnedTrue()
|
||||
{
|
||||
$metadata = new ClassMetadata('\stdClass');
|
||||
|
||||
$loader1 = $this->getMock('Symfony\Component\Validator\Mapping\Loader\LoaderInterface');
|
||||
$loader1->expects($this->any())
|
||||
->method('loadClassMetadata')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$loader2 = $this->getMock('Symfony\Component\Validator\Mapping\Loader\LoaderInterface');
|
||||
$loader2->expects($this->any())
|
||||
->method('loadClassMetadata')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$chain = new LoaderChain(array(
|
||||
$loader1,
|
||||
$loader2,
|
||||
));
|
||||
|
||||
$this->assertTrue($chain->loadClassMetadata($metadata));
|
||||
}
|
||||
|
||||
public function testReturnsFalseIfNoLoaderReturnedTrue()
|
||||
{
|
||||
$metadata = new ClassMetadata('\stdClass');
|
||||
|
||||
$loader1 = $this->getMock('Symfony\Component\Validator\Mapping\Loader\LoaderInterface');
|
||||
$loader1->expects($this->any())
|
||||
->method('loadClassMetadata')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$loader2 = $this->getMock('Symfony\Component\Validator\Mapping\Loader\LoaderInterface');
|
||||
$loader2->expects($this->any())
|
||||
->method('loadClassMetadata')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$chain = new LoaderChain(array(
|
||||
$loader1,
|
||||
$loader2,
|
||||
));
|
||||
|
||||
$this->assertFalse($chain->loadClassMetadata($metadata));
|
||||
}
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||
|
||||
class StaticMethodLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $errorLevel;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->errorLevel = error_reporting();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
error_reporting($this->errorLevel);
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataReturnsTrueIfSuccessful()
|
||||
{
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderEntity');
|
||||
|
||||
$this->assertTrue($loader->loadClassMetadata($metadata));
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataReturnsFalseIfNotSuccessful()
|
||||
{
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$metadata = new ClassMetadata('\stdClass');
|
||||
|
||||
$this->assertFalse($loader->loadClassMetadata($metadata));
|
||||
}
|
||||
|
||||
public function testLoadClassMetadata()
|
||||
{
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderEntity');
|
||||
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$this->assertEquals(StaticLoaderEntity::$invokedWith, $metadata);
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataDoesNotRepeatLoadWithParentClasses()
|
||||
{
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderDocument');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
$this->assertCount(0, $metadata->getConstraints());
|
||||
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\BaseStaticLoaderDocument');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
$this->assertCount(1, $metadata->getConstraints());
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataIgnoresInterfaces()
|
||||
{
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\StaticLoaderInterface');
|
||||
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$this->assertCount(0, $metadata->getConstraints());
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataInAbstractClasses()
|
||||
{
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticLoader');
|
||||
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$this->assertCount(1, $metadata->getConstraints());
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataIgnoresAbstractMethods()
|
||||
{
|
||||
// Disable error reporting, as AbstractStaticMethodLoader produces a
|
||||
// strict standards error
|
||||
error_reporting(0);
|
||||
|
||||
if (0 !== error_reporting()) {
|
||||
$this->markTestSkipped('Could not disable error reporting');
|
||||
}
|
||||
|
||||
$metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticMethodLoader');
|
||||
|
||||
$loader = new StaticMethodLoader('loadMetadata');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$this->assertCount(0, $metadata->getConstraints());
|
||||
}
|
||||
}
|
||||
|
||||
interface StaticLoaderInterface
|
||||
{
|
||||
public static function loadMetadata(ClassMetadata $metadata);
|
||||
}
|
||||
|
||||
abstract class AbstractStaticLoader
|
||||
{
|
||||
public static function loadMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$metadata->addConstraint(new ConstraintA());
|
||||
}
|
||||
}
|
||||
|
||||
class StaticLoaderEntity
|
||||
{
|
||||
public static $invokedWith = null;
|
||||
|
||||
public static function loadMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
self::$invokedWith = $metadata;
|
||||
}
|
||||
}
|
||||
|
||||
class StaticLoaderDocument extends BaseStaticLoaderDocument
|
||||
{
|
||||
}
|
||||
|
||||
class BaseStaticLoaderDocument
|
||||
{
|
||||
public static function loadMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$metadata->addConstraint(new ConstraintA());
|
||||
}
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\All;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
use Symfony\Component\Validator\Constraints\Collection;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
use Symfony\Component\Validator\Constraints\Range;
|
||||
use Symfony\Component\Validator\Constraints\Regex;
|
||||
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||
use Symfony\Component\Validator\Exception\MappingException;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
|
||||
|
||||
class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testLoadClassMetadataReturnsTrueIfSuccessful()
|
||||
{
|
||||
$loader = new XmlFileLoader(__DIR__.'/constraint-mapping.xml');
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
|
||||
$this->assertTrue($loader->loadClassMetadata($metadata));
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataReturnsFalseIfNotSuccessful()
|
||||
{
|
||||
$loader = new XmlFileLoader(__DIR__.'/constraint-mapping.xml');
|
||||
$metadata = new ClassMetadata('\stdClass');
|
||||
|
||||
$this->assertFalse($loader->loadClassMetadata($metadata));
|
||||
}
|
||||
|
||||
public function testLoadClassMetadata()
|
||||
{
|
||||
$loader = new XmlFileLoader(__DIR__.'/constraint-mapping.xml');
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$expected = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
$expected->setGroupSequence(array('Foo', 'Entity'));
|
||||
$expected->addConstraint(new ConstraintA());
|
||||
$expected->addConstraint(new ConstraintB());
|
||||
$expected->addConstraint(new Callback('validateMe'));
|
||||
$expected->addConstraint(new Callback('validateMeStatic'));
|
||||
$expected->addConstraint(new Callback(array('Symfony\Component\Validator\Tests\Fixtures\CallbackClass', 'callback')));
|
||||
$expected->addPropertyConstraint('firstName', new NotNull());
|
||||
$expected->addPropertyConstraint('firstName', new Range(array('min' => 3)));
|
||||
$expected->addPropertyConstraint('firstName', new Choice(array('A', 'B')));
|
||||
$expected->addPropertyConstraint('firstName', new All(array(new NotNull(), new Range(array('min' => 3)))));
|
||||
$expected->addPropertyConstraint('firstName', new All(array('constraints' => array(new NotNull(), new Range(array('min' => 3))))));
|
||||
$expected->addPropertyConstraint('firstName', new Collection(array('fields' => array(
|
||||
'foo' => array(new NotNull(), new Range(array('min' => 3))),
|
||||
'bar' => array(new Range(array('min' => 5))),
|
||||
))));
|
||||
$expected->addPropertyConstraint('firstName', new Choice(array(
|
||||
'message' => 'Must be one of %choices%',
|
||||
'choices' => array('A', 'B'),
|
||||
)));
|
||||
$expected->addGetterConstraint('lastName', new NotNull());
|
||||
$expected->addGetterConstraint('valid', new IsTrue());
|
||||
$expected->addGetterConstraint('permissions', new IsTrue());
|
||||
|
||||
$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()
|
||||
{
|
||||
$loader = new XmlFileLoader(__DIR__.'/constraint-mapping.xml');
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity');
|
||||
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$expected = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity');
|
||||
$expected->setGroupSequenceProvider(true);
|
||||
|
||||
$this->assertEquals($expected, $metadata);
|
||||
}
|
||||
|
||||
public function testThrowExceptionIfDocTypeIsSet()
|
||||
{
|
||||
$loader = new XmlFileLoader(__DIR__.'/withdoctype.xml');
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
|
||||
$this->setExpectedException('\Symfony\Component\Validator\Exception\MappingException');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/symfony/symfony/pull/12158
|
||||
*/
|
||||
public function testDoNotModifyStateIfExceptionIsThrown()
|
||||
{
|
||||
$loader = new XmlFileLoader(__DIR__.'/withdoctype.xml');
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
|
||||
try {
|
||||
$loader->loadClassMetadata($metadata);
|
||||
} catch (MappingException $e) {
|
||||
$this->setExpectedException('\Symfony\Component\Validator\Exception\MappingException');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\All;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Constraints\Choice;
|
||||
use Symfony\Component\Validator\Constraints\Collection;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
use Symfony\Component\Validator\Constraints\Range;
|
||||
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
|
||||
|
||||
class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testLoadClassMetadataReturnsFalseIfEmpty()
|
||||
{
|
||||
$loader = new YamlFileLoader(__DIR__.'/empty-mapping.yml');
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
|
||||
$this->assertFalse($loader->loadClassMetadata($metadata));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidYamlFiles
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidYamlFiles($path)
|
||||
{
|
||||
$loader = new YamlFileLoader(__DIR__.'/'.$path);
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
|
||||
$loader->loadClassMetadata($metadata);
|
||||
}
|
||||
|
||||
public function provideInvalidYamlFiles()
|
||||
{
|
||||
return array(
|
||||
array('nonvalid-mapping.yml'),
|
||||
array('bad-format.yml'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/symfony/symfony/pull/12158
|
||||
*/
|
||||
public function testDoNotModifyStateIfExceptionIsThrown()
|
||||
{
|
||||
$loader = new YamlFileLoader(__DIR__.'/nonvalid-mapping.yml');
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
try {
|
||||
$loader->loadClassMetadata($metadata);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
// Call again. Again an exception should be thrown
|
||||
$this->setExpectedException('\InvalidArgumentException');
|
||||
$loader->loadClassMetadata($metadata);
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataReturnsTrueIfSuccessful()
|
||||
{
|
||||
$loader = new YamlFileLoader(__DIR__.'/constraint-mapping.yml');
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
|
||||
$this->assertTrue($loader->loadClassMetadata($metadata));
|
||||
}
|
||||
|
||||
public function testLoadClassMetadataReturnsFalseIfNotSuccessful()
|
||||
{
|
||||
$loader = new YamlFileLoader(__DIR__.'/constraint-mapping.yml');
|
||||
$metadata = new ClassMetadata('\stdClass');
|
||||
|
||||
$this->assertFalse($loader->loadClassMetadata($metadata));
|
||||
}
|
||||
|
||||
public function testLoadClassMetadata()
|
||||
{
|
||||
$loader = new YamlFileLoader(__DIR__.'/constraint-mapping.yml');
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$expected = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||
$expected->setGroupSequence(array('Foo', 'Entity'));
|
||||
$expected->addConstraint(new ConstraintA());
|
||||
$expected->addConstraint(new ConstraintB());
|
||||
$expected->addConstraint(new Callback('validateMe'));
|
||||
$expected->addConstraint(new Callback('validateMeStatic'));
|
||||
$expected->addConstraint(new Callback(array('Symfony\Component\Validator\Tests\Fixtures\CallbackClass', 'callback')));
|
||||
$expected->addPropertyConstraint('firstName', new NotNull());
|
||||
$expected->addPropertyConstraint('firstName', new Range(array('min' => 3)));
|
||||
$expected->addPropertyConstraint('firstName', new Choice(array('A', 'B')));
|
||||
$expected->addPropertyConstraint('firstName', new All(array(new NotNull(), new Range(array('min' => 3)))));
|
||||
$expected->addPropertyConstraint('firstName', new All(array('constraints' => array(new NotNull(), new Range(array('min' => 3))))));
|
||||
$expected->addPropertyConstraint('firstName', new Collection(array('fields' => array(
|
||||
'foo' => array(new NotNull(), new Range(array('min' => 3))),
|
||||
'bar' => array(new Range(array('min' => 5))),
|
||||
))));
|
||||
$expected->addPropertyConstraint('firstName', new Choice(array(
|
||||
'message' => 'Must be one of %choices%',
|
||||
'choices' => array('A', 'B'),
|
||||
)));
|
||||
$expected->addGetterConstraint('lastName', new NotNull());
|
||||
$expected->addGetterConstraint('valid', new IsTrue());
|
||||
$expected->addGetterConstraint('permissions', new IsTrue());
|
||||
|
||||
$this->assertEquals($expected, $metadata);
|
||||
}
|
||||
|
||||
public function testLoadGroupSequenceProvider()
|
||||
{
|
||||
$loader = new YamlFileLoader(__DIR__.'/constraint-mapping.yml');
|
||||
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity');
|
||||
|
||||
$loader->loadClassMetadata($metadata);
|
||||
|
||||
$expected = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity');
|
||||
$expected->setGroupSequenceProvider(true);
|
||||
|
||||
$this->assertEquals($expected, $metadata);
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
namespaces:
|
||||
custom: Symfony\Component\Validator\Tests\Fixtures\
|
||||
|
||||
Symfony\Component\Validator\Tests\Fixtures\Entity:
|
||||
constraints:
|
||||
# Custom constraint
|
||||
- Symfony\Component\Validator\Tests\Fixtures\ConstraintA: ~
|
||||
# Custom constraint with namespaces prefix
|
||||
- "custom:ConstraintB": ~
|
|
@ -1,19 +0,0 @@
|
|||
<?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>
|
|
@ -1,119 +0,0 @@
|
|||
<?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">
|
||||
|
||||
<group-sequence>
|
||||
<value>Foo</value>
|
||||
<value>Entity</value>
|
||||
</group-sequence>
|
||||
|
||||
<!-- CLASS CONSTRAINTS -->
|
||||
|
||||
<!-- Custom constraint -->
|
||||
<constraint name="Symfony\Component\Validator\Tests\Fixtures\ConstraintA" />
|
||||
|
||||
<!-- Custom constraint with namespace abbreviation-->
|
||||
<constraint name="custom:ConstraintB" />
|
||||
|
||||
<!-- Callbacks -->
|
||||
<constraint name="Callback">validateMe</constraint>
|
||||
|
||||
<constraint name="Callback">validateMeStatic</constraint>
|
||||
|
||||
<constraint name="Callback">
|
||||
<value>Symfony\Component\Validator\Tests\Fixtures\CallbackClass</value>
|
||||
<value>callback</value>
|
||||
</constraint>
|
||||
|
||||
<!-- PROPERTY CONSTRAINTS -->
|
||||
|
||||
<property name="firstName">
|
||||
|
||||
<!-- Constraint without value -->
|
||||
<constraint name="NotNull" />
|
||||
|
||||
<!-- Constraint with single value -->
|
||||
<constraint name="Range">
|
||||
<option name="min">3</option>
|
||||
</constraint>
|
||||
|
||||
<!-- Constraint with multiple values -->
|
||||
<constraint name="Choice">
|
||||
<value>A</value>
|
||||
<value>B</value>
|
||||
</constraint>
|
||||
|
||||
<!-- Constraint with child constraints -->
|
||||
<constraint name="All">
|
||||
<constraint name="NotNull" />
|
||||
<constraint name="Range">
|
||||
<option name="min">3</option>
|
||||
</constraint>
|
||||
|
||||
</constraint>
|
||||
|
||||
<!-- Option with child constraints -->
|
||||
<constraint name="All">
|
||||
<option name="constraints">
|
||||
<constraint name="NotNull" />
|
||||
<constraint name="Range">
|
||||
<option name="min">3</option>
|
||||
</constraint>
|
||||
</option>
|
||||
</constraint>
|
||||
|
||||
<!-- Value with child constraints -->
|
||||
<constraint name="Collection">
|
||||
<option name="fields">
|
||||
<value key="foo">
|
||||
<constraint name="NotNull" />
|
||||
<constraint name="Range">
|
||||
<option name="min">3</option>
|
||||
</constraint>
|
||||
</value>
|
||||
<value key="bar">
|
||||
<constraint name="Range">
|
||||
<option name="min">5</option>
|
||||
</constraint>
|
||||
</value>
|
||||
</option>
|
||||
</constraint>
|
||||
|
||||
<!-- Constraint with options -->
|
||||
<constraint name="Choice">
|
||||
<!-- Option with single value -->
|
||||
<option name="message"> Must be one of %choices% </option>
|
||||
<!-- Option with multiple values -->
|
||||
<option name="choices">
|
||||
<value>A</value>
|
||||
<value>B</value>
|
||||
</option>
|
||||
</constraint>
|
||||
</property>
|
||||
|
||||
<!-- GETTER CONSTRAINTS -->
|
||||
|
||||
<getter property="lastName">
|
||||
<constraint name="NotNull" />
|
||||
</getter>
|
||||
<getter property="valid">
|
||||
<constraint name="IsTrue" />
|
||||
</getter>
|
||||
<getter property="permissions">
|
||||
<constraint name="IsTrue" />
|
||||
</getter>
|
||||
</class>
|
||||
|
||||
<class name="Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity">
|
||||
|
||||
<!-- GROUP SEQUENCE PROVIDER -->
|
||||
<group-sequence-provider />
|
||||
|
||||
</class>
|
||||
</constraint-mapping>
|
|
@ -1,62 +0,0 @@
|
|||
namespaces:
|
||||
custom: Symfony\Component\Validator\Tests\Fixtures\
|
||||
|
||||
Symfony\Component\Validator\Tests\Fixtures\Entity:
|
||||
group_sequence:
|
||||
- Foo
|
||||
- Entity
|
||||
|
||||
constraints:
|
||||
# Custom constraint
|
||||
- Symfony\Component\Validator\Tests\Fixtures\ConstraintA: ~
|
||||
# Custom constraint with namespaces prefix
|
||||
- "custom:ConstraintB": ~
|
||||
# Callbacks
|
||||
- Callback: validateMe
|
||||
- Callback: validateMeStatic
|
||||
- Callback: [Symfony\Component\Validator\Tests\Fixtures\CallbackClass, callback]
|
||||
|
||||
properties:
|
||||
firstName:
|
||||
# Constraint without value
|
||||
- NotNull: ~
|
||||
# Constraint with single value
|
||||
- Range:
|
||||
min: 3
|
||||
# Constraint with multiple values
|
||||
- Choice: [A, B]
|
||||
# Constraint with child constraints
|
||||
- All:
|
||||
- NotNull: ~
|
||||
- Range:
|
||||
min: 3
|
||||
# Option with child constraints
|
||||
- All:
|
||||
constraints:
|
||||
- NotNull: ~
|
||||
- Range:
|
||||
min: 3
|
||||
# Value with child constraints
|
||||
- Collection:
|
||||
fields:
|
||||
foo:
|
||||
- NotNull: ~
|
||||
- Range:
|
||||
min: 3
|
||||
bar:
|
||||
- Range:
|
||||
min: 5
|
||||
# Constraint with options
|
||||
- Choice: { choices: [A, B], message: Must be one of %choices% }
|
||||
dummy:
|
||||
|
||||
getters:
|
||||
lastName:
|
||||
- NotNull: ~
|
||||
valid:
|
||||
- "IsTrue": ~
|
||||
permissions:
|
||||
- "IsTrue": ~
|
||||
|
||||
Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity:
|
||||
group_sequence_provider: true
|
|
@ -1 +0,0 @@
|
|||
foo
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE foo>
|
||||
<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">
|
||||
<class name="Symfony\Component\Validator\Tests\Fixtures\Entity" />
|
||||
</constraint-mapping>
|
|
@ -1,119 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Valid;
|
||||
use Symfony\Component\Validator\Mapping\MemberMetadata;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
|
||||
|
||||
class MemberMetadataTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $metadata;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->metadata = new TestMemberMetadata(
|
||||
'Symfony\Component\Validator\Tests\Fixtures\Entity',
|
||||
'getLastName',
|
||||
'lastName'
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->metadata = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAddValidSetsMemberToCascaded()
|
||||
{
|
||||
$result = $this->metadata->addConstraint(new Valid());
|
||||
|
||||
$this->assertEquals(array(), $this->metadata->getConstraints());
|
||||
$this->assertEquals($result, $this->metadata);
|
||||
$this->assertTrue($this->metadata->isCascaded());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAddOtherConstraintDoesNotSetMemberToCascaded()
|
||||
{
|
||||
$result = $this->metadata->addConstraint($constraint = new ConstraintA());
|
||||
|
||||
$this->assertEquals(array($constraint), $this->metadata->getConstraints());
|
||||
$this->assertEquals($result, $this->metadata);
|
||||
$this->assertFalse($this->metadata->isCascaded());
|
||||
}
|
||||
|
||||
public function testAddConstraintRequiresClassConstraints()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
|
||||
|
||||
$this->metadata->addConstraint(new ClassConstraint());
|
||||
}
|
||||
|
||||
public function testSerialize()
|
||||
{
|
||||
$this->metadata->addConstraint(new ConstraintA(array('property1' => 'A')));
|
||||
$this->metadata->addConstraint(new ConstraintB(array('groups' => 'TestGroup')));
|
||||
|
||||
$metadata = unserialize(serialize($this->metadata));
|
||||
|
||||
$this->assertEquals($this->metadata, $metadata);
|
||||
}
|
||||
|
||||
public function testSerializeCollectionCascaded()
|
||||
{
|
||||
$this->metadata->addConstraint(new Valid(array('traverse' => true)));
|
||||
|
||||
$metadata = unserialize(serialize($this->metadata));
|
||||
|
||||
$this->assertEquals($this->metadata, $metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacySerializeCollectionCascadedDeeply()
|
||||
{
|
||||
$this->metadata->addConstraint(new Valid(array('traverse' => true)));
|
||||
|
||||
$metadata = unserialize(serialize($this->metadata));
|
||||
|
||||
$this->assertEquals($this->metadata, $metadata);
|
||||
}
|
||||
|
||||
public function testSerializeCollectionNotCascaded()
|
||||
{
|
||||
$this->metadata->addConstraint(new Valid(array('traverse' => false)));
|
||||
|
||||
$metadata = unserialize(serialize($this->metadata));
|
||||
|
||||
$this->assertEquals($this->metadata, $metadata);
|
||||
}
|
||||
}
|
||||
|
||||
class TestMemberMetadata extends MemberMetadata
|
||||
{
|
||||
public function getPropertyValue($object)
|
||||
{
|
||||
}
|
||||
|
||||
protected function newReflectionMember($object)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\PropertyMetadata;
|
||||
use Symfony\Component\Validator\Tests\Fixtures\Entity;
|
||||
|
||||
class PropertyMetadataTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
|
||||
const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
|
||||
|
||||
public function testInvalidPropertyName()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException');
|
||||
|
||||
new PropertyMetadata(self::CLASSNAME, 'foobar');
|
||||
}
|
||||
|
||||
public function testGetPropertyValueFromPrivateProperty()
|
||||
{
|
||||
$entity = new Entity('foobar');
|
||||
$metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
|
||||
|
||||
$this->assertEquals('foobar', $metadata->getPropertyValue($entity));
|
||||
}
|
||||
|
||||
public function testGetPropertyValueFromOverriddenPrivateProperty()
|
||||
{
|
||||
$entity = new Entity('foobar');
|
||||
$metadata = new PropertyMetadata(self::PARENTCLASS, 'data');
|
||||
|
||||
$this->assertTrue($metadata->isPublic($entity));
|
||||
$this->assertEquals('Overridden data', $metadata->getPropertyValue($entity));
|
||||
}
|
||||
}
|
Reference in a new issue