Yaffs site version 1.1
[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 use Symfony\Component\Validator\Validation;
17
18 /**
19  * @author Daniel Holmes <daniel@danielholmes.org>
20  */
21 class IdenticalToValidatorTest extends AbstractComparisonValidatorTestCase
22 {
23     protected function getApiVersion()
24     {
25         return Validation::API_VERSION_2_5;
26     }
27
28     protected function createValidator()
29     {
30         return new IdenticalToValidator();
31     }
32
33     protected function createConstraint(array $options)
34     {
35         return new IdenticalTo($options);
36     }
37
38     protected function getErrorCode()
39     {
40         return IdenticalTo::NOT_IDENTICAL_ERROR;
41     }
42
43     public function provideAllValidComparisons()
44     {
45         $this->setDefaultTimezone('UTC');
46
47         // Don't call addPhp5Dot5Comparisons() automatically, as it does
48         // not take care of identical objects
49         $comparisons = $this->provideValidComparisons();
50
51         $this->restoreDefaultTimezone();
52
53         return $comparisons;
54     }
55
56     /**
57      * {@inheritdoc}
58      */
59     public function provideValidComparisons()
60     {
61         $date = new \DateTime('2000-01-01');
62         $object = new ComparisonTest_Class(2);
63
64         $comparisons = array(
65             array(3, 3),
66             array('a', 'a'),
67             array($date, $date),
68             array($object, $object),
69             array(null, 1),
70         );
71
72         if (\PHP_VERSION_ID >= 50500) {
73             $immutableDate = new \DateTimeImmutable('2000-01-01');
74             $comparisons[] = array($immutableDate, $immutableDate);
75         }
76
77         return $comparisons;
78     }
79
80     /**
81      * {@inheritdoc}
82      */
83     public function provideInvalidComparisons()
84     {
85         return array(
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'),
92         );
93     }
94 }