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 12namespace Symfony\Component\Validator\Tests\Constraints; 13 14use Symfony\Component\Validator\Constraints\IdenticalTo; 15use Symfony\Component\Validator\Constraints\IdenticalToValidator; 16 17/** 18 * @author Daniel Holmes <daniel@danielholmes.org> 19 */ 20class 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 = [ 59 [3, 3], 60 ['a', 'a'], 61 [$date, $date], 62 [$object, $object], 63 [null, 1], 64 ]; 65 66 $immutableDate = new \DateTimeImmutable('2000-01-01'); 67 $comparisons[] = [$immutableDate, $immutableDate]; 68 69 return $comparisons; 70 } 71 72 /** 73 * {@inheritdoc} 74 */ 75 public function provideValidComparisonsToPropertyPath() 76 { 77 return [ 78 [5], 79 ]; 80 } 81 82 /** 83 * {@inheritdoc} 84 */ 85 public function provideInvalidComparisons() 86 { 87 return [ 88 [1, '1', 2, '2', 'integer'], 89 [2, '2', '2', '"2"', 'string'], 90 ['22', '"22"', '333', '"333"', 'string'], 91 [new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', 'DateTime'], 92 [new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', new \DateTime('1999-01-01'), 'Jan 1, 1999, 12:00 AM', 'DateTime'], 93 [new ComparisonTest_Class(4), '4', new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'], 94 ]; 95 } 96 97 public function provideComparisonsToNullValueAtPropertyPath() 98 { 99 return [ 100 [5, '5', false], 101 ]; 102 } 103} 104