8000 OptionsResolver test coverage by eventhorizonpl · Pull Request #16446 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

OptionsResolver test coverage #16446

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 7 commits into from
Closed

OptionsResolver test coverage #16446

wants to merge 7 commits into from

Conversation

eventhorizonpl
Copy link

Hi,

This PR adds 100% test code coverage to OptionsResolver component.

Best regards,
Michal

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

@Tobion
Copy link
Contributor
Tobion commented Nov 3, 2015
  1. it should not be done with the LegacyOptionsResolverTest but the real one
  2. private methods should not be tested with reflection but through the public api

@eventhorizonpl
Copy link
Author

@Tobion

I introduced the changes you wanted. I have very mixed feelings about the principle number 2. I know that it's good for most cases but sometimes some parts of code are harder to test. I don't see anything wrong with using reflections in such cases. Can this be discussed?

Thanks for review.

@fabpot
Copy link
Member
fabpot commented Nov 4, 2015

I agree with @Tobion, private methods encapsulate logic as black boxes. We need to test them via the regular public API developers are going to use.

@Tobion
Copy link
Contributor
Tobion commented Nov 4, 2015

@eventhorizonpl I don't see the true case (https://github.com/eventhorizonpl/symfony/blob/options_resolver_test_coverage/src/Symfony/Component/OptionsResolver/OptionsResolver.php#L1192) being used in the OptionsResolver2Dot6Test. Are you sure it's 100% tests coverage with only the new test class?

@eventhorizonpl
Copy link
Author

@Tobion

true case is covered by testResolveFailsIfValueAllowedCallbackReturnsFalse according to a report.

scren

@Tobion
Copy link
Contributor
Tobion commented Nov 4, 2015

@eventhorizonpl testResolveFailsIfValueAllowedCallbackReturnsFalse is only in the legacy test suite. So in master, where the legacy is removed, there would not be 100% test coverage anymore.

$this->resolver->setDefined('option');
$this->resolver->setAllowedTypes('option', 'string');

$this->resolver->resolve(array('option' => []));
Copy link
Member

Choose a reason for hiding this comment

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

please keep the code compatible with PHP 5.3 (this is why Travis is failing)

@Tobion
Copy link
Contributor
Tobion commented Nov 6, 2015

@eventhorizonpl can you please rewrite the tests to use a dataProvider. This provider (actual type, allowed type, exception message) would then also cover all the other types (from testResolveFailsIfInvalidType, testResolveFailsIfInvalidTypeIsNull, testResolveFailsIfNotInstanceOfClass). This way there is much less repitition.
And you could also do a similar approach to test that passing the correct type succeeds for each type (testResolveSucceedsIfValidType etc.).

@eventhorizonpl
Copy link
Author

@Tobion

I added dataProvider for my tests and testResolveFailsIfInvalidType, testResolveFailsIfInvalidTypeIsNull, testResolveFailsIfNotInstanceOfClass.

I didn't changed testResolveSucceedsIfValidType* because my current goal is not to fix all tests. Right now i 8000 t's just about covering code.

* @dataProvider getFormatValueData
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testFormatValue($actualType, $allowedType, $exceptionMessage)
Copy link
Contributor

Choose a reason for hiding this comment

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

please name this test testResolveFailsIfInvalidType and at the same lines of the old tests (line 505). this makes merging easier.

@@ -499,27 +499,29 @@ public function testFailIfSetAllowedTypesFromLazyOption()
}

/**
* @dataProvider provideInvalidTypes
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
Copy link
Contributor

Choose a reason for hiding this comment

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

must be removed

@Tobion
Copy link
Contributor
Tobion commented Nov 12, 2015

Thank you @eventhorizonpl.

Tobion added a commit that referenced this pull request Nov 12, 2015
This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #16446).

Discussion
----------

OptionsResolver test coverage

Hi,

This PR adds 100% test code coverage to OptionsResolver component.

Best regards,
Michal

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Commits
-------

185950c OptionsResolver test coverage
@Tobion Tobion closed this Nov 12, 2015
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.

6 participants
0