-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Unit testing FormType with constructor #6053
Comments
The article you reference indeed needs an update. In case the form type doesn't have dependencies, you would pass the fully-qualified class name instead of an instance. If your form type has dependencies, the solution you proposed seems to be correct. I don't like it that much either... @webmozart do you have an alternative or an idea how we can improve testing form types with dependencies? |
There is something I'm missing with the above example, as it still errors, and I the form type isn't in FormRegistry. |
You were on a good path already. Something like this should work: protected function setUp()
{
$this->user = $this->getMock(UserInterface::class);
parent::setUp();
}
protected function getExtensions()
{
return array(
new PreloadedExtension(array(
new TicketMessageType($this->user)
)),
);
}
public function testFoobar()
{
$form = $this->factory->create(TicketMessageType::class);
// ...
} |
…(WouterJ) This PR was merged into the 2.8 branch. Discussion ---------- Update Testing Form Types article for 2.8 refactorings | Q | A | --- | --- | Doc fix? | yes | New docs? | yes | Applies to | 2.8+ | Fixed tickets | #6053 Commits ------- 906d55a Update Testing Form Types article for 2.8 refactorings
This code used to work in Symfony <= 2.7
However in Symfony 3.0, the following error is thrown.
The functionality was changed in this commit. There doesn't seem to be any mention of the above, in any change logs, only that getName was deprecated.
[Form] removed deprecated FormType::getName()
I've been on the hunt for documentation that explains how to do this.
In How to Unit Test your Forms (3.0), the following code appears, but I can't see how it'd work.
Whereas it should be passed in as a string.
Though I'm still confused as to how you're supposed to do the above when your type has a constructor.
Closest I have found seems to be:
The text was updated successfully, but these errors were encountered: