Вход Регистрация
Файл: symfony-2.7/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php
Строк: 164
<?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 SymfonyComponentFormTestsExtensionValidator;

use 
SymfonyComponentFormExtensionValidatorValidatorExtension;

class 
ValidatorExtensionTest extends PHPUnit_Framework_TestCase
{
    public function 
test2Dot5ValidationApi()
    {
        
$validator $this->getMock('SymfonyComponentValidatorValidatorValidatorInterface');
        
$metadata $this->getMockBuilder('SymfonyComponentValidatorMappingClassMetadata')
            ->
disableOriginalConstructor()
            ->
getMock();

        
$validator->expects($this->once())
            ->
method('getMetadataFor')
            ->
with($this->identicalTo('SymfonyComponentFormForm'))
            ->
will($this->returnValue($metadata));

        
// Verify that the constraints are added
        
$metadata->expects($this->once())
            ->
method('addConstraint')
            ->
with($this->isInstanceOf('SymfonyComponentFormExtensionValidatorConstraintsForm'));

        
$metadata->expects($this->once())
            ->
method('addPropertyConstraint')
            ->
with('children'$this->isInstanceOf('SymfonyComponentValidatorConstraintsValid'));

        
$extension = new ValidatorExtension($validator);
        
$guesser $extension->loadTypeGuesser();

        
$this->assertInstanceOf('SymfonyComponentFormExtensionValidatorValidatorTypeGuesser'$guesser);
    }

    public function 
test2Dot4ValidationApi()
    {
        
$factory $this->getMock('SymfonyComponentValidatorMetadataFactoryInterface');
        
$validator $this->getMock('SymfonyComponentValidatorValidatorInterface');
        
$metadata $this->getMockBuilder('SymfonyComponentValidatorMappingClassMetadata')
            ->
disableOriginalConstructor()
            ->
getMock();

        
$validator->expects($this->any())
            ->
method('getMetadataFactory')
            ->
will($this->returnValue($factory));

        
$factory->expects($this->once())
            ->
method('getMetadataFor')
            ->
with($this->identicalTo('SymfonyComponentFormForm'))
            ->
will($this->returnValue($metadata));

        
// Verify that the constraints are added
        
$metadata->expects($this->once())
            ->
method('addConstraint')
            ->
with($this->isInstanceOf('SymfonyComponentFormExtensionValidatorConstraintsForm'));

        
$metadata->expects($this->once())
            ->
method('addPropertyConstraint')
            ->
with('children'$this->isInstanceOf('SymfonyComponentValidatorConstraintsValid'));

        
$extension = new ValidatorExtension($validator);
        
$guesser $extension->loadTypeGuesser();

        
$this->assertInstanceOf('SymfonyComponentFormExtensionValidatorValidatorTypeGuesser'$guesser);
    }

    
/**
     * @expectedException SymfonyComponentFormExceptionUnexpectedTypeException
     */
    
public function testInvalidValidatorInterface()
    {
        new 
ValidatorExtension(null);
    }
}
Онлайн: 0
Реклама