ValidatorContextTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Validator;
  11. use Symfony\Component\Validator\Validator;
  12. use Symfony\Component\Validator\ValidatorContext;
  13. class ValidatorContextTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected $context;
  16. protected function setUp()
  17. {
  18. $this->context = new ValidatorContext();
  19. }
  20. protected function tearDown()
  21. {
  22. $this->context = null;
  23. }
  24. public function testSetClassMetadataFactory()
  25. {
  26. $factory = $this->getMock('Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface');
  27. $result = $this->context->setClassMetadataFactory($factory);
  28. $this->assertSame($this->context, $result);
  29. $this->assertSame($factory, $this->context->getClassMetadataFactory());
  30. }
  31. public function testSetConstraintValidatorFactory()
  32. {
  33. $factory = $this->getMock('Symfony\Component\Validator\ConstraintValidatorFactoryInterface');
  34. $result = $this->context->setConstraintValidatorFactory($factory);
  35. $this->assertSame($this->context, $result);
  36. $this->assertSame($factory, $this->context->getConstraintValidatorFactory());
  37. }
  38. public function testGetValidator()
  39. {
  40. $metadataFactory = $this->getMock('Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface');
  41. $validatorFactory = $this->getMock('Symfony\Component\Validator\ConstraintValidatorFactoryInterface');
  42. $validator = $this->context
  43. ->setClassMetadataFactory($metadataFactory)
  44. ->setConstraintValidatorFactory($validatorFactory)
  45. ->getValidator();
  46. $this->assertEquals(new Validator($metadataFactory, $validatorFactory), $validator);
  47. }
  48. }