From 0d0f92b7c60ae9a97099e025a1e15480f792b3f1 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 18 Sep 2020 19:32:30 +0200 Subject: [PATCH] stop using the deprecated at() PHPUnit matcher --- src/Symfony/Component/Form/composer.json | 2 +- .../Test/ConstraintValidatorTestCase.php | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Form/composer.json b/src/Symfony/Component/Form/composer.json index 0c69794b4e..03ba22716a 100644 --- a/src/Symfony/Component/Form/composer.json +++ b/src/Symfony/Component/Form/composer.json @@ -29,7 +29,7 @@ }, "require-dev": { "doctrine/collections": "~1.0", - "symfony/validator": "^4.4|^5.0", + "symfony/validator": "^4.4.12|^5.1.6", "symfony/dependency-injection": "^4.4|^5.0", "symfony/expression-language": "^4.4|^5.0", "symfony/config": "^4.4|^5.0", diff --git a/src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php b/src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php index 7b4972028d..cce35db0dd 100644 --- a/src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php +++ b/src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php @@ -24,6 +24,7 @@ use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationInterface; +use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\Context\ExecutionContext; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Mapping\ClassMetadata; @@ -56,6 +57,8 @@ abstract class ConstraintValidatorTestCase extends TestCase protected $propertyPath; protected $constraint; protected $defaultTimezone; + private $expectedViolations; + private $call; protected function setUp(): void { @@ -74,6 +77,9 @@ abstract class ConstraintValidatorTestCase extends TestCase $this->validator = $this->createValidator(); $this->validator->initialize($this->context); + $this->expectedViolations = []; + $this->call = 0; + \Locale::setDefault('en'); $this->setDefaultTimezone('UTC'); @@ -107,6 +113,11 @@ abstract class ConstraintValidatorTestCase extends TestCase $translator = $this->getMockBuilder(TranslatorInterface::class)->getMock(); $translator->expects($this->any())->method('trans')->willReturnArgument(0); $validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock(); + $validator->expects($this->any()) + ->method('validate') + ->willReturnCallback(function () { + return $this->expectedViolations[$this->call++] ?? new ConstraintViolationList(); + }); $context = new ExecutionContext($validator, $this->root, $translator); $context->setGroup($this->group); @@ -260,11 +271,7 @@ abstract class ConstraintValidatorTestCase extends TestCase $validator->initialize($context); $validator->validate($value, $constraint); - $this->context->getValidator() - ->expects($this->at($i)) - ->method('validate') - ->willReturn($context->getViolations()) - ; + $this->expectedViolations[] = $context->getViolations(); return $context->getViolations(); }