stop using the deprecated at() PHPUnit matcher

This commit is contained in:
Christian Flothmann 2020-09-18 19:32:30 +02:00
parent 9610daf1bc
commit 0d0f92b7c6
2 changed files with 13 additions and 6 deletions

View File

@ -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",

View File

@ -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();
}