0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-20 01:52:15 +02:00
Commit Graph

1828 Commits

Author SHA1 Message Date
jrfnl
c16da1afa8 GH Actions: set up code coverage monitoring via codecov
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 %.
2021-07-04 15:03:01 +02:00
Marcus Bointon
e0c140a127
Merge pull request #2405 from jrfnl/feature/icaltest-simplify
ICalTest: minor simplifications
2021-07-04 14:59:20 +02:00
Marcus Bointon
1988527535
Merge pull request #2404 from jrfnl/feature/tests-reorganize-18
Tests: move pathinfo tests to own file
2021-07-04 14:51:47 +02:00
Marcus Bointon
f4eba3a68c
Merge pull request #2403 from jrfnl/feature/setup-php-linting
GH Actions: add PHP linting job
2021-07-04 14:50:43 +02:00
Marcus Bointon
f3978c38cc
Merge pull request #2406 from jrfnl/feature/remove-PR-template
Remove PR template
2021-07-04 14:50:09 +02:00
jrfnl
ee9c363160 Remove PR template
PR 2373 changed the CI in such a way that coding standards errors will now be shown inline in the code of PRs.

With that change in place, having the information about running PHPCS in the pull request template has become redundant.
2021-07-04 01:47:09 +02:00
jrfnl
cdc2164361 ICalTest: minor simplifications
Follow up on 2384.

1. This test does not actually need a regular expression to test the mime message, an `assertStringContainsString()` assertion is sufficient.
2. Remove duplicate information from the `$expected` parameter. The `Content-Type: text/calendar; method=` part will always be the same. Only the method name will change.
2021-07-03 22:00:40 +02:00
jrfnl
8771d5f146 MbPathinfoTest: add @covers tag 2021-07-03 13:00:03 +02:00
jrfnl
78cb650429 MbPathinfoTest: add additional test cases for testMb_pathinfoWithOptions()
... to ensure all supported options are covered by a test.
2021-07-03 13:00:01 +02:00
jrfnl
487551ddac MbPathinfoTest: add additional test cases for testMb_pathinfoWithoutOptions()
Including test cases with:
* Spaces in the paths.
* Incomplete file paths.

Note: the "empty string" test may need looking at.... should this return an empty array instead ?
2021-07-03 12:59:59 +02:00
jrfnl
3a03d51399 MbPathinfoTest: reorganize to use data providers
* Replace the existing test code with two new test methods using data providers.
* Maintains the same test code and test cases.
* Makes it easier to add additional test cases in the future.
2021-07-03 12:59:57 +02:00
jrfnl
64fa2bf831 Tests/reorganize: move pathinfo tests to own file
As this test does not actually need an instantiated PHPMailer object, this class extends the `Yoast\PHPUnitPolyfills\TestCases\TestCase` instead of the `PHPMailer\Test\TestCase`.

Note: this doesn't move the complete test from the original test file, just select parts of the test method.
2021-07-03 12:59:55 +02:00
jrfnl
f0cfd3f49d GH Actions: add PHP linting job
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
2021-07-03 12:55:00 +02:00
Marcus Bointon
57a1323ef3
Merge pull request #2402 from jrfnl/feature/ghactions-various-tweaks
GH Actions: various tweaks
2021-07-03 12:47:47 +02:00
Marcus Bointon
69655d247a
Merge pull request #2401 from jrfnl/feature/tests-reorganize-17
Tests: move file name to type tests to own file
2021-07-03 12:47:25 +02:00
jrfnl
15994972fa GH Actions: test matrix - fix typo
There was a stray `.` in the string.
2021-07-02 17:48:31 +02:00
jrfnl
61e8701e02 GH Actions: test run - remove redundant dependency
The `xdebug` extension is already tagged as needed via the `coverage` setting, no need to add it to the `extensions` list.
---

Note: generally speaking, I personally normally don't pass an `extensions` list and allow the `setup-php` action to run with the default extensions, which is sufficient in most cases and would be sufficient here as well.

More than anything, I use the `extensions` key to _disable_ extensions for certain test runs, rather than enable them. Just something to consider.

The below documentation should give more insight.

Refs:
* https://github.com/shivammathur/setup-php/wiki/Php-extensions-loaded-on-ubuntu-18.04
* https://github.com/shivammathur/setup-php#heavy_plus_sign-php-extension-support
2021-07-02 17:46:08 +02:00
jrfnl
8a0e0d09f3 GH Actions: use predefined action to run composer install with caching
It is generally speaking a good idea to cache downloaded Composer packages between runs for performance reasons.

Now, this can be set up manually and would add two more steps to the scripts, or Ben's `composer-install` action can be used which will handle it all for you. The `composer-install` action is versatile and allows for passing additional parameters, so is perfectly suitable for this.

Ref: https://github.com/marketplace/actions/install-composer-dependencies
2021-07-02 17:41:07 +02:00
jrfnl
a7c19c069b GH Actions: test run - remove "dependency version" matrix key
Running against stable/lowest dependencies is relevant when a package has runtime (non-dev) dependencies.
However, PHPMailer does not have runtime dependencies.

In other words, the `dependency-version` matrix key is redundant and unused, so we may as well remove it.
2021-07-02 17:37:19 +02:00
jrfnl
bc5fe4dc1f GH Actions: CS run - remove matrix
The CS run only needs to run against one PHP version, so there is no need to set up a matrix for this.
2021-07-02 17:34:58 +02:00
jrfnl
decf70fa2b FilenameToTypeTest: add @covers tag 2021-07-02 17:25:47 +02:00
jrfnl
76aa6a06cb FilenameToTypeTest: add some additional test cases
... which should be supported based on the function docs.

Note: the "empty string" test may need looking at.... is this a bug ?
2021-07-02 17:25:45 +02:00
jrfnl
6ba68af48c FilenameToTypeTest: reorganize to use data providers
* Maintains the same test code and test cases.
* Removes code duplication.
* Makes it easier to add additional test cases in the future.
2021-07-02 17:25:44 +02:00
jrfnl
77c1d87123 Tests/reorganize: move file name to type tests to own file
As this test does not actually need an instantiated PHPMailer object, this class extends the `Yoast\PHPUnitPolyfills\TestCases\TestCase` instead of the `PHPMailer\Test\TestCase`.

Note: this doesn't move the complete test from the original test file, just select parts of the test method.
2021-07-02 17:25:42 +02:00
Marcus Bointon
35ab349e01
Merge pull request #2400 from jrfnl/feature/tests-reorganize-16
Tests: move line break normalization tests to own file
2021-07-02 16:57:52 +02:00
jrfnl
8bfb7d1e2f NormalizeBreaksTest: add @covers tag 2021-07-02 15:23:43 +02:00
jrfnl
d6f3fea0ea NormalizeBreaksTest: add extra test
... to verify the behaviour of the `PHPMailer::normalizeBreaks()` method when the `PHPMailer::$LE` property has been customized.
2021-07-02 15:23:43 +02:00
jrfnl
14d7458826 NormalizeBreaksTest: add additional test case
... to ensure text without line breaks is returned unchanged.
2021-07-02 15:23:43 +02:00
jrfnl
ade3b63428 NormalizeBreaksTest: reorganize to use data providers
* Maintains (largely) the same test code and test cases.
* Removes code duplication.
* Makes it easier to add additional test cases in the future.
2021-07-02 15:23:43 +02:00
jrfnl
0f916dd90a Tests/reorganize: move line break normalization tests to own file
As this test does not actually need an instantiated PHPMailer object, this class extends the `Yoast\PHPUnitPolyfills\TestCases\TestCase` instead of the `PHPMailer\Test\TestCase`.

Note: this doesn't move the complete tests from the original test file, just select parts of two test methods.
2021-07-02 15:23:43 +02:00
Marcus Bointon
49a2ea60ee
Merge pull request #2399 from jrfnl/feature/testcase-improve-on-static-prop-stability
TestCase: iterate on resetting of static properties
2021-07-02 12:12:46 +02:00
jrfnl
f6715fd047 TestCase: iterate on resetting of static properties
The `PHPMailer::preSend()` method may alter the value of the _`protect static`_ `PHPMailer::$LE` property.

a9978d2079/src/PHPMailer.php (L1494-L1504)

This means that tests which rely on the value of the property being the default, may start to fail unexpectedly depending on the _order_ in which tests are being run.
I.e. if the test relying on the default value is run first, all will be fine, however, if that same test is run _after_ a test which calls `preSend()` on a non-Windows box with PHP < 8.0 and with `$this->Mailer` set to `mail`, the test may fail unexpectedly.

This commit fixes that by expanding the previously introduced "resetting of static properties" logic.

This commit:
* Expands the list of static properties in the `TestCase` class to include the `PHPMailer::$LE` property.
* Introduces two new methods to the `TestCase` class:
    - `resetStaticProperties()` to reset all static properties listed in the `TestCase::$PHPMailerStaticProps` property to their default values.
    - `updateStaticProperty()` to change the value of one individual static property in a class.
* The `updateStaticProperty()` method was made `public static` to allow for tests which do not need an instantiated PHPMailer object and thus extend the `Yoast\PHPUnitPolyfills\TestCases\TestCase` directly to be able to use the method as well.
    If any such tests would use the method, that particular test will be responsible for resetting the value back to the default after the test.
* The resetting of the static properties has also been moved from the `set_up()` to the `tear_down()` method.
    As mentioned above, these static properties may be used by both tests extending this `TestCase` as well as test extending the `Yoast\PHPUnitPolyfills\TestCases\TestCase`. With that in mind, resetting _after_ each test will be more stable, as long as tests which extend the `Yoast\PHPUnitPolyfills\TestCases\TestCase` and would change static properties clean up after themselves.

**Note**: I'm not including the `PHPMailer::$IcalMethods` property in this change as AFAICS, this property is not being changed anywhere in the package code and as the property is `protected`, it cannot easily be changed from within a test either (and if it would be changed by a test, that test would be responsible for resetting it).

Also note: due to limitations in the `Reflection` extension, a hard-coded list of the default values of the static properties will need to be maintained in the `TestCase`. This cannot be helped as the `Reflection` extension does not have a way to accurately retrieve the default value of static properties in a PHP cross-version compatible manner.
2021-07-02 00:17:36 +02:00
Marcus Bointon
a9978d2079
Merge pull request #2398 from jrfnl/feature/testcase-minor-tweaks
TestCase: various tweaks
2021-07-01 22:50:40 +02:00
jrfnl
afd0da8a20 TestCase: minor tidying up
... of the inline comments in the `TestCase` file.
2021-07-01 21:52:19 +02:00
jrfnl
b97983fcf6 TestCase: add support for initializing PHPMailer with exceptions
The `PHPMailer::__construct()` method has an optional `$exceptions` property to throw exceptions on errors.

Up to now, the `PHPMailer` instance created by the `set_up()` would not pass any parameters, effectively instantiating `PHPMailer` without turning on exceptions.

In a test situation it may be useful for tests to test the behaviour of a method _with_ and _without_ the exceptions option and to test that certain exceptions are thrown and throw the correct message.

With that in mind, I'm introducing a `USE_EXCEPTIONS` class constant to the `TestCase` which can be overloaded in individual test classes and will be used by the `set_up()` method to determine whether it will be instantiated with exceptions or not.

Includes introducing an overload of the class constant in one of the test class for which it would seem appropriate at this time.
Note: this does mean that the `testDKIMSigningMail()` test will show as errored instead of failed if no SMTP connection could be made, but that IMO is the more correct status anyhow.
2021-07-01 21:50:57 +02:00
jrfnl
af68fb202a TestCase::setAddress(): add support for ReplyTo
This allows for using the `setAddress()` method in a more consistent manner (where appropriate).

Includes introducing the use of the `setAddress()` function in a few select places.

