Skip to content

A cookbook article on how to test forms #2012

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

Merged
merged 3 commits into from
Feb 24, 2013
Merged

A cookbook article on how to test forms #2012

merged 3 commits into from
Feb 24, 2013

Conversation

marekkalnik
Copy link
Contributor

As requested by @johnkary a Cookbook version of my article from Theodo Blog (http://www.theodo.fr/blog/2012/11/symfony-testing-patterns-forms/).

This is my first Cookbook article so all feedback is very much welcome!

=============

The form component itself consists of 3 core objects: the FormType, the
Form and the FormView.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should create links to the API documentation for objects as described in the documentation: http://symfony.com/doc/current/contributing/documentation/format.html#adding-links

@marekkalnik
Copy link
Contributor Author

Thanks for the comments @wouterj. I've updated the article according to them.

Testing forms
=============

The form component itself consists of 3 core objects: a FormType (extending
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove itself

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A uppercase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the uppercase?

@marekkalnik
Copy link
Contributor Author

Thanks @cordoval! I've updated the text according to your comments. IMHO the A in "The form component consists of 3 core objects: a FormType, the Form and the FormView" should stay in lowercase so I didn't change it.

=============

The form component consists of 3 core objects: a FormType (extending
:class:`Symfony\\Component\\Form\\AbstractType`), the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you don't need to extend from AbstractType, only to implement the FormTypeInterface. Extending from AbstractType is only a way to avoid redefining empty methods each time when you don't need to customize all of them

@cordoval
Copy link
Contributor

cordoval commented Dec 8, 2012

good job 👍 👍

Testing forms
=============

The form component consists of 3 core objects: a FormType (extending
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dad always said after a colon always upper case

the same as mama always said flush after creating an object

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to capitialize form component (it should become The Form Component)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cordoval maybe it's because I'm not a native English speaker, but I've never heard of this rule. Could you provide any grammar resource that discusses it? If it's right, we should also correct the rest of the documentation, there are many entries where it is not respected.

@marekkalnik
Copy link
Contributor Author

I've pushed some updates. I guess the changes will be easier to follow if I'll keep doing commits and then squash it when it's ready to merge.

$form = $this->factory->create($type);

$object = new TestObject();
$object->fromArray($formData)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing semi-colon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@weaverryan weaverryan merged commit 5e97d69 into symfony:2.1 Feb 24, 2013
@weaverryan
Copy link
Member

Hi Marek!

Sorry for the delay on this - it's a very very nice entry - I think you could learn a lot about forms in general by reading it. I've merged this into the 2.1 branch and made a few minor changes at sha: Marek

Thanks!

@marekkalnik
Copy link
Contributor Author

Hi Ryan!

That's some great news, I've already thought the article didn't have enough of support to be merged. Thank you very much!

@wouterj
Copy link
Member

wouterj commented Feb 25, 2013

I have created an issue about moving those test classes to their own namespace. It will be done in 2.3, meaning that we need to monitor that issue and change this article when it is merged.

@wouterj
Copy link
Member

wouterj commented Apr 13, 2013

@weaverryan is there any reason why this isn't merged into the 2.0 branch?

@marekkalnik
Copy link
Contributor Author

@wouterj The article is not Symfony2.0 compilant. I don't remember the exact reasons, but I uses some SF2.1 functionalities. IMHO, the 2.0 is not supported anyway, so it's not worth adapting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants