While rare, there are some deprecations which PHP can show when a file is being linted.
By default these are ignored by PHP-Parallel-Lint.
Apparently though, there is an option to show them (wasn't documented until recently), so let's turn that option on.
The `dealerdirect/phpcodesniffer-composer-installer` Composer plugin is used to register external PHPCS standards with PHPCS.
As of Composer 2.2.0, Composer plugins need to be explicitly allowed to run. This adds the necessary configuration for that.
Refs:
* https://blog.packagist.com/composer-2-2/#more-secure-plugin-execution
The Codecov service is a way to monitor test vs code coverage of a project over time and allows for the code coverage % + delta to be reported in each PR.
This commits:
* Adds a Codecov configuration.
* Adds a convenience script to the `composer.json` file to run the tests with or without code coverage.
* Adds a new matrix variable to the GH Actions `test` workflow to run the tests with code coverage and send the results to the Codecov service.
Notes:
- This disables the code coverage reporting in the "normal" test runs, including disabling `xdebug` for those runs which should make them slightly faster.
- This splits the test runs into two sets:
* High/low PHP are being run with code coverage (and have been removed from the "normal" test run matrix).
* For all other PHP versions, the tests are being run without code coverage.
* Adds a badge to the README to show the current code coverage %.
This commit:
* Add a new dependency on the PHP Parallel Lint package for fast PHP linting.
The PHP Parallel Lint package, in combination with the PHP Console Highlighter provides the following advantages in comparison with "plain" PHP linting:
- Higher speed due to the parallel processes.
- Improved usability by providing color coded syntax highlighting of found errors on the command-line.
- Integration with the `cs2pr` tool, allowing for the results of the lint command to be shown in-line in PRs.
* Adds a Composer `lint` script for easy access to the tool for devs, while making sure the correct command line parameters will be used.
The linting command as currently set up, will also check the example files for linting errors.
* Adds a GH Actions job for linting the code on the high/low supported PHP versions, one arbitrary interim version + an experimental build against PHP 8.1.
The `cs2pr` tool has been enabled and will show the results of the non-experimental lint runs in-line in PRs.
**Note**: For PHP 8.1, the `cs2pr` tool is not used as there is a known issue in the Parallel Lint tool with PHP 8.1 which breaks on the checkstyle reporting. There is already a [PR open](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/64) to fix this upstream. Once this PR has been merged and a new version of Parallel Lint has been released, the separate step for PHP 8.1 linting can be removed.
* Makes the `test` job in the GHA workflow dependent on the `lint` job having passed...
... as the tests would fail anyway if there are linting errors.
Also adjusts the name of the `test` jobs to include the word "Test" so they can be easily distinguished from the Lint jobs.
Refs:
* https://github.com/php-parallel-lint/PHP-Parallel-Lint
While working on 2363, I noticed that the code sniffer run was using PHP 8.0, but Composer still allowed for a PHP_CodeSniffer version to be installed which is not fully compatible with PHP 8.0.
Note: there are still two known incompatibilities with PHP 8.0 in PHPCS 3.6.0, but everything else has been fixed.
Ref: https://github.com/squizlabs/php_codesniffer/releases
Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
* .gitignore: ignore files created during a test run
* Tests: make config cross-version compatible
PHPUnit config file:
* Add `backupGlobals="true"`.
The default value for this setting changed in PHPUnit 6 from `true` to `false`. By explicitly setting it to `true`, the existing behaviour is maintained.
* Remove the `logIncompleteSkipped` directive which is no longer supported.
* Remove a number of directives which use the default values and for which the defaults have not changed across PHPUnit versions.
* Remove the space in the testsuite name to make it more easily usable on the command line.
* Make sure that all src files are taken into consideration when calculating code coverage.
* Add XSD schema reference.
Note: the config as-is will now validate for PHPUnit 4.4-9.2. For PHPUnit 9.3, the code coverage terminology has changed, though the "old" configuration is still supported.
If needs be (PHPUnit 10), the config can be updated on the fly by using `--migrate-configuration`.
Other:
* Ignore a locally overloaded PHPUnit config file using the standard `phpunit.xml` file name.
Question: why does the config file not use the standard `phpunit.xml.dist` file name ? That would allow for running the tests without command line arguments.
That file can still be overloaded locally by a `phpunit.xml` file.
* Composer: add dependency on the PHPUnit Polyfills package
* Adds a dev dependency to the `yoast/phpunit-polyfills` package.
* As that package already requires and manages the installable versions for PHPUnit, remove this as an explicit requirement from `require-dev` in favour of letting the PHPUnit Polyfills package manage the versions.
This will update the supported PHPUnit versions from `^4.8 || ^5.7` to `^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0`.
Note: the supported versions for PHPUnit 4.x and 5.x are very specific and restrictive as it specifically targets the versions in which the "forward compatible" alias files for the namespaced classes are available.
This new package adds the following features:
* Polyfills for various PHPUnit cross-version changes.
* Basic test case and test listener.
Refs:
* https://github.com/Yoast/PHPUnit-Polyfills/
Includes adding the PHPUnit cache file, which is automatically created in PHPUnit 8 and 9, to the `.gitignore` file.
* Tests: switch over to use the Yoast\PHPUnitPolyfills\TestCases\TestCase
This switches the parent class of the test classes over `TestCase` from the PHPUnit native TestCase to the `Yoast\PHPUnitPolyfills\TestCases\TestCase`.
The Yoast `TestCase`:
* Provides cross-version compatibility using snake case fixture method names instead of the PHPUnit native camelCase names.
This switch over includes:
* Renaming the `setUp()` and `tearDown()` methods to, respectively, `set_up()` and `tear_down()` in various test classes for PHPUnit cross-version compatibility.
* Tests: switch over to use the Yoast Polyfill TestListenerDefaultImplementation
This switches `DebugLogTestListener` class over to using the PHPUnit 9 default implementation pattern in combination with using the `TestListenerDefaultImplementation` from the PHPUnit Polyfill library for the cross-version compatibility layer for the TestListener.
The Yoast `TestListenerDefaultImplementation`:
* Provides cross-version compatibility using snake case method names instead of the PHPUnit native camelCase names.
This switch over includes:
* Renaming the template methods used in the `DebugLogTestListener` to use their snake_case variant and removes the type declarations.
* Tests: switch out `assertInternalType()`
... in favour of the more specific assertion(s) as introduced in PHPUnit 7.5.0.
The new assertions are automatically polyfilled via the PHPUnit Polyfill repo as this test class extends the `Yoast\PHPUnitPolyfills\TestCases\TestCase` test case.
* Tests: switch out `assert[Not]Contains()` with string haystacks
... in favour of the string specific `assertString[Not]ContainsString() assertion(s) as introduced in PHPUnit 7.5.0.
The new assertions are automatically polyfilled via the PHPUnit Polyfill repo as this test class extends the `Yoast\PHPUnitPolyfills\TestCases\TestCase` test case.
* Tests: switch out `@expectException` annotations
... in favour of method calls to the `TestCase::expectException()` method as introduced in PHPUnit 5.2.0.
The new method and its variants are automatically polyfilled via the PHPUnit Polyfill repo as this test class extends the `Yoast\PHPUnitPolyfills\TestCases\TestCase` test case.
* Tests: switch out `assertRegExp()`
... in favour of the renamed `Assert::assertMatchesRegularExpression() as introduced in PHPUnit 9.1.0.
The new assertion is automatically polyfilled via the PHPUnit Polyfill repo as this test class extends the `Yoast\PHPUnitPolyfills\TestCases\TestCase` test case.
* Tests: mark a test as incomplete
As per the comment in the docblock:
> Needs a connection to a server that supports this auth mechanism, so commented out by default.
As the test cannot currently be executed succesfully, we may as well skip it with a meaningful message.
* Tests: mark a test as not performing assertions
... to prevent it from being marked as risky.
Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
* PHPCS: rename config file
... to `phpcs.xml.dist` to allow devs to locally overload the file by using a `.phpcs.xml` or `phpcs.xml` file, to, for instance, test out some new rules.
Includes:
* Adding the local overload files to `.gitignore`.
* Adding the standard config file to `.gitattributes`.
* PHPCS: scan missing file
The `get_oauth_token.php` file in the project root seems to have been overlooked when configuring the PHPCS ruleset.
Fixed now by adding it to the file to be scanned.
Includes minor fixes to make the file comply with the configured standard.
* CS: fix two files
Two minor CS fixes.
* PHPCS: miscellaneous changes
* Don't fix the PHPCS/external standards version restraints.
* Add the PHPCS cache file to `.gitignore`.
* Removing the no longer existent `.php_cs` file from `.gitattributes`.
Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
Many of the PHP extensions used by PHPMailer are optional, in one of
two senses. Either there is a fallback if the extension is not
present, or the use of the extension is avoidable entirely. For
example, there is a fallback parser if "imap_rfc822_parse_adrlist" is
not available, and OpenSSL is not needed unless encryption is used;
therefore neither are hard dependencies.
The filter extension, on the other hand, is unavoidable. It is used
unconditionally, with no fallbacks, in (for example) the "isValidHost"
function. This commit adds "ext-filter" to composer.json, to document
the dependency and to help out composer users.
Closes: https://github.com/PHPMailer/PHPMailer/issues/1298
* Add PHP-CS-Fixer checks
* Remove composer.lock to early catch FC break on CI
* Travis: cache dependencies
* Enable code-coverage only for latest build
* Remove Symfony-specific PHP-Doc rules
* Apply coding-standards fix