php-parallel-lint / PHP-Var-Dump-Check

Find forgotten variables dump in PHP source code.
Other
21 stars 11 forks source link

Make the unit tests cross version compatible #12

Closed jrfnl closed 4 years ago

jrfnl commented 4 years ago

PHPUnit setup: rename the config file

It is recommended to use the phpunit.xml.dist file name for the PHPUnit configuration file to allow individual developers to overload it with a phpunit.xml file.

To this end, I've:

PHPUnit: use the namespaced testcase

Commit 71c87a2 fixed this for the CheckTest.php file, but the other test files also needed fixing.

PHPUnit: don't use __construct() / cross-version compat up to PHPUnit 7.x

The __construct() method in the PHPUnit TestCase class is used by that class itself. Overloading it from a child class, while not problematic in PHPUnit 4.x, is problematic in later PHPUnit versions.

Better to use the setUpBeforeClass()or setUp() methods instead to set up fixtures.

With this change, the unit tests can now be run on PHPUnit 4 - 7.

PHPUnit: use annotations for fixtures / cross-version compat up to PHPUnit 9.x

As of PHPUnit 8.x, the method signature for the setUpBeforeClass(), setUp(), tearDown() and tearDownAfterClass() fixture methods has changed to require the void return type.

As the void return type isn't available until PHP 7.1, this cannot be implemented.

Anntations to the rescue. By renaming the setUpBeforeClass() methods to another, descriptive name and using the @beforeClass annotation, the tests can be made cross-version compatible up to PHPUnit 9.x.

With this change, the unit tests can now be run on PHPUnit 4 - 9.

As PHPUnit has a caching feature build in as of PHPUnit 8, we need to add the .phpunit.result.cache file to .gitignore.

grogy commented 4 years ago

Thank you. Extended commit messages are great, for example, information about usages annotation for old PHP. It is excellent preparation and I am glad for it