|
| 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\PositiveOrZero; |
| 15 | + |
| 16 | +/** |
| 17 | + * @author Jan Schädlich <jan.schaedlich@sensiolabs.de> |
| 18 | + */ |
| 19 | +class GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest extends GreaterThanOrEqualValidatorTest |
| 20 | +{ |
| 21 | + protected function createConstraint(array $options = null) |
| 22 | + { |
| 23 | + return new PositiveOrZero(); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * {@inheritdoc} |
| 28 | + */ |
| 29 | + public function provideValidComparisons() |
| 30 | + { |
| 31 | + return [ |
| 32 | + [0, 0], |
| 33 | + [1, 0], |
| 34 | + [2, 0], |
| 35 | + [2.5, 0], |
| 36 | + ['0', '0'], |
| 37 | + ['333', '0'], |
| 38 | + [null, 0], |
| 39 | + ]; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * {@inheritdoc} |
| 44 | + */ |
| 45 | + public function provideInvalidComparisons() |
| 46 | + { |
| 47 | + return [ |
| 48 | + [-1, '-1', 0, '0', 'integer'], |
| 49 | + [-2, '-2', 0, '0', 'integer'], |
| 50 | + [-2.5, '-2.5', 0, '0', 'integer'], |
| 51 | + ]; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException |
| 56 | + * @expectedExceptionMessage The "propertyPath" option of the "Symfony\Component\Validator\Constraints\PositiveOrZero" constraint cannot be set. |
| 57 | + */ |
| 58 | + public function testThrowsConstraintExceptionIfPropertyPath() |
| 59 | + { |
| 60 | + return new PositiveOrZero(['propertyPath' => 'field']); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException |
| 65 | + * @expectedExceptionMessage The "value" option of the "Symfony\Component\Validator\Constraints\PositiveOrZero" constraint cannot be set. |
| 66 | + */ |
| 67 | + public function testThrowsConstraintExceptionIfValue() |
| 68 | + { |
| 69 | + return new PositiveOrZero(['value' => 0]); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @dataProvider provideInvalidConstraintOptions |
| 74 | + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException |
| 75 | + * @expectedExceptionMessage requires either the "value" or "propertyPath" option to be set. |
| 76 | + */ |
| 77 | + public function testThrowsConstraintExceptionIfNoValueOrPropertyPath($options) |
| 78 | + { |
| 79 | + $this->markTestSkipped('Value option always set for PositiveOrZero constraint'); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException |
| 84 | + * @expectedExceptionMessage requires only one of the "value" or "propertyPath" options to be set, not both. |
| 85 | + */ |
| 86 | + public function testThrowsConstraintExceptionIfBothValueAndPropertyPath() |
| 87 | + { |
| 88 | + $this->markTestSkipped('Value option is set for PositiveOrZero constraint automatically'); |
| 89 | + } |
| 90 | + |
| 91 | + public function testInvalidValuePath() |
| 92 | + { |
| 93 | + $this->markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint'); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * @dataProvider provideValidComparisonsToPropertyPath |
| 98 | + */ |
| 99 | + public function testValidComparisonToPropertyPath($comparedValue) |
| 100 | + { |
| 101 | + $this->markTestSkipped('PropertyPath option is not used in PositiveOrZero constraint'); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * @dataProvider provideValidComparisonsToPropertyPath |
| 106 | + */ |
| 107 | + public function testValidComparisonToPropertyPathOnArray($comparedValue) |
| 108 | + { |
| 109 | + $this->markTestSkipped('PropertyPath option is not used in Positive constraint'); |
| 110 | + } |
| 111 | +} |
0 commit comments