d2f846b453
This continues the work started in #12497 on the `2.3` branch.
146 lines
4.5 KiB
PHP
146 lines
4.5 KiB
PHP
<?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;
|
|
|
|
use Symfony\Component\Validator\Validation;
|
|
use Symfony\Component\Validator\ValidatorBuilder;
|
|
use Symfony\Component\Validator\ValidatorBuilderInterface;
|
|
|
|
class ValidatorBuilderTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* @var ValidatorBuilderInterface
|
|
*/
|
|
protected $builder;
|
|
|
|
protected function setUp()
|
|
{
|
|
$this->builder = new ValidatorBuilder();
|
|
}
|
|
|
|
protected function tearDown()
|
|
{
|
|
$this->builder = null;
|
|
}
|
|
|
|
public function testAddObjectInitializer()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->addObjectInitializer(
|
|
$this->getMock('Symfony\Component\Validator\ObjectInitializerInterface')
|
|
));
|
|
}
|
|
|
|
public function testAddObjectInitializers()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->addObjectInitializers(array()));
|
|
}
|
|
|
|
public function testAddXmlMapping()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->addXmlMapping('mapping'));
|
|
}
|
|
|
|
public function testAddXmlMappings()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->addXmlMappings(array()));
|
|
}
|
|
|
|
public function testAddYamlMapping()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->addYamlMapping('mapping'));
|
|
}
|
|
|
|
public function testAddYamlMappings()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->addYamlMappings(array()));
|
|
}
|
|
|
|
public function testAddMethodMapping()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->addMethodMapping('mapping'));
|
|
}
|
|
|
|
public function testAddMethodMappings()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->addMethodMappings(array()));
|
|
}
|
|
|
|
public function testEnableAnnotationMapping()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->enableAnnotationMapping());
|
|
}
|
|
|
|
public function testDisableAnnotationMapping()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->disableAnnotationMapping());
|
|
}
|
|
|
|
public function testSetMetadataCache()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->setMetadataCache(
|
|
$this->getMock('Symfony\Component\Validator\Mapping\Cache\CacheInterface'))
|
|
);
|
|
}
|
|
|
|
public function testSetConstraintValidatorFactory()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->setConstraintValidatorFactory(
|
|
$this->getMock('Symfony\Component\Validator\ConstraintValidatorFactoryInterface'))
|
|
);
|
|
}
|
|
|
|
public function testSetTranslator()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->setTranslator(
|
|
$this->getMock('Symfony\Component\Translation\TranslatorInterface'))
|
|
);
|
|
}
|
|
|
|
public function testSetTranslationDomain()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->setTranslationDomain('TRANS_DOMAIN'));
|
|
}
|
|
|
|
public function testDefaultApiVersion()
|
|
{
|
|
if (PHP_VERSION_ID < 50309) {
|
|
// Old implementation on PHP < 5.3.9
|
|
$this->assertInstanceOf('Symfony\Component\Validator\Validator', $this->builder->getValidator());
|
|
} else {
|
|
// Legacy compatible implementation on PHP >= 5.3.9
|
|
$this->assertInstanceOf('Symfony\Component\Validator\Validator\LegacyValidator', $this->builder->getValidator());
|
|
}
|
|
}
|
|
|
|
public function testSetApiVersion24()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->setApiVersion(Validation::API_VERSION_2_4));
|
|
$this->assertInstanceOf('Symfony\Component\Validator\Validator', $this->builder->getValidator());
|
|
}
|
|
|
|
public function testSetApiVersion25()
|
|
{
|
|
$this->assertSame($this->builder, $this->builder->setApiVersion(Validation::API_VERSION_2_5));
|
|
$this->assertInstanceOf('Symfony\Component\Validator\Validator\RecursiveValidator', $this->builder->getValidator());
|
|
}
|
|
|
|
public function testSetApiVersion24And25()
|
|
{
|
|
if (PHP_VERSION_ID < 50309) {
|
|
$this->markTestSkipped('Not supported prior to PHP 5.3.9');
|
|
}
|
|
|
|
$this->assertSame($this->builder, $this->builder->setApiVersion(Validation::API_VERSION_2_5_BC));
|
|
$this->assertInstanceOf('Symfony\Component\Validator\Validator\LegacyValidator', $this->builder->getValidator());
|
|
}
|
|
}
|