AssertTrueValidatorTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\Constraints;
  11. use Symfony\Component\Validator\Constraints\True;
  12. use Symfony\Component\Validator\Constraints\TrueValidator;
  13. class TrueValidatorTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected $validator;
  16. protected function setUp()
  17. {
  18. $this->validator = new TrueValidator();
  19. }
  20. protected function tearDown()
  21. {
  22. $this->validator = null;
  23. }
  24. public function testNullIsValid()
  25. {
  26. $this->assertTrue($this->validator->isValid(null, new True()));
  27. }
  28. public function testTrueIsValid()
  29. {
  30. $this->assertTrue($this->validator->isValid(true, new True()));
  31. }
  32. public function testFalseIsInvalid()
  33. {
  34. $constraint = new True(array(
  35. 'message' => 'myMessage'
  36. ));
  37. $this->assertFalse($this->validator->isValid(false, $constraint));
  38. $this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
  39. $this->assertEquals($this->validator->getMessageParameters(), array());
  40. }
  41. }