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