Skip to content

Commit ca10641

Browse files
committed
Tests: refactor the test framework
As things were, the test framework used a setup with custom test suites, which was based on PHPUnit 2/3 and only still worked by accident, not by design. This type of setup was deprecated in PHPUnit 4 and support has been removed completely in PHPUnit 10. This commit updates the test framework to start using the test suite setup via the PHPUnit config file instead and removes all classes related to the custom test suite setup. Notes: * As all test suites are now declared in the PHPUnit config file, the tests can now be run by just calling `phpunit`. No need to explicitly pass the `tests/AllTests.php` file anymore. * As part of the test suite setup, all files needed by the tests were preloaded and the autoloader was removed once the test suites had been set up. This looks to have been designed like this originally to allow for the tests to be run in a PEAR setup. Various global variables were used in this process and referred to in the test cases. Those global variables are now no longer declared and all uses of these have been removed. * The aforementioned preloading previously could cause issues when running tests for external standards and/or when running the tests for PHPCS itself when various external standards were registered in `installed_paths`. To work around this, PR squizlabs/PHP_CodeSniffer 1146 introduced a `PHPCS_IGNORE_TESTS` environment variable to explicitly ignore other standards than the one(s) being tested. With the changes now made, it is no longer needed to set this environment variable (once a test suite for an external standard has been made compatible with the PHPCS 4.0 test framework). * As there is now no place from which to call the `printPHPCodeSnifferTestOutput()` method anymore, the method has been removed and the "# sniff test files generated # unique error codes; # were fixable (#%)" summary line will no longer be printed at the end of a test run. A number of global variables were declared and written to by the tests to allow for that output previously. Those global variables are now no longer declared and assignments to these has been removed. * The previously used global variables containing an instance of the `Config` class and an array of instances of the `Ruleset` class have also been removed. This information is now stored in `private static` properties in the `AbstractSniffUnitTest` class. * To ensure autoloading of the tests and other files also works for tests for external standards using the PHPCS native test framework and loading the PHPCS native test bootstrap from _their_ test bootstrap, all standards registered in the applicable `CodeSniffer.conf` file will be registered with the autoloader. Information on how to upgrade test suites for external standards which are based on the PHPCS native test framework will be included in the PHPCS 4.0 upgrade guide. Fixes 25 Refs: * sebastianbergmann/phpunit 3213 * sebastianbergmann/phpunit 4460
1 parent be84dd8 commit ca10641

File tree

11 files changed

+68
-469
lines changed

11 files changed

+68
-469
lines changed

.github/workflows/quicktest.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ jobs:
6060

6161
- name: 'PHPUnit: run the full test suite'
6262
if: ${{ matrix.os != 'windows-latest' }}
63-
run: php "vendor/bin/phpunit" tests/AllTests.php --no-coverage
63+
run: php "vendor/bin/phpunit" --no-coverage
6464

6565
- name: 'PHPUnit: run tests which may have different outcomes on Windows'
6666
if: ${{ matrix.os == 'windows-latest' }}
67-
run: php "vendor/bin/phpunit" tests/AllTests.php --group Windows --no-coverage
67+
run: php "vendor/bin/phpunit" --group Windows --no-coverage
6868

6969
- name: 'PHPUnit: run select tests in CBF mode'
70-
run: php "vendor/bin/phpunit" tests/AllTests.php --group CBF --exclude-group nothing --no-coverage
70+
run: php "vendor/bin/phpunit" --group CBF --exclude-group nothing --no-coverage
7171
env:
7272
PHP_CODESNIFFER_CBF: '1'
7373

.github/workflows/test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ jobs:
204204

205205
- name: 'PHPUnit: run the full test suite without code coverage'
206206
if: ${{ matrix.skip_tests != true }}
207-
run: php "vendor/bin/phpunit" tests/AllTests.php --no-coverage
207+
run: php "vendor/bin/phpunit" --no-coverage
208208

