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