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