AssertTrueValidatorTest.php 1.2 KB

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