Skip to content
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

[Form] FormValidator removed code related to removed cascade_validation option #18081

Closed
wants to merge 2 commits into from
Closed

[Form] FormValidator removed code related to removed cascade_validation option #18081

wants to merge 2 commits into from

Conversation

peterrehm
Copy link
Contributor

Q A
Branch 3.0
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #18063
License MIT

@peterrehm
Copy link
Contributor Author

Args, should be merged into 3.0.

@peterrehm
Copy link
Contributor Author

I see some tests are failing, but only with some deps versions. Does anyone have a hint in this regards?

@sustmi
Copy link
Contributor

sustmi commented Mar 9, 2016

I would rename:

testDontValidateIfParentWithoutCascadeValidation
to testDontValidateIfChildWithoutValidConstraint
because there is another test testValidateIfChildWithValidConstraint testing the opposite.

and testValidateConstraintsEvenIfNoCascadeValidation
to testValidateChildConstraintsEvenWithoutValidConstraint.

@peterrehm
Copy link
Contributor Author

Updated, just the PHP 7 test with the low deps fails, is this maybe due to subtree split or so?

@@ -149,11 +127,11 @@ public function testValidateIfChildWithValidConstraint()
$this->assertNoViolation();
}

public function testDontValidateIfParentWithoutCascadeValidation()
public function testDontValidateIfParentWithoutValidConstraint()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need these tests? Don't they duplicate other tests here?

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 am not sure, I thought it might be intended as it looks like the test for an explizit cascade without the option/constraint.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd appreciate if you could check the other test cases whether any of them duplicates this one. If that's the case, we can safely remove this. This was mainly designed in order to test the special treatment of the cascade_validation option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my understanding it looks like it is not duplicated as we have the related tests

  • testValidateConstraintsEvenIfNoValidConstraint
  • testValidateIfChildWithValidConstraint
  • testDontValidateIfParentWithoutValidConstraint

Copy link
Contributor

Choose a reason for hiding this comment

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

Let me phrase this another way: Is there any way to make these two tests fail (individually) without making at least one other test in this test class fail at the same time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems so, but I am actually a bit confused about the difference of testValidateConstraintsEvenIfNoValidConstraint and testDontValidateIfParentWithoutValidConstraint as it looks like in the first tests constraints in the child are validated even when there is no Valid constraint.

Copy link
Contributor

Choose a reason for hiding this comment

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

@peterrehm I guess the naming of the tests is confusing. We have two different cases:

  • the constraints option: Constraints set in this option are always validated (given their groups match).
  • the Valid constraint: This constraint (either set in the validation metadata - e.g. as annotation - or in the constraints option) results in the constraints defined ine the metadata of the data being validated.

Example:

// data_class = Customer

$form->add('address', FormType::class);
$form->get('address')->add('street', TextType::class, [
    'constraints' => new NotBlank(),
]);

class Customer
{
    private $address;
}

class Address
{
    /**
     * @Length(min=3)
     */
    private $street;
}

In this example, by default only the NotBlank constraint is validated. The constraints defined in the Address class, however, are not validated:

  • There is no Valid constraint in the constraints option of the address field in the form.
  • There is no Valid constraint on the Customer::$address property.

If you add the Valid constraint in either of these places, the Length constraint is validated as well.

We could clarify the tests for example by renaming testValidateConstraintsEvenIfNoValidConstraint to testValidateConstraintsOptionEvenIfParentWithoutValidConstraint etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks better! Could you name the three tests for the Valid constraint consistently?

  • testValidateChildIfValidConstraint
  • testDontValidateChildIfNoValidConstraint
  • testValidateConstraintsOptionEvenIfNoValidConstraint

@peterrehm
Copy link
Contributor Author

Any further feedback?

@Tobion
Copy link
Member

Tobion commented Mar 19, 2016

👍 to be merged in 3.0

Status: Reviewed

@sustmi
Copy link
Contributor

sustmi commented Mar 19, 2016

After re-reading the tests I came to the following conclusions:

testValidateConstraintsEvenIfNoValidConstraint (originally testValidateConstraintsEvenIfNoCascadeValidation) tests that child form data is validated by constraints defined in the child form even if the child form has no @Valid constraint.
I would rename the test to testChildFormDataAreValidatedByFormConstraintsEvenWithoutValidConstraint.

testValidateIfChildWithValidConstraint tests that child form data is validated if the child form has @Valid constraint.
I am not sure if the test makes sense since (as you can see in previous test) constraints defined on subforms are by default always validated (because form's children property has always constraint @Valid; see https://github.com/symfony/symfony/blob/3.0/src/Symfony/Component/Form/Resources/config/validation.xml).
We could rename the test to: testChildFormDataAreValidatedByFormConstraintsIfValidConstraint, but I am not sure if the test makes sense. Also I think that the test should assert that some other constraints are validated too, not just the @Valid.

testDontValidateIfParentWithoutValidConstraint (originally testDontValidateIfParentWithoutCascadeValidation) tests that no validation is run on child form data when it has no constraints.
I would rename the test to testChildFormDataAreNotValidatedByFormConstraintsIfNoConstraints. And I guess this test makes sense only as a sanity check.

EDIT: Added byFormConstraints into the new test names as there is a difference between validating form data by constraints defined in form and constraints defined on the class of the form data object.

@peterrehm
Copy link
Contributor Author

@webmozart Updated.

@webmozart
Copy link
Contributor

👍 apart from my last remark

@peterrehm
Copy link
Contributor Author

@webmozart: Updated, I hope it is as per your request.

@xabbuh
Copy link
Member

xabbuh commented Apr 4, 2016

Looks like you need to fix the tests:

Fatal error: Cannot redeclare Symfony\Component\Form\Tests\Extension\Validator\Constraints\FormValidatorTest::testValidateConstraintsOptionEvenIfNoValidConstraint() in /home/travis/build/symfony/symfony/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php on line 165

PHP Fatal error:  Cannot redeclare Symfony\Component\Form\Tests\Extension\Validator\Constraints\FormValidatorTest::testValidateConstraintsOptionEvenIfNoValidConstraint() in /home/travis/build/symfony/symfony/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php on line 165

@peterrehm
Copy link
Contributor Author

Updated.

@fabpot
Copy link
Member

fabpot commented Apr 7, 2016

Thank you @peterrehm.

fabpot added a commit that referenced this pull request Apr 7, 2016
…ade_validation` option (peterrehm)

This PR was submitted for the master branch but it was merged into the 3.0 branch instead (closes #18081).

Discussion
----------

[Form] FormValidator removed code related to removed `cascade_validation` option

| Q             | A
| ------------- | ---
| Branch        | 3.0
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18063
| License       | MIT

Commits
-------

05fe6f9 [Form] FormValidator removed code related to removed  option
@fabpot fabpot closed this Apr 7, 2016
@fabpot fabpot mentioned this pull request May 3, 2016
@peterrehm peterrehm deleted the cascade-validation branch May 24, 2016 06:56
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.

None yet

8 participants