Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ecef1fc

Browse filesBrowse files
ismail1432javiereguiluz
authored andcommitted
Add a 2nd argument to create()
1 parent e37d7e3 commit ecef1fc
Copy full SHA for ecef1fc

File tree

Expand file treeCollapse file tree

1 file changed

+7
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-6
lines changed

‎form/unit_testing.rst

Copy file name to clipboardExpand all lines: form/unit_testing.rst
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,19 @@ The simplest ``TypeTestCase`` implementation looks like the following::
5252
'test2' => 'test2',
5353
);
5454

55-
$type = new TestedType();
56-
$form = $this->factory->create($type);
55+
$objectToCompare = new TestObject();
56+
// $objectToCompare will retrieve data from the form submission; pass it as the second argument
57+
$form = $this->factory->create(TestedType::class, $objectToCompare);
5758

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

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

65+
$objectToCompare = $form->getData();
6466
$this->assertTrue($form->isSynchronized());
65-
$this->assertEquals($object, $form->getData());
67+
$this->assertEquals($object, $objectToCompare);
6668

6769
$view = $form->createView();
6870
$children = $view->children;
@@ -79,8 +81,7 @@ First you verify if the ``FormType`` compiles. This includes basic class
7981
inheritance, the ``buildForm()`` function and options resolution. This should
8082
be the first test you write::
8183

82-
$type = new TestedType();
83-
$form = $this->factory->create($type);
84+
$form = $this->factory->create(TestedType::class, $objectToCompare);
8485

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

101-
$this->assertEquals($object, $form->getData());
102+
$this->assertEquals($object, $objectToCompare);
102103

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.