209209
- name: 'PHPUnit: run select tests in CBF mode'
210210
if: ${{ matrix.skip_tests != true }}
211-
run: php "vendor/bin/phpunit" tests/AllTests.php --group CBF --exclude-group nothing --no-coverage
211+
run: php "vendor/bin/phpunit" --group CBF --exclude-group nothing --no-coverage
212212
env:
213213
PHP_CODESNIFFER_CBF: '1'
214214

@@ -307,13 +307,13 @@ jobs:
307307
- name: "Run the unit tests with code coverage"
308308
if: ${{ matrix.os != 'windows-latest' }}
309309
run: >
310-
php "vendor/bin/phpunit" tests/AllTests.php
310+
php "vendor/bin/phpunit"
311311
${{ steps.phpunit_version.outputs.VERSION >= '9.3' && '--coverage-cache ./build/phpunit-cache' || '' }}
312312
313313
- name: "Run select tests in CBF mode with code coverage"
314314
if: ${{ matrix.os != 'windows-latest' }}
315315
run: >
316-
php "vendor/bin/phpunit" tests/AllTests.php
316+
php "vendor/bin/phpunit"
317317
${{ steps.phpunit_version.outputs.VERSION >= '9.3' && '--coverage-cache ./build/phpunit-cache' || '' }}
318318
--group CBF --exclude-group nothing --coverage-clover build/logs/clover-cbf.xml
319319
env:
@@ -322,7 +322,7 @@ jobs:
322322
- name: "Run the unit tests which may have different outcomes on Windows with code coverage"
323323
if: ${{ matrix.os == 'windows-latest' }}
324324
run: >
325-
php "vendor/bin/phpunit" tests/AllTests.php --group Windows
325+
php "vendor/bin/phpunit" --group Windows
326326
${{ steps.phpunit_version.outputs.VERSION >= '9.3' && '--coverage-cache ./build/phpunit-cache' || '' }}
327327
328328
- name: "Upload coverage results to Coveralls (normal run)"

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@
5959
],
6060
"test": [
6161
"Composer\\Config::disableProcessTimeout",
62-
"@php ./vendor/phpunit/phpunit/phpunit tests/AllTests.php --no-coverage"
62+
"@php ./vendor/phpunit/phpunit/phpunit --no-coverage"
6363
],
6464
"coverage": [
6565
"Composer\\Config::disableProcessTimeout",
66-
"@php ./vendor/phpunit/phpunit/phpunit tests/AllTests.php -d max_execution_time=0"
66+
"@php ./vendor/phpunit/phpunit/phpunit -d max_execution_time=0"
6767
],
6868
"coverage-local": [
6969
"Composer\\Config::disableProcessTimeout",
70-
"@php ./vendor/phpunit/phpunit/phpunit tests/AllTests.php --coverage-html ./build/coverage-html -d max_execution_time=0"
70+
"@php ./vendor/phpunit/phpunit/phpunit --coverage-html ./build/coverage-html -d max_execution_time=0"
7171
],
7272
"build": [
7373
"Composer\\Config::disableProcessTimeout",

phpunit.xml.dist

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@
1313
forceCoversAnnotation="true"
1414
>
1515
<testsuites>
16-
<testsuite name="PHP_CodeSniffer Test Suite">
17-
<file>tests/AllTests.php</file>
16+
<testsuite name="PHPCS_Core">
17+
<directory>./tests/Core/</directory>
18+
</testsuite>
19+
<testsuite name="PHPCS_Sniffs">
20+
<directory>./src/Standards/Generic/Tests/</directory>
21+
<directory>./src/Standards/PEAR/Tests/</directory>
22+
<directory>./src/Standards/PSR1/Tests/</directory>
23+
<directory>./src/Standards/PSR2/Tests/</directory>
24+
<directory>./src/Standards/PSR12/Tests/</directory>
25+
<directory>./src/Standards/Squiz/Tests/</directory>
26+
<directory>./src/Standards/Zend/Tests/</directory>
1827
</testsuite>
1928
</testsuites>
2029

tests/AllTests.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/Core/AllTests.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

tests/FileList.php

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)