ConstraintViolationTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\ConstraintViolation;
  13. class ConstraintViolationTest extends TestCase
  14. {
  15. public function testToStringHandlesArrays()
  16. {
  17. $violation = new ConstraintViolation(
  18. 'Array',
  19. '{{ value }}',
  20. array('{{ value }}' => array(1, 2, 3)),
  21. 'Root',
  22. 'property.path',
  23. null
  24. );
  25. $expected = <<<'EOF'
  26. Root.property.path:
  27. Array
  28. EOF;
  29. $this->assertSame($expected, (string) $violation);
  30. }
  31. public function testToStringHandlesArrayRoots()
  32. {
  33. $violation = new ConstraintViolation(
  34. '42 cannot be used here',
  35. 'this is the message template',
  36. array(),
  37. array('some_value' => 42),
  38. 'some_value',
  39. null
  40. );
  41. $expected = <<<'EOF'
  42. Array.some_value:
  43. 42 cannot be used here
  44. EOF;
  45. $this->assertSame($expected, (string) $violation);
  46. }
  47. }