ExecutionContextTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\ExecutionContext;
  12. class ExecutionContextTest extends \PHPUnit_Framework_TestCase
  13. {
  14. protected $walker;
  15. protected $metadataFactory;
  16. protected $context;
  17. protected function setUp()
  18. {
  19. $this->walker = $this->getMock('Symfony\Component\Validator\GraphWalker', array(), array(), '', false);
  20. $this->metadataFactory = $this->getMock('Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface');
  21. $this->context = new ExecutionContext('Root', $this->walker, $this->metadataFactory);
  22. }
  23. public function testClone()
  24. {
  25. $clone = clone $this->context;
  26. $this->assertNotSame($this->context, $clone);
  27. }
  28. public function testAddViolation()
  29. {
  30. $this->assertEquals(0, count($this->context->getViolations()));
  31. $this->context->addViolation('', array(), '');
  32. $this->assertEquals(1, count($this->context->getViolations()));
  33. }
  34. public function testGetViolations()
  35. {
  36. $this->context->addViolation('', array(), '');
  37. $this->assertEquals(1, count($this->context->getViolations()));
  38. $this->assertInstanceOf('Symfony\Component\Validator\ConstraintViolationList', $this->context->getViolations());
  39. }
  40. public function testGetRoot()
  41. {
  42. $this->assertEquals('Root', $this->context->getRoot());
  43. }
  44. public function testSetGetPropertyPath()
  45. {
  46. $this->context->setPropertyPath('property_path');
  47. $this->assertEquals('property_path', $this->context->getPropertyPath());
  48. }
  49. public function testSetGetCurrentClass()
  50. {
  51. $this->context->setCurrentClass('current_class');
  52. $this->assertEquals('current_class', $this->context->getCurrentClass());
  53. }
  54. public function testSetGetCurrentProperty()
  55. {
  56. $this->context->setCurrentProperty('current_property');
  57. $this->assertEquals('current_property', $this->context->getCurrentProperty());
  58. }
  59. public function testSetGetGroup()
  60. {
  61. $this->context->setGroup('group');
  62. $this->assertEquals('group', $this->context->getGroup());
  63. }
  64. public function testGetGraphWalker()
  65. {
  66. $this->assertSame($this->walker, $this->context->getGraphWalker());
  67. $this->assertInstanceOf(
  68. 'Symfony\Component\Validator\GraphWalker',
  69. $this->context->getGraphWalker()
  70. );
  71. }
  72. public function testGetMetadataFactory()
  73. {
  74. $this->assertSame($this->metadataFactory, $this->context->getMetadataFactory());
  75. $this->assertInstanceOf(
  76. 'Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface',
  77. $this->context->getMetadataFactory()
  78. );
  79. }
  80. }