Server IP : 66.29.132.122 / Your IP : 18.191.132.26 Web Server : LiteSpeed System : Linux business142.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : admazpex ( 531) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/proc/self/root/proc/thread-self/root/proc/thread-self/root/proc/self/root/proc/thread-self/root/proc/self/root/proc/self/root/opt/alt/php55/usr/share/pear/test/Validator/Symfony/Component/Validator/Tests/Constraints/ |
Upload File : |
<?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); } }