4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Tests\Constraints;
14 use Symfony\Component\Validator\Constraints\IdenticalTo;
15 use Symfony\Component\Validator\Constraints\IdenticalToValidator;
16 use Symfony\Component\Validator\Validation;
19 * @author Daniel Holmes <daniel@danielholmes.org>
21 class IdenticalToValidatorTest extends AbstractComparisonValidatorTestCase
23 protected function getApiVersion()
25 return Validation::API_VERSION_2_5;
28 protected function createValidator()
30 return new IdenticalToValidator();
33 protected function createConstraint(array $options)
35 return new IdenticalTo($options);
38 protected function getErrorCode()
40 return IdenticalTo::NOT_IDENTICAL_ERROR;
43 public function provideAllValidComparisons()
45 $this->setDefaultTimezone('UTC');
47 // Don't call addPhp5Dot5Comparisons() automatically, as it does
48 // not take care of identical objects
49 $comparisons = $this->provideValidComparisons();
51 $this->restoreDefaultTimezone();
59 public function provideValidComparisons()
61 $date = new \DateTime('2000-01-01');
62 $object = new ComparisonTest_Class(2);
68 array($object, $object),
72 if (PHP_VERSION_ID >= 50500) {
73 $immutableDate = new \DateTimeImmutable('2000-01-01');
74 $comparisons[] = array($immutableDate, $immutableDate);
83 public function provideInvalidComparisons()
86 array(1, '1', 2, '2', 'integer'),
87 array(2, '2', '2', '"2"', 'string'),
88 array('22', '"22"', '333', '"333"', 'string'),
89 array(new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', 'DateTime'),
90 array(new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', new \DateTime('1999-01-01'), 'Jan 1, 1999, 12:00 AM', 'DateTime'),
91 array(new ComparisonTest_Class(4), '4', new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'),