ValidatorBuilderTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\Component\Validator\Tests;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Validator\ValidatorBuilder;
  13. use Symfony\Component\Validator\ValidatorBuilderInterface;
  14. class ValidatorBuilderTest extends TestCase
  15. {
  16. /**
  17. * @var ValidatorBuilderInterface
  18. */
  19. protected $builder;
  20. protected function setUp()
  21. {
  22. $this->builder = new ValidatorBuilder();
  23. }
  24. protected function tearDown()
  25. {
  26. $this->builder = null;
  27. }
  28. public function testAddObjectInitializer()
  29. {
  30. $this->assertSame($this->builder, $this->builder->addObjectInitializer(
  31. $this->getMockBuilder('Symfony\Component\Validator\ObjectInitializerInterface')->getMock()
  32. ));
  33. }
  34. public function testAddObjectInitializers()
  35. {
  36. $this->assertSame($this->builder, $this->builder->addObjectInitializers(array()));
  37. }
  38. public function testAddXmlMapping()
  39. {
  40. $this->assertSame($this->builder, $this->builder->addXmlMapping('mapping'));
  41. }
  42. public function testAddXmlMappings()
  43. {
  44. $this->assertSame($this->builder, $this->builder->addXmlMappings(array()));
  45. }
  46. public function testAddYamlMapping()
  47. {
  48. $this->assertSame($this->builder, $this->builder->addYamlMapping('mapping'));
  49. }
  50. public function testAddYamlMappings()
  51. {
  52. $this->assertSame($this->builder, $this->builder->addYamlMappings(array()));
  53. }
  54. public function testAddMethodMapping()
  55. {
  56. $this->assertSame($this->builder, $this->builder->addMethodMapping('mapping'));
  57. }
  58. public function testAddMethodMappings()
  59. {
  60. $this->assertSame($this->builder, $this->builder->addMethodMappings(array()));
  61. }
  62. public function testEnableAnnotationMapping()
  63. {
  64. $this->assertSame($this->builder, $this->builder->enableAnnotationMapping());
  65. }
  66. public function testDisableAnnotationMapping()
  67. {
  68. $this->assertSame($this->builder, $this->builder->disableAnnotationMapping());
  69. }
  70. public function testSetMetadataCache()
  71. {
  72. $this->assertSame($this->builder, $this->builder->setMetadataCache(
  73. $this->getMockBuilder('Symfony\Component\Validator\Mapping\Cache\CacheInterface')->getMock())
  74. );
  75. }
  76. public function testSetConstraintValidatorFactory()
  77. {
  78. $this->assertSame($this->builder, $this->builder->setConstraintValidatorFactory(
  79. $this->getMockBuilder('Symfony\Component\Validator\ConstraintValidatorFactoryInterface')->getMock())
  80. );
  81. }
  82. public function testSetTranslator()
  83. {
  84. $this->assertSame($this->builder, $this->builder->setTranslator(
  85. $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock())
  86. );
  87. }
  88. public function testSetTranslationDomain()
  89. {
  90. $this->assertSame($this->builder, $this->builder->setTranslationDomain('TRANS_DOMAIN'));
  91. }
  92. public function testGetValidator()
  93. {
  94. $this->assertInstanceOf('Symfony\Component\Validator\Validator\RecursiveValidator', $this->builder->getValidator());
  95. }
  96. }