From 3227303dab98b04a2797df8184fd018200534050 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 9 Sep 2020 18:58:25 +0200 Subject: [PATCH 1/2] allow consumers to mock all methods --- .../Test/ConstraintValidatorTestCase.php | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php b/src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php index 3d1fc81c9a..1b4a151826 100644 --- a/src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php +++ b/src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php @@ -112,10 +112,44 @@ abstract class ConstraintValidatorTestCase extends TestCase $context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath); $context->setConstraint($this->constraint); + $contextualValidator = $this->getMockBuilder(AssertingContextualValidator::class) + ->setMethods([ + 'atPath', + 'validate', + 'validateProperty', + 'validatePropertyValue', + 'getViolations', + ]) + ->getMock(); + $contextualValidator->expects($this->any()) + ->method('atPath') + ->willReturnCallback(function ($path) use ($contextualValidator) { + return $contextualValidator->doAtPath($path); + }); + $contextualValidator->expects($this->any()) + ->method('validate') + ->willReturnCallback(function ($value, $constraints = null, $groups = null) use ($contextualValidator) { + return $contextualValidator->doValidate($value, $constraints, $groups); + }); + $contextualValidator->expects($this->any()) + ->method('validateProperty') + ->willReturnCallback(function ($object, $propertyName, $groups = null) use ($contextualValidator) { + return $contextualValidator->validateProperty($object, $propertyName, $groups); + }); + $contextualValidator->expects($this->any()) + ->method('validatePropertyValue') + ->willReturnCallback(function ($objectOrClass, $propertyName, $value, $groups = null) use ($contextualValidator) { + return $contextualValidator->doValidatePropertyValue($objectOrClass, $propertyName, $value, $groups); + }); + $contextualValidator->expects($this->any()) + ->method('getViolations') + ->willReturnCallback(function () use ($contextualValidator) { + return $contextualValidator->doGetViolations(); + }); $validator->expects($this->any()) ->method('inContext') ->with($context) - ->willReturn($this->getMockBuilder(AssertingContextualValidator::class)->setMethods(null)->getMock()); + ->willReturn($contextualValidator); return $context; } @@ -353,6 +387,10 @@ class AssertingContextualValidator implements ContextualValidatorInterface private $expectedValidate = []; public function atPath($path) + { + } + + public function doAtPath($path) { Assert::assertFalse($this->expectNoValidate, 'No validation calls have been expected.'); @@ -366,6 +404,10 @@ class AssertingContextualValidator implements ContextualValidatorInterface } public function validate($value, $constraints = null, $groups = null) + { + } + + public function doValidate($value, $constraints = null, $groups = null) { Assert::assertFalse($this->expectNoValidate, 'No validation calls have been expected.'); @@ -379,11 +421,19 @@ class AssertingContextualValidator implements ContextualValidatorInterface } public function validateProperty($object, $propertyName, $groups = null) + { + } + + public function doValidateProperty($object, $propertyName, $groups = null) { return $this; } public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = null) + { + } + + public function doValidatePropertyValue($objectOrClass, $propertyName, $value, $groups = null) { return $this; } @@ -392,6 +442,10 @@ class AssertingContextualValidator implements ContextualValidatorInterface { } + public function doGetViolations() + { + } + public function expectNoValidate() { $this->expectNoValidate = true; From e927c7cf691654b2b9afb3c18326383790b3247f Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 11 Sep 2020 11:15:40 +0200 Subject: [PATCH 2/2] add mising sr (latn & cyrl) translations --- .../translations/validators.sr_Cyrl.xlf | 20 +++++++++++++++++++ .../translations/validators.sr_Latn.xlf | 20 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.sr_Cyrl.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.sr_Cyrl.xlf index 3f2b9eaba8..fce95a0769 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.sr_Cyrl.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.sr_Cyrl.xlf @@ -366,6 +366,26 @@ This value should be between {{ min }} and {{ max }}. Ова вредност треба да буде између {{ min }} и {{ max }}. + + This value is not a valid hostname. + Ова вредност није исправно име послужитеља (hostname). + + + The number of elements in this collection should be a multiple of {{ compared_value }}. + Број елемената у овој колекцији би требало да буде дељив са {{ compared_value }}. + + + This value should satisfy at least one of the following constraints: + Ова вредност би требало да задовољава најмање једно од наредних ограничења: + + + Each element of this collection should satisfy its own set of constraints. + Сваки елемент ове колекције би требало да задовољи сопствени скуп ограничења. + + + This value is not a valid International Securities Identification Number (ISIN). + Ова вредност није исправна међународна идентификациона ознака хартија од вредности (ISIN). + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf index 43d2070ab7..06b164be8a 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.sr_Latn.xlf @@ -366,6 +366,26 @@ This value should be between {{ min }} and {{ max }}. Ova vrednost treba da bude između {{ min }} i {{ max }}. + + This value is not a valid hostname. + Ova vrednost nije ispravno ime poslužitelja (hostname). + + + The number of elements in this collection should be a multiple of {{ compared_value }}. + Broj elemenata u ovoj kolekciji bi trebalo da bude deljiv sa {{ compared_value }}. + + + This value should satisfy at least one of the following constraints: + Ova vrednost bi trebalo da zadovoljava namjanje jedno od narednih ograničenja: + + + Each element of this collection should satisfy its own set of constraints. + Svaki element ove kolekcije bi trebalo da zadovolji sopstveni skup ograničenja. + + + This value is not a valid International Securities Identification Number (ISIN). + Ova vrednost nije ispravna međunarodna identifikaciona oznaka hartija od vrednosti (ISIN). +