Skip to content

Tests: stability tweaks for the non-sniff tests #576

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

Merged
merged 2 commits into from
Jul 27, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 27, 2024

Description

AbstractMethodUnitTest: add "tear down" method to reset static properties

... to prevent changes to the values of these for one test, influencing another test.

This is only a stability tweak, there are no existing tests affected by this issue at this time.

Tests/ConfigDouble: bug fix - always reset Config statics after use

The Config class uses a number of static properties, which may be updated during tests. These were previously - prior to #275 - reset to their default values in the AbstractMethodUnitTest::resetTestFile() method, but this reset was inadvertently removed with the reasoning that, if all tests use the ConfigDouble, the reset would no longer be needed as the ConfigDouble resets on being initialized.

The flaw in this logic is that not all tests are guaranteed to use the ConfigDouble, which means that without the reset, the Config class may be left "dirty" after tests using the ConfigDouble, which could break tests.

This commit fixes this issue by:

  • Adding a __destruct() method to the ConfigDouble class which will reset the static properties on the PHPCS native Config class whenever an object created from this class is destroyed.
  • Explicitly calling the __destruct() method from the AbstractMethodUnitTest::reset() method to ensure it is always run after a test has finished ("after class"), even if there would still be a lingering reference to the object.

This is only a stability tweak, there are no existing tests affected by this issue at this time.

Suggested changelog entry

N/A

jrfnl added 2 commits July 27, 2024 10:44
…ties

... to prevent changes to the values of these for one test, influencing another test.

This is only a stability tweak, there are no existing tests affected by this issue at this time.
The `Config` class uses a number of static properties, which may be updated during tests. These were previously - prior to 275 - reset to their default values in the `AbstractMethodUnitTest::resetTestFile()` method, but this reset was inadvertently removed with the reasoning that, if all tests use the `ConfigDouble`, the reset would no longer be needed as the `ConfigDouble` resets on being initialized.

The flaw in this logic is that not all tests are guaranteed to use the `ConfigDouble`, which means that without the reset, the `Config` class may be left "dirty" after tests using the `ConfigDouble`, which could break tests.

This commit fixes this issue by:
* Adding a `__destruct()` method to the `ConfigDouble` class which will reset the static properties on the PHPCS native `Config` class whenever an object created from this class is destroyed.
* Explicitly calling the `__destruct()` method from the `AbstractMethodUnitTest::reset()` method to ensure it is always run after a test has finished ("after class"), even if there would still be a lingering reference to the object.

This is only a stability tweak, there are no existing tests affected by this issue at this time.
@jrfnl jrfnl added this to the 3.10.x Next milestone Jul 27, 2024
@jrfnl jrfnl merged commit a3d11a9 into master Jul 27, 2024
50 checks passed
@jrfnl jrfnl deleted the feature/configdouble-stabilize branch July 27, 2024 09:41
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.

1 participant