-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Error FormTypeTest : Call to a member function addConstraint() on null #20952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@GCalmels I think that's an issue with the example provided in the documentation, but not related to the Symfony code. Can open a new issue on the docs repository? |
Well, do you know the valid example? Yes, I will open a new issue! |
The mocked |
I post the solution I found : protected function getExtensions()
{
$this->validator = $this->createMock(ValidatorInterface::class);
$this->validator
->method('validate')
->will($this->returnValue(new ConstraintViolationList()));
$this->validator
->method('getMetadataFor')
->will($this->returnValue(new ClassMetadata('Symfony\Component\Form\Form')));
return array(
new ValidatorExtension($this->validator)
);
} |
@GCalmels Thank you! Can you please also add this as a comment to symfony/symfony-docs#7270. |
This PR was merged into the 2.7 branch. Discussion ---------- added missing ClassMetadata This needs to be merged into the following branches too Closes #7270 Refs symfony/symfony#20952 Commits ------- c193035 added missing ClassMetadata
I followed the doc for adding custom extensions and I had an error at
new ValidatorExtension($this->validator),
The cause of this error is on the
_construct
of ValidatorExtension.php :$metadata = $validator->getMetadataFor('Symfony\Component\Form\Form');
and after :
$metadata->addConstraint(new Form());
but $metadata is nullThe text was updated successfully, but these errors were encountered: