/opt/alt/php54/usr/share/pear/test/Validator/Symfony/Component/Validator/Tests/Constraints
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Range; use Symfony\Component\Validator\Constraints\RangeValidator; class RangeValidatorTest extends \PHPUnit_Framework_TestCase { protected $context; protected $validator; protected function setUp() { $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false); $this->validator = new RangeValidator(); $this->validator->initialize($this->context); } public function testNullIsValid() { $this->context->expects($this->never()) ->method('addViolation'); $this->validator->validate(null, new Range(array('min' => 10, 'max' => 20))); } public function getTenToTwenty() { return array( array(10.00001), array(19.99999), array('10.00001'), array('19.99999'), array(10), array(20), array(10.0), array(20.0), ); } public function getLessThanTen() { return array( array(9.99999), array('9.99999'), array(5), array(1.0), ); } public function getMoreThanTwenty() { return array( array(20.000001), array('20.000001'), array(21), array(30.0), ); } /** * @dataProvider getTenToTwenty */ public function testValidValuesMin($value) { $this->context->expects($this->never()) ->method('addViolation'); $constraint = new Range(array('min' => 10)); $this->validator->validate($value, $constraint); } /** * @dataProvider getTenToTwenty */ public function testValidValuesMax($value) { $this->context->expects($this->never()) ->method('addViolation'); $constraint = new Range(array('max' => 20)); $this->validator->validate($value, $constraint); } /** * @dataProvider getTenToTwenty */ public function testValidValuesMinMax($value) { $this->context->expects($this->never()) ->method('addViolation'); $constraint = new Range(array('min' => 10, 'max' => 20)); $this->validator->validate($value, $constraint); } /** * @dataProvider getLessThanTen */ public function testInvalidValuesMin($value) { $constraint = new Range(array( 'min' => 10, 'minMessage' => 'myMessage', )); $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', $this->identicalTo(array( '{{ value }}' => $value, '{{ limit }}' => 10, ))); $this->validator->validate($value, $constraint); } /** * @dataProvider getMoreThanTwenty */ public function testInvalidValuesMax($value) { $constraint = new Range(array( 'max' => 20, 'maxMessage' => 'myMessage', )); $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', $this->identicalTo(array( '{{ value }}' => $value, '{{ limit }}' => 20, ))); $this->validator->validate($value, $constraint); } /** * @dataProvider getMoreThanTwenty */ public function testInvalidValuesCombinedMax($value) { $constraint = new Range(array( 'min' => 10, 'max' => 20, 'minMessage' => 'myMinMessage', 'maxMessage' => 'myMaxMessage', )); $this->context->expects($this->once()) ->method('addViolation') ->with('myMaxMessage', $this->identicalTo(array( '{{ value }}' => $value, '{{ limit }}' => 20, ))); $this->validator->validate($value, $constraint); } /** * @dataProvider getLessThanTen */ public function testInvalidValuesCombinedMin($value) { $constraint = new Range(array( 'min' => 10, 'max' => 20, 'minMessage' => 'myMinMessage', 'maxMessage' => 'myMaxMessage', )); $this->context->expects($this->once()) ->method('addViolation') ->with('myMinMessage', $this->identicalTo(array( '{{ value }}' => $value, '{{ limit }}' => 10, ))); $this->validator->validate($value, $constraint); } public function getInvalidValues() { return array( array(9.999999), array(20.000001), array('9.999999'), array('20.000001'), array(new \stdClass()), ); } public function testMinMessageIsSet() { $constraint = new Range(array( 'min' => 10, 'max' => 20, 'minMessage' => 'myMessage', )); $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => 9, '{{ limit }}' => 10, )); $this->validator->validate(9, $constraint); } public function testMaxMessageIsSet() { $constraint = new Range(array( 'min' => 10, 'max' => 20, 'maxMessage' => 'myMessage', )); $this->context->expects($this->once()) ->method('addViolation') ->with('myMessage', array( '{{ value }}' => 21, '{{ limit }}' => 20, )); $this->validator->validate(21, $constraint); } }
.
Edit
..
Edit
AbstractComparisonValidatorTestCase.php
Edit
AllTest.php
Edit
AllValidatorTest.php
Edit
BlankValidatorTest.php
Edit
CallbackValidatorTest.php
Edit
CardSchemeValidatorTest.php
Edit
ChoiceValidatorTest.php
Edit
CollectionTest.php
Edit
CollectionValidatorArrayObjectTest.php
Edit
CollectionValidatorArrayTest.php
Edit
CollectionValidatorCustomArrayObjectTest.php
Edit
CollectionValidatorTest.php
Edit
CountValidatorArrayTest.php
Edit
CountValidatorCountableTest.php
Edit
CountValidatorTest.php
Edit
CountryValidatorTest.php
Edit
CurrencyValidatorTest.php
Edit
DateTimeValidatorTest.php
Edit
DateValidatorTest.php
Edit
EmailValidatorTest.php
Edit
EqualToValidatorTest.php
Edit
ExpressionValidatorTest.php
Edit
FalseValidatorTest.php
Edit
FileValidatorObjectTest.php
Edit
FileValidatorPathTest.php
Edit
FileValidatorTest.php
Edit
Fixtures
Edit
GreaterThanOrEqualValidatorTest.php
Edit
GreaterThanValidatorTest.php
Edit
IbanValidatorTest.php
Edit
IdenticalToValidatorTest.php
Edit
ImageValidatorTest.php
Edit
IpValidatorTest.php
Edit
IsbnValidatorTest.php
Edit
IssnValidatorTest.php
Edit
LanguageValidatorTest.php
Edit
LengthValidatorTest.php
Edit
LessThanOrEqualValidatorTest.php
Edit
LessThanValidatorTest.php
Edit
LocaleValidatorTest.php
Edit
LuhnValidatorTest.php
Edit
NotBlankValidatorTest.php
Edit
NotEqualToValidatorTest.php
Edit
NotIdenticalToValidatorTest.php
Edit
NotNullValidatorTest.php
Edit
NullValidatorTest.php
Edit
RangeValidatorTest.php
Edit
RegexValidatorTest.php
Edit
TimeValidatorTest.php
Edit
TrueValidatorTest.php
Edit
TypeValidatorTest.php
Edit
UrlValidatorTest.php
Edit
ValidTest.php
Edit