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

ErrorSuppressionTest: refactor to use data providers + bug fixes for the tests #3335

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented May 8, 2021

Follow up to #3071 (comment)

This refactors all test methods in the ErrorSuppresionTest class to use data providers.

For each of these refactors, the following comment applies:

  • Maintains the exact same existing tests, now using a data provider.
    The data provider uses keys which allows for much more descriptive output when using the PHPUnit --testdox option, as well as for easier debugging if/when a test would fail.
  • Orders the tests in logical groups in the data provider.
  • Switches out assertEquals() (loose type comparison) for assertSame() (strict type comparison).
  • Caches the $config and $ruleset for the test via static local variables to prevent the test run from becoming slower due to the change to the data provider.

Notable (other) commits/commit comments

ErrorSuppressionTest: move one test case out of testSuppressLine()

... as it uses a different code pattern, so doesn't fit with the other tests for the (upcoming) data provider.

ErrorSuppressionTest: add test for midline ignore

ErrorSuppressionTest: fix bug in testSuppressScope()

As the "no suppression" test would yield no errors, the test wasn't actually testing anything as there were no errors to suppress.

Fixed now by using a different sniff to test against, which does yield an error on the line being suppressed by the rest of the tests.

ErrorSuppressionTest::testSuppressFile(): fix bugs in test

This fixes two bugs in two test cases for the testSuppressFile() method:

  1. The code snippet as was, contained a parse error (missing semi-colon after class instantiation).
  2. The code snippet did not contain anything which would trigger the warning the test is looking for in the first place, so these two tests would always pass.

ErrorSuppressionTest::testDisableSelected(): refactor to data provider

Note: the "docblock" tests have changed to use the same basic code sample as the other tests. In practice this means that instead of having 0 errors and 0/1 warnings, they will now yield 1 error and 0/1 warnings. Functionally these tests still test the same principle.

ErrorSuppressionTest::testDisableSelected(): add some more tests

By the looks of it, combining disabling at different levels and disabling error codes wasn't covered in the tests.

jrfnl added 16 commits May 8, 2021 22:00
* Maintains the exact same existing tests, now using a data provider.
    The data provider uses keys which allows for much more descriptive output when using the PHPUnit `--testdox` option, as well as for easier debugging if/when a test would fail.
* Orders the tests in logical groups in the data provider.
* Switches out `assertEquals()` (loose type comparison) for `assertSame()` (strict type comparison).
* Caches the `$config` and `$ruleset` for the test via static local variables to prevent the test run from becoming slower due to the change to the data provider.
…ider

* Maintains the exact same existing tests, now using a data provider.
    The data provider uses keys which allows for much more descriptive output when using the PHPUnit `--testdox` option, as well as for easier debugging if/when a test would fail.
* Orders the tests in logical groups in the data provider.
* Switches out `assertEquals()` (loose type comparison) for `assertSame()` (strict type comparison).
* Caches the `$config` and `$ruleset` for the test via static local variables to prevent the test run from becoming slower due to the change to the data provider.
* Maintains the exact same existing tests, now using a data provider.
    The data provider uses keys which allows for much more descriptive output when using the PHPUnit `--testdox` option, as well as for easier debugging if/when a test would fail.
* Orders the tests in logical groups in the data provider.
* Switches out `assertEquals()` (loose type comparison) for `assertSame()` (strict type comparison).
* Caches the `$config` and `$ruleset` for the test via static local variables to prevent the test run from becoming slower due to the change to the data provider.
... as it uses a different code pattern, so doesn't fit with the other tests for the (upcoming) data provider.
* Maintains the exact same existing tests, now using a data provider.
    The data provider uses keys which allows for much more descriptive output when using the PHPUnit `--testdox` option, as well as for easier debugging if/when a test would fail.
* Orders the tests in logical groups in the data provider.
* Switches out `assertEquals()` (loose type comparison) for `assertSame()` (strict type comparison).
* Caches the `$config` and `$ruleset` for the test via static local variables to prevent the test run from becoming slower due to the change to the data provider.
…ider

* Maintains the exact same existing tests, now using a data provider.
    The data provider uses keys which allows for much more descriptive output when using the PHPUnit `--testdox` option, as well as for easier debugging if/when a test would fail.
* Orders the tests in logical groups in the data provider.
* Switches out `assertEquals()` (loose type comparison) for `assertSame()` (strict type comparison).
* Caches the `$config` and `$ruleset` for the test via static local variables to prevent the test run from becoming slower due to the change to the data provider.
As the "no suppression" test would yield no errors, the test wasn't actually testing anything as there were no errors to suppress.

