LessThanOrEqualValidatorTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\Constraints;
  11. use Symfony\Component\Validator\Constraints\LessThanOrEqual;
  12. use Symfony\Component\Validator\Constraints\LessThanOrEqualValidator;
  13. use Symfony\Component\Validator\Validation;
  14. /**
  15. * @author Daniel Holmes <daniel@danielholmes.org>
  16. */
  17. class LessThanOrEqualValidatorTest extends AbstractComparisonValidatorTestCase
  18. {
  19. protected function getApiVersion()
  20. {
  21. return Validation::API_VERSION_2_5;
  22. }
  23. protected function createValidator()
  24. {
  25. return new LessThanOrEqualValidator();
  26. }
  27. protected function createConstraint(array $options = null)
  28. {
  29. return new LessThanOrEqual($options);
  30. }
  31. protected function getErrorCode()
  32. {
  33. return LessThanOrEqual::TOO_HIGH_ERROR;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function provideValidComparisons()
  39. {
  40. return array(
  41. array(1, 2),
  42. array(1, 1),
  43. array(new \DateTime('2000-01-01'), new \DateTime('2000-01-01')),
  44. array(new \DateTime('2000-01-01'), new \DateTime('2020-01-01')),
  45. array(new \DateTime('2000-01-01'), '2000-01-01'),
  46. array(new \DateTime('2000-01-01'), '2020-01-01'),
  47. array(new \DateTime('2000-01-01 UTC'), '2000-01-01 UTC'),
  48. array(new \DateTime('2000-01-01 UTC'), '2020-01-01 UTC'),
  49. array(new ComparisonTest_Class(4), new ComparisonTest_Class(5)),
  50. array(new ComparisonTest_Class(5), new ComparisonTest_Class(5)),
  51. array('a', 'a'),
  52. array('a', 'z'),
  53. array(null, 1),
  54. );
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function provideInvalidComparisons()
  60. {
  61. return array(
  62. array(2, '2', 1, '1', 'integer'),
  63. array(new \DateTime('2010-01-01'), 'Jan 1, 2010, 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', 'DateTime'),
  64. array(new \DateTime('2010-01-01'), 'Jan 1, 2010, 12:00 AM', '2000-01-01', 'Jan 1, 2000, 12:00 AM', 'DateTime'),
  65. array(new \DateTime('2010-01-01 UTC'), 'Jan 1, 2010, 12:00 AM', '2000-01-01 UTC', 'Jan 1, 2000, 12:00 AM', 'DateTime'),
  66. array(new ComparisonTest_Class(5), '5', new ComparisonTest_Class(4), '4', __NAMESPACE__.'\ComparisonTest_Class'),
  67. array('c', '"c"', 'b', '"b"', 'string'),
  68. );
  69. }
  70. }