Server IP : 66.29.132.122 / Your IP : 18.222.117.211 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\Constraint; use Symfony\Component\Validator\Constraints\AbstractComparisonValidator; class ComparisonTest_Class { protected $value; public function __construct($value) { $this->value = $value; } public function __toString() { return (string) $this->value; } } /** * @author Daniel Holmes <daniel@danielholmes.org> */ abstract class AbstractComparisonValidatorTestCase extends \PHPUnit_Framework_TestCase { private $validator; private $context; protected function setUp() { $this->validator = $this->createValidator(); $this->context = $this->getMockBuilder('Symfony\Component\Validator\ExecutionContext') ->disableOriginalConstructor() ->getMock(); $this->validator->initialize($this->context); } /** * @return AbstractComparisonValidator */ abstract protected function createValidator(); public function testThrowsConstraintExceptionIfNoValueOrProperty() { $this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException'); $comparison = $this->createConstraint(array()); $this->validator->validate('some value', $comparison); } /** * @dataProvider provideValidComparisons * @param mixed $dirtyValue * @param mixed $comparisonValue */ public function testValidComparisonToValue($dirtyValue, $comparisonValue) { $this->context->expects($this->never()) ->method('addViolation'); $constraint = $this->createConstraint(array('value' => $comparisonValue)); $this->context->expects($this->any()) ->method('getPropertyPath') ->will($this->returnValue('property1')); $this->validator->validate($dirtyValue, $constraint); } /** * @return array */ abstract public function provideValidComparisons(); /** * @dataProvider provideInvalidComparisons * @param mixed $dirtyValue * @param mixed $comparedValue * @param mixed $comparedValueString * @param string $comparedValueType */ public function testInvalidComparisonToValue($dirtyValue, $comparedValue, $comparedValueString, $comparedValueType) { $constraint = $this->createConstraint(array('value' => $comparedValue)); $constraint->message = 'Constraint Message'; $this->context->expects($this->any()) ->method('getPropertyPath') ->will($this->returnValue('property1')); $this->context->expects($this->once()) ->method('addViolation') ->with('Constraint Message', array( '{{ value }}' => $comparedValueString, '{{ compared_value }}' => $comparedValueString, '{{ compared_value_type }}' => $comparedValueType )); $this->validator->validate($dirtyValue, $constraint); } /** * @return array */ abstract public function provideInvalidComparisons(); /** * @param array $options Options for the constraint * @return Constraint */ abstract protected function createConstraint(array $options); }