EqualToValidatorTest.php 2.2 KB

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