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;
18 * @author Daniel Holmes <daniel@danielholmes.org>
20 class IdenticalToValidatorTest extends AbstractComparisonValidatorTestCase
22 protected function createValidator()
24 return new IdenticalToValidator();
27 protected function createConstraint(array $options = null)
29 return new IdenticalTo($options);
32 protected function getErrorCode()
34 return IdenticalTo::NOT_IDENTICAL_ERROR;
37 public function provideAllValidComparisons()
39 $this->setDefaultTimezone('UTC');
41 // Don't call addPhp5Dot5Comparisons() automatically, as it does
42 // not take care of identical objects
43 $comparisons = $this->provideValidComparisons();
45 $this->restoreDefaultTimezone();
53 public function provideValidComparisons()
55 $date = new \DateTime('2000-01-01');
56 $object = new ComparisonTest_Class(2);
62 array($object, $object),
66 $immutableDate = new \DateTimeImmutable('2000-01-01');
67 $comparisons[] = array($immutableDate, $immutableDate);
75 public function provideValidComparisonsToPropertyPath()
85 public function provideInvalidComparisons()
88 array(1, '1', 2, '2', 'integer'),
89 array(2, '2', '2', '"2"', 'string'),
90 array('22', '"22"', '333', '"333"', 'string'),
91 array(new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', 'DateTime'),
92 array(new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', new \DateTime('1999-01-01'), 'Jan 1, 1999, 12:00 AM', 'DateTime'),
93 array(new ComparisonTest_Class(4), '4', new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'),