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

✨ New PHPCSUtils\TestUtils\ConfigDouble class #550

Merged
merged 2 commits into from
May 20, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jan 15, 2024

New PHPCSUtils\TestUtils\ConfigDouble class

The PHP_CodeSniffer native Config class contains a number of static properties.
As the value of these static properties will be retained between instantiations of the class, config values set in one test can influence the results for another test, which makes tests unstable.

This commit introduces a test "double" of the Config class which prevents this from happening.
In most cases, tests should be using this class instead of the "normal" Config, with the exception of select tests for the PHPCS Config class itself.

Includes tests covering the new class.

UtilityMethodTestCase: implement use of the new PHPCSUtils\TestUtils\ConfigDouble class

Start using the new ConfigDouble class in the UtilityMethodTestCase class.

Note: this includes deprecating the UtilityMethodTestCase::setStaticConfigProperty() method, which was introduced, but not publicized, in PHPCSUtils 1.0.9 in favour of handling the same in the ConfigDouble class.

@jrfnl jrfnl added this to the 1.1.0 milestone Jan 15, 2024
@jrfnl jrfnl force-pushed the testutils/new-configdouble-utility-class branch 4 times, most recently from 0598162 to 170ec3d Compare January 15, 2024 06:26
@jrfnl jrfnl force-pushed the testutils/new-configdouble-utility-class branch 2 times, most recently from 283214b to 816e5ae Compare March 18, 2024 01:27
@jrfnl jrfnl force-pushed the testutils/new-configdouble-utility-class branch 3 times, most recently from b7c5c55 to f488a53 Compare May 12, 2024 07:15
@jrfnl jrfnl force-pushed the testutils/new-configdouble-utility-class branch 2 times, most recently from a675d0d to c61fa32 Compare May 13, 2024 11:30
jrfnl added 2 commits May 20, 2024 16:04
The PHP_CodeSniffer native `Config` class contains a number of static properties.
As the value of these static properties will be retained between instantiations of the class, config values set in one test can influence the results for another test, which makes tests unstable.

This commit introduces a test "double" of the `Config` class which prevents this from happening.
In _most_ cases, tests should be using this class instead of the "normal" Config, with the exception of select tests for the PHPCS Config class itself.

Includes tests covering the new class.
…\ConfigDouble` class

Start using the new `ConfigDouble` class in the `UtilityMethodTestCase` class.

Note: this includes deprecating the `UtilityMethodTestCase::setStaticConfigProperty()` method, which was introduced, but not publicized, in PHPCSUtils 1.0.9 in favour of handling the same in the `ConfigDouble` class.
@jrfnl jrfnl force-pushed the testutils/new-configdouble-utility-class branch from c61fa32 to 4f0f9a4 Compare May 20, 2024 14:05
@jrfnl
Copy link
Member Author

jrfnl commented May 20, 2024

Rebased without changes, merging.

@jrfnl jrfnl merged commit da8827f into develop May 20, 2024
54 checks passed
@jrfnl jrfnl deleted the testutils/new-configdouble-utility-class branch May 20, 2024 17:55
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

1 participant