360eccabc70250d23aee61e677093ea0b6d4048b
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / IdenticalToValidatorTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator\Tests\Constraints;
13
14 use Symfony\Component\Validator\Constraints\IdenticalTo;
15 use Symfony\Component\Validator\Constraints\IdenticalToValidator;
16
17 /**
18  * @author Daniel Holmes <daniel@danielholmes.org>
19  */
20 class IdenticalToValidatorTest extends AbstractComparisonValidatorTestCase
21 {
22     protected function createValidator()
23     {
24         return new IdenticalToValidator();
25     }
26
27     protected function createConstraint(array $options = null)
28     {
29         return new IdenticalTo($options);
30     }
31
32     protected function getErrorCode()
33     {
34         return IdenticalTo::NOT_IDENTICAL_ERROR;
35     }
36
37     public function provideAllValidComparisons()
38     {
39         $this->setDefaultTimezone('UTC');
40
41         // Don't call addPhp5Dot5Comparisons() automatically, as it does
42         // not take care of identical objects
43         $comparisons = $this->provideValidComparisons();
44
45         $this->restoreDefaultTimezone();
46
47         return $comparisons;
48     }
49
50     /**
51      * {@inheritdoc}
52      */
53     public function provideValidComparisons()
54     {
55         $date = new \DateTime('2000-01-01');
56         $object = new ComparisonTest_Class(2);
57
58         $comparisons = array(
59             array(3, 3),
60             array('a', 'a'),
61             array($date, $date),
62             array($object, $object),
63             array(null, 1),
64         );
65
66         $immutableDate = new \DateTimeImmutable('2000-01-01');
67         $comparisons[] = array($immutableDate, $immutableDate);
68
69         return $comparisons;
70     }
71
72     /**
73      * {@inheritdoc}
74      */
75     public function provideValidComparisonsToPropertyPath()
76     {
77         return array(
78             array(5),
79         );
80     }
81
82     /**
83      * {@inheritdoc}
84      */
85     public function provideInvalidComparisons()
86     {
87         return array(
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'),
94         );
95     }
96 }