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

finish #13598 #18047

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

finish #13598 #18047

wants to merge 2 commits into from

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Mar 7, 2016

Q A
Branch 2.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #13598
License MIT
Doc PR

… it throws a TransformationFailedException with message: 'Expected a string.'.
@xabbuh
Copy link
Member Author

xabbuh commented Mar 7, 2016

@HeahDude
Copy link
Contributor

HeahDude commented Mar 7, 2016

The tests are still skipped, even with #18019 :(

@xabbuh
Copy link
Member Author

xabbuh commented Mar 7, 2016

At least, on AppVeyor they are executed and pass.

@HeahDude
Copy link
Contributor

HeahDude commented Mar 7, 2016

Great! Do they fail without the fix too ? never mind, just read your comment in the previous PR.

@xabbuh
Copy link
Member Author

xabbuh commented Mar 7, 2016

@xabbuh xabbuh force-pushed the pr-13598 branch 2 times, most recently from 3006020 to aa5e45b Compare March 7, 2016 13:54

public function testSubmitNullWithEmptyDataTrueWhenNested()
{
$form = $this->factory->create('form')
Copy link
Contributor

Choose a reason for hiding this comment

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

Do the tests pass (before the change) if this is not nested? If not, I'd simplify this test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Neither this one nor testSubmitNullWithEmptyData(which is the same without nesting) do pass without the change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, actually @webmozart is right.

You can remove "WhenNested" is the method name and refractor this to:

$form = $this->factory->create('checkbox', null, array(
                 'empty_data' => true,
             ));

$form->submit(null);

$this->assertTrue($form->getData());
$this->assertSame('1', $form->getViewData());

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh okay, got it now what you were talking about. I changed the CheckboxType tests to not use nested forms and removed the nested test from the IntegerTypeTest where it also wasn't necessary.

@HeahDude
Copy link
Contributor

HeahDude commented Mar 7, 2016

Also, I confirm I still cannot close #17822 in favor of this one. It remains a singular case.

@HeahDude
Copy link
Contributor

HeahDude commented Mar 7, 2016

👍

Status: Reviewed

public function testSubmitNullWithEmptyDataTrue()
{
$form = $this->factory->create('checkbox', null, array(
'empty_data' => true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, this code is invalid. empty_data expects data in view format, not in model format. The view format depends on the transformer that is used.

Imagine the field is configured with the following transformer

true <---> 'yes'
false <---> 'no'

Then this code will fail. The empty_data value true will be cast to the string '1'. Consequently, the transformer fails, since it doesn't know how to reverse transform '1'.

The correct test would be:

$form = $this->factory->create('checkbox', null, array(
    'empty_data' => '1',
));

I understand this is not very straight-forward nor intuitive, but we can't change that for the moment.

I believe that the use case that motivated this change was actually using the empty_data incorrectly, by passing data in model instead of view format (ping @guilhermeblanco).

Copy link
Contributor

Choose a reason for hiding this comment

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

But it's valid with default settings, right ?

In that test $this->assertSame('1', $viewData) would pass.

@guilhermeblanco
Copy link
Contributor

@xabbuh @webmozart my case was explicitly with integer types, not checkboxes (which are boolean values).

@HeahDude
Copy link
Contributor

HeahDude commented Mar 8, 2016

@guilhermeblanco Fortunately your fix solves both :) Thanks.

@webmozart
Copy link
Contributor

@guilhermeblanco Did you pass integers or strings (integer strings) to empty_data?

@webmozart
Copy link
Contributor

See symfony/symfony-docs#6340

@xabbuh
Copy link
Member Author

xabbuh commented Mar 10, 2016

I guess we can close here. Changing the test to use the string 1 instead of the integer makes the test pass even without the fix.

Thanks for raising the issue on the docs repo @webmozart. This is indeed something that we have to improve (I didn't know that before).

@HeahDude
Copy link
Contributor

Agreed, I guess we all learned something with this one.

@xabbuh I could deal with in symfony/symfony-docs#6265, what do you think ?

@xabbuh
Copy link
Member Author

xabbuh commented Mar 10, 2016

@HeahDude 👍

@guilhermeblanco
Copy link
Contributor

OMG... Using string as workaround was detailed in the original ticket that it worked. However, that's not a solution. If you declare an integer field, you expect an integer back, not a string.

@xabbuh
Copy link
Member Author

xabbuh commented Mar 11, 2016

@guilhermeblanco Sorry for the inconvenience. Though it turns out that using a string is not a workaround but the right solution as this is how the view data for the integer type look like.

@webmozart
Copy link
Contributor

@guilhermeblanco I agree with you. Unfortunately we can't change that for the moment due to BC implications.

@webmozart webmozart closed this Mar 14, 2016
@xabbuh xabbuh deleted the pr-13598 branch March 14, 2016 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.