-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
$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); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove spaces on an empty line |
||
//Will fill data in $objectToCompare | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would actually just remove this comment |
||
$objectToCompare = $form->getData(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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` | ||
|
@@ -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:: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space after
//
There was a problem hiding this comment.
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).