NotIdenticalToValidatorTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\NotIdenticalTo;
  12. use Symfony\Component\Validator\Constraints\NotIdenticalToValidator;
  13. use Symfony\Component\Validator\Validation;
  14. /**
  15. * @author Daniel Holmes <daniel@danielholmes.org>
  16. */
  17. class NotIdenticalToValidatorTest extends AbstractComparisonValidatorTestCase
  18. {
  19. protected function getApiVersion()
  20. {
  21. return Validation::API_VERSION_2_5;
  22. }
  23. protected function createValidator()
  24. {
  25. return new NotIdenticalToValidator();
  26. }
  27. protected function createConstraint(array $options = null)
  28. {
  29. return new NotIdenticalTo($options);
  30. }
  31. protected function getErrorCode()
  32. {
  33. return NotIdenticalTo::IS_IDENTICAL_ERROR;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function provideValidComparisons()
  39. {
  40. return array(
  41. array(1, 2),
  42. array('2', 2),
  43. array('22', '333'),
  44. array(new \DateTime('2001-01-01'), new \DateTime('2000-01-01')),
  45. array(new \DateTime('2000-01-01'), new \DateTime('2000-01-01')),
  46. array(new \DateTime('2001-01-01'), '2000-01-01'),
  47. array(new \DateTime('2000-01-01'), '2000-01-01'),
  48. array(new \DateTime('2001-01-01'), '2000-01-01'),
  49. array(new \DateTime('2000-01-01 UTC'), '2000-01-01 UTC'),
  50. array(null, 1),
  51. );
  52. }
  53. public function provideAllInvalidComparisons()
  54. {
  55. $this->setDefaultTimezone('UTC');
  56. // Don't call addPhp5Dot5Comparisons() automatically, as it does
  57. // not take care of identical objects
  58. $comparisons = $this->provideInvalidComparisons();
  59. $this->restoreDefaultTimezone();
  60. return $comparisons;
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function provideInvalidComparisons()
  66. {
  67. $date = new \DateTime('2000-01-01');
  68. $object = new ComparisonTest_Class(2);
  69. $comparisons = array(
  70. array(3, '3', 3, '3', 'integer'),
  71. array('a', '"a"', 'a', '"a"', 'string'),
  72. array($date, 'Jan 1, 2000, 12:00 AM', $date, 'Jan 1, 2000, 12:00 AM', 'DateTime'),
  73. array($object, '2', $object, '2', __NAMESPACE__.'\ComparisonTest_Class'),
  74. );
  75. return $comparisons;
  76. }
  77. }