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\LessThan; 15use Symfony\Component\Validator\Constraints\LessThanValidator; 16 17/** 18 * @author Daniel Holmes <daniel@danielholmes.org> 19 */ 20class LessThanValidatorTest extends AbstractComparisonValidatorTestCase 21{ 22 protected function createValidator() 23 { 24 return new LessThanValidator(); 25 } 26 27 protected function createConstraint(array $options = null) 28 { 29 return new LessThan($options); 30 } 31 32 protected function getErrorCode() 33 { 34 return LessThan::TOO_HIGH_ERROR; 35 } 36 37 /** 38 * {@inheritdoc} 39 */ 40 public function provideValidComparisons() 41 { 42 return [ 43 [1, 2], 44 [new \DateTime('2000-01-01'), new \DateTime('2010-01-01')], 45 [new \DateTime('2000-01-01'), '2010-01-01'], 46 [new \DateTime('2000-01-01 UTC'), '2010-01-01 UTC'], 47 [new ComparisonTest_Class(4), new ComparisonTest_Class(5)], 48 ['22', '333'], 49 [null, 1], 50 ]; 51 } 52 53 /** 54 * {@inheritdoc} 55 */ 56 public function provideValidComparisonsToPropertyPath() 57 { 58 return [ 59 [4], 60 ]; 61 } 62 63 /** 64 * {@inheritdoc} 65 */ 66 public function provideInvalidComparisons() 67 { 68 return [ 69 [3, '3', 2, '2', 'integer'], 70 [2, '2', 2, '2', 'integer'], 71 [new \DateTime('2010-01-01'), 'Jan 1, 2010, 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', 'DateTime'], 72 [new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', 'DateTime'], 73 [new \DateTime('2010-01-01'), 'Jan 1, 2010, 12:00 AM', '2000-01-01', 'Jan 1, 2000, 12:00 AM', 'DateTime'], 74 [new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', '2000-01-01', 'Jan 1, 2000, 12:00 AM', 'DateTime'], 75 [new \DateTime('2010-01-01 UTC'), 'Jan 1, 2010, 12:00 AM', '2000-01-01 UTC', 'Jan 1, 2000, 12:00 AM', 'DateTime'], 76 [new \DateTime('2000-01-01 UTC'), 'Jan 1, 2000, 12:00 AM', '2000-01-01 UTC', 'Jan 1, 2000, 12:00 AM', 'DateTime'], 77 [new ComparisonTest_Class(5), '5', new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'], 78 [new ComparisonTest_Class(6), '6', new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'], 79 ['333', '"333"', '22', '"22"', 'string'], 80 ]; 81 } 82 83 public function provideComparisonsToNullValueAtPropertyPath() 84 { 85 return [ 86 [5, '5', true], 87 ]; 88 } 89} 90