bug #38131 [Validator] allow consumers to mock all methods (xabbuh)
This PR was merged into the 3.4 branch.
Discussion
----------
[Validator] allow consumers to mock all methods
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #38048
| License | MIT
| Doc PR |
Commits
-------
3227303dab
allow consumers to mock all methods
This commit is contained in:
commit
0f704c947d
@ -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;
|
||||
|
Reference in New Issue
Block a user