Skip to content

Add a 2nd argument to create() #9413

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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions form/unit_testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,21 @@ The simplest ``TypeTestCase`` implementation looks like the following::
'test' => 'test',
'test2' => 'test2',
);

$form = $this->factory->create(TestedType::class);


$objectToCompare = new TestObject();
//$objectToCompare will retrieve data from the form submission pass it at second argument
Copy link
Member

Choose a reason for hiding this comment

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

missing space after //

Copy link
Contributor

Choose a reason for hiding this comment

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

and 1 space before //, 1 space before $objectToCompare (the indents are incorrect).

$form = $this->factory->create(TestedType::class, $objectToCompare);

$object = new TestObject();
// ...populate $object properties with the data stored in $formData

// submit the data to the form directly
$form->submit($formData);


Copy link
Contributor

Choose a reason for hiding this comment

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

remove spaces on an empty line

//Will fill data in $objectToCompare
Copy link
Member

Choose a reason for hiding this comment

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

same here

Copy link
Member

Choose a reason for hiding this comment

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

I would actually just remove this comment

$objectToCompare = $form->getData();
Copy link
Member

Choose a reason for hiding this comment

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

I would not introduce this variable here. There is no need for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand but IMO it's strange to declare a variable, pass it as an argument and never use it after.

Copy link
Member

Choose a reason for hiding this comment

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

But now we are doing exactly that because we are overwriting the previously declared variable.

Copy link
Member

Choose a reason for hiding this comment

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

@xabbuh do we need to change anything in the merged PR? If yes, could you please create a quick issue (or PR) to not forget about it? Thanks a lot!

Copy link
Member

Choose a reason for hiding this comment

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

see #9431

$this->assertTrue($form->isSynchronized());
$this->assertEquals($object, $form->getData());
$this->assertEquals($object, $objectToCompare);

$view = $form->createView();
$children = $view->children;
Expand All @@ -73,7 +77,7 @@ First you verify if the ``FormType`` compiles. This includes basic class
inheritance, the ``buildForm()`` function and options resolution. This should
be the first test you write::

$form = $this->factory->create(TestedType::class);
$form = $this->factory->create(TestedType::class, $objectToCompare);

This test checks that none of your data transformers used by the form
failed. The :method:`Symfony\\Component\\Form\\FormInterface::isSynchronized`
Expand All @@ -91,7 +95,7 @@ method is only set to ``false`` if a data transformer throws an exception::
Next, verify the submission and mapping of the form. The test below
checks if all the fields are correctly specified::

$this->assertEquals($object, $form->getData());
$this->assertEquals($object, $objectToCompare);

Finally, check the creation of the ``FormView``. You should check if all
widgets you want to display are available in the children property::
Expand Down