Note: I do wonder whether this method should ever be used outside of `set_up()` and `tear_down()`, but that is for further discussion and outside the scope of this commit.
2021-07-01 19:15:07 +02:00
jrfnl
1c32844af2 TestCase: remove unused property 2021-07-01 19:03:17 +02:00
Marcus Bointon
c5c35e4378
Merge pull request #2397 from jrfnl/feature/tests-ensure-static-property-starts-with-default-value
Tests: stabilize handling of static properties in PHPMailer class
2021-07-01 18:49:15 +02:00
Marcus Bointon
a8967c31a2
Merge pull request #2395 from jrfnl/feature/tests-reorganize-15
Tests: move wrapText test to own file
2021-07-01 18:48:13 +02:00
jrfnl
21fd99b057 ValidateAddressTest: stabilize handling of static $validator property in PHPMailer class
While this class does not (currently) _change_ the `PHPMailer::$validator` property, it does rely on the default value being the expected default.

By resetting the value of the property before and after the class, this is safeguarded for the current tests.
2021-07-01 18:29:49 +02:00
jrfnl
2077a3dc31 TestCase: stabilize handling of static properties in PHPMailer class
Public static properties changed by individual tests were not being reset to their default value prior to the next test being run.
This could influence the test results of subsequent tests as static properties are not automatically reset when a new instance of a class is instantiated. See: https://3v4l.org/8s1RB

Luckily this didn't aversely affect the tests so far, but should be safeguarded for the future.

There are only three static properties in the `PHPMailer` class, with only one of these being `public`.

This commit introduces a code snippet which will reset any static properties as listed in the `$PHPMailerStaticProps` property of the `TestCase` to the default value, as also set in the `$PHPMailerStaticProps` property, at the start of the `set_up()` which is run before each test using the `TestCase`.

For now, this is only relevant for the `ValidateAddressCustomValidatorTest` test and only when the `testSetDefaultValidatorToCustom()` test would fail before resetting the property. All the same, having the reset in place by default will ensure that future tests which change this property won't introduce side-effects to other tests.
2021-07-01 18:29:30 +02:00
jrfnl
b5826af2df WrapTextTest: add @covers tag 2021-06-30 22:45:01 +02:00
jrfnl
e1bf4a0dd5 WrapTextTest: add additional test cases
... in part to document the behaviour of the function, in part to actually test it.

By the looks of it more tests are still needed though to raise the code coverage of this function to 100%.

I'd also recommend adding tests with different charset settings as the current tests are all based on the default charset (`CHARSET_ISO88591`).

Also note: the "empty string" test may need looking at.... is this a bug ?
2021-06-30 22:44:34 +02:00
jrfnl
3ed9f04ff2 WrapTextTest: reorganize to use data providers
* Maintains the existing test cases.
* Prevent one failing assertion hiding a potential second failure.
* Makes it easier to add additional test cases in the future.
2021-06-30 22:36:11 +02:00
jrfnl
f9d63167df Tests/reorganize: move wrapText test to own file 2021-06-30 22:36:09 +02:00
Marcus Bointon
03edf2348c
Merge pull request #2394 from jrfnl/feature/tests-skip-pop-tests-on-windows
PopBeforeSmtpTest: skip on Windows
2021-06-30 15:31:12 +02:00
jrfnl
39426ae930 PopBeforeSmtpTest: skip on Windows
The shell commands used in the test are not available on Windows, so these tests would always fail, so we may as well skip them.
2021-06-29 12:36:07 +02:00
Juliette
c717120668
Tests/reorganize: move Auth CRAM MD5 test to own file (#2392)
As this test is marked _incomplete_, no further review of the test has been done and no `@covers` tag has been added.

Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
2021-06-29 11:22:51 +02:00
Marcus Bointon
84325b80b3
Improve simple messageid regex for default pattern 2021-06-28 10:54:41 +02:00
Marcus Bointon
cb25751853
Minor tweak to MessageID regex, fixes #2388 2021-06-28 10:28:28 +02:00