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

Tests/Ruleset: introduce an abstract base TestCase and start using it #702

Merged
merged 2 commits into from
Nov 22, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 21, 2024

Description

Tests/Ruleset: introduce an abstract base TestCase

Introduce an abstract base TestCase with some helper methods specifically for tests testing aspects of the Ruleset class.

Tests/Ruleset: start using the new AbstractRulesetTestCase

Start using the new AbstractRulesetTestCase in pre-existing Ruleset tests.

Suggested changelog entry

N/A

Related issues/external references

This is a preliminary PR for a series of PRs expanding the tests for the Ruleset class.

Copy link
Contributor

@rodrigoprimo rodrigoprimo left a comment

Choose a reason for hiding this comment

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

LGTM!

I just have one question that is not a blocker. Instead of creating an abstract base class for the ruleset tests, have you considered creating a more generic abstract base class that can be used by other tests as well?

I imagine that having those PHPUnit cross-version compatible methods will be useful for other tests. For example, there are already a few places in the PHPCS code base that check whether to use expectException() or setExpectedException():

https://github.com/search?q=repo%3APHPCSStandards%2FPHP_CodeSniffer%20method_exists(%24this%2C%20%27expectException%27)&type=code

There is even AbstractMethodUnitTest::expectRunTimeException():

https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/866f7cf551e49a410581cd50e4e1c44e2e4db2f0/tests/Core/AbstractMethodUnitTest.php#L207C21-L207C43

Introduce an abstract base TestCase with some helper methods specifically for tests testing aspects of the `Ruleset` class.
Start using the new `AbstractRulesetTestCase` in pre-existing `Ruleset` tests.
@jrfnl jrfnl force-pushed the feature/ruleset-tests-baseclass branch from 6911355 to db02f0d Compare November 22, 2024 16:26
@jrfnl
Copy link
Member Author

jrfnl commented Nov 22, 2024

I just have one question that is not a blocker. Instead of creating an abstract base class for the ruleset tests, have you considered creating a more generic abstract base class that can be used by other tests as well?

I imagine that having those PHPUnit cross-version compatible methods will be useful for other tests. For example, there are already a few places in the PHPCS code base that check whether to use expectException() or setExpectedException():

Good question. Originally (while working on this series) this base test case contained some more Ruleset specific methods, which is why I introduced it as a Ruleset specific test case.

On that note, I just noticed the RULESET_CLASS constant declaration, which is a left-over of that earlier iteration with more Ruleset specific methods. I've just removed that, as it is no longer used in the current version of the class.

I did consider introducing a more generic TestCase for the Core tests (and am still considering it), but part of the usefulness of that class would be moot once we get to PHPCS 4.0 as support for PHPUnit < 8 has been dropped and the toggle for expecting exceptions is no longer needed.

As most of that work to drop support for PHPUnit < 8 is already in the 4.x branch, it would also make merging a PR which introduced a generic TestCase to existing tests more difficult for the cherrypick to the 4.x branch and would also make future cherrypicks for Core tests to the 4.x branch more difficult.

All in all, I decided that introducing this TestCase (as it currently is) now would be helpful for the task at hand (Ruleset tests) and to evaluate whether it should be moved to be a more generic TestCase at a later point in time. Most likely when working on the 4.x branch recreation.

Does that make sense ?

@jrfnl jrfnl merged commit fa96dd3 into master Nov 22, 2024
70 checks passed
@jrfnl jrfnl deleted the feature/ruleset-tests-baseclass branch November 22, 2024 20:16
@rodrigoprimo
Copy link
Contributor

Does that make sense ?

That makes sense. Thanks for the additional details!

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.

2 participants