Fixed now by using a different sniff to test against, which does yield an error on the line being suppressed by the rest of the tests.
* Maintains the exact same existing tests, now using a data provider.
    The data provider uses keys which allows for much more descriptive output when using the PHPUnit `--testdox` option, as well as for easier debugging if/when a test would fail.
* Orders the tests in logical groups in the data provider.
* Switches out `assertEquals()` (loose type comparison) for `assertSame()` (strict type comparison).
* Caches the `$config` and `$ruleset` for the test via static local variables to prevent the test run from becoming slower due to the change to the data provider.
This fixes two bugs in two test cases for the `testSuppressFile()` method:
1. The code snippet as was, contained a parse error (missing semi-colon after class instantiation).
2. The code snippet did not contain anything which would trigger the warning the test is looking for in the first place, so these two tests would always pass.
* Maintains the exact same existing tests, now using a data provider.
    The data provider uses keys which allows for much more descriptive output when using the PHPUnit `--testdox` option, as well as for easier debugging if/when a test would fail.
* Orders the tests in logical groups in the data provider.
* Switches out `assertEquals()` (loose type comparison) for `assertSame()` (strict type comparison).
* Caches the `$config` and `$ruleset` for the test via static local variables to prevent the test run from becoming slower due to the change to the data provider.
**Note**: the "docblock" tests have changed to use the same basic code sample as the other tests. In practice this means that instead of having 0 errors and 0/1 warnings, they will now yield 1 error and 0/1 warnings. Functionally these tests still test the same principle.

* Maintains the exact same existing tests, now using a data provider.
    The data provider uses keys which allows for much more descriptive output when using the PHPUnit `--testdox` option, as well as for easier debugging if/when a test would fail.
* Orders the tests in logical groups in the data provider.
* Switches out `assertEquals()` (loose type comparison) for `assertSame()` (strict type comparison).
* Caches the `$config` and `$ruleset` for the test via static local variables to prevent the test run from becoming slower due to the change to the data provider.
By the looks of it, combining disabling at different levels and disabling error codes wasn't covered in the tests.
* Maintains the exact same existing tests, now using a data provider.
    The data provider uses keys which allows for much more descriptive output when using the PHPUnit `--testdox` option, as well as for easier debugging if/when a test would fail.
* Orders the tests in logical groups in the data provider.
* Switches out `assertEquals()` (loose type comparison) for `assertSame()` (strict type comparison).
* Caches the `$config` and `$ruleset` for the test via static local variables to prevent the test run from becoming slower due to the change to the data provider.
* Maintains the exact same existing tests, now using a data provider.
    The data provider uses keys which allows for much more descriptive output when using the PHPUnit `--testdox` option, as well as for easier debugging if/when a test would fail.
* Orders the tests in logical groups in the data provider.
* Switches out `assertEquals()` (loose type comparison) for `assertSame()` (strict type comparison).
* Caches the `$config` and `$ruleset` for the test via static local variables to prevent the test run from becoming slower due to the change to the data provider.
* Maintains the exact same existing tests, now using a data provider.
    The data provider uses keys which allows for much more descriptive output when using the PHPUnit `--testdox` option, as well as for easier debugging if/when a test would fail.
* Orders the tests in logical groups in the data provider.
* Switches out `assertEquals()` (loose type comparison) for `assertSame()` (strict type comparison).
* Caches the `$config` and `$ruleset` for the test via static local variables to prevent the test run from becoming slower due to the change to the data provider.
@jrfnl jrfnl changed the title ErrorSuppressionTest: refactor to use data providers + test bug fixes ErrorSuppressionTest: refactor to use data providers + bug fixes for the tests May 8, 2021
@gsherwood gsherwood added this to the 3.6.1 milestone May 11, 2021
@gsherwood gsherwood merged commit 07bb757 into squizlabs:master May 27, 2021
@gsherwood
Copy link
Member

Was a fun merge into 4.0 :) I ended up squashing the commits to make it easier, but think I captured all the changes in the commit message. Thanks - so much cleaner.

@jrfnl jrfnl deleted the feature/3071-follow-up-refactor-errorsuppression-tests branch May 27, 2021 11:39
@jrfnl
Copy link
Contributor Author

jrfnl commented May 27, 2021

@gsherwood I imagine so 😂 And yes, the separate commits were only there to allow for easier review of this PR as it's so huge and the review was done for 3.x branch anyhow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants