LessThanValidatorTest.php 2.7 KB

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