PHPCSStandards / PHPCSUtils

A suite of utility functions for use with PHP_CodeSniffer
https://phpcsutils.com/
GNU Lesser General Public License v3.0
53 stars 7 forks source link

TestUtils/ConfigDouble: bug fix - always reset Config statics after use #612

Closed jrfnl closed 1 month ago

jrfnl commented 3 months ago

The PHPCS native Config class uses a number of static properties, which may be updated during tests. These were previously reset to their default values in the UtilityMethodTestCase::resetTestFile() method, but this reset was inadvertently removed in commit https://github.com/PHPCSStandards/PHPCSUtils/pull/550/commits/4f0f9a4af04db6a3de28d657d06e707187c0c152 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:

Includes tests for the new __destruct() method. Includes an additional test for the UtilityMethodTestCase class to ensure this snafu cannot come back without tests failing on it.

Props to @fredden for helping me debug this issue.