4267 Commits

Author SHA1 Message Date
Sergey Biryukov
fff4242f1a Code Modernization: Rename the readonly() function to wp_readonly().
Since PHP 8.1, `readonly` is a reserved keyword and cannot be used as a function name.

In order to avoid PHP parser errors, the `readonly()` function was extracted to a separate file and is now only included conditionally on PHP < 8.1.

This commit also:
* Moves the tests for the `__checked_selected_helper()` function and all the related functions to their own file.
* Switches to named data providers. This makes the output when using the `--testdox` option more descriptive and is helpful when trying to debug which data set from a data provider failed the test.
* Improves the tests in question to make them feature-complete and expand test coverage.

Props jrf, ayeshrajans, haosun, knutsp, swissspidy, SergeyBiryukov.
Fixes #53858.

git-svn-id: https://develop.svn.wordpress.org/trunk@51586 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-09 17:19:21 +00:00
Sergey Biryukov
385025b0ba Build/Test Tools: Declare two TestCase classes as abstract.
TestCases which are intended to be extended and not run directly, should be `abstract`.

Follow-up to [763/tests], [30277].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51585 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-09 14:51:05 +00:00
Sergey Biryukov
9e07a480c5 Build/Test Tools: Remove Unicode character from PHPUnit version check message.
Not all CLI tools can handle Unicode characters or non-system specific line endings well, so this type of CLI messaging should always be written with the optimal cross-platform, cross-CLI tool end-user experience in mind.

Follow-up to [51581].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51584 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-09 13:04:38 +00:00
Sergey Biryukov
40bbe55b8e Build/Test Tools: Add schema reference to PHPUnit config files.
The current config files validate against the PHPUnit XSD schema for config files for PHPUnit 5.7 – 9.2.

The schema was changed in PHPUnit 9.3, and the `filter` and `logging` settings were deprecated in favor of `coverage` and a different format for `logging`.

This commit explicitly sets the schema against which the files currently validate, for clarity.

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51583 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-09 12:52:58 +00:00
Sergey Biryukov
53f5eaddb4 Build/Test Tools: Fix message display in test bootstrap.
Any messages to the user which are echo-ed out in the test bootstrap will generally display on a command-line interface.

The *nix specific `"\n"` line ending will be ignored on Windows, making the messages less readable.

For new lines in CLI messages, `PHP_EOL` should be used instead.

This was already done in a few places in the script, but not consistently so. Fixed now.

Follow-up to [UT882], [UT890], [44723], [45020], [48592], [49535], [51560].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51581 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 14:45:08 +00:00
Sergey Biryukov
fa2c313224 Tests: Use more appropriate assertions in get_themes() tests.
This replaces instances of `assertTrue( is_dir( ... ) )` with `assertDirectoryExists()` to use native PHPUnit functionality.

The `assertDirectoryExists()` method was introduced in PHPUnit 5.6. As the minimum supported PHPUnit version has been raised to PHPUnit 5.7.21, it can now be used.

Follow-up to [51543], [51574], [51579].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51580 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 14:18:31 +00:00
Sergey Biryukov
213bbf76ed Tests: Use more appropriate assertions in get_themes() tests.
This replaces instances of `assertTrue( is_file( ... ) )` followed by `assertTrue( is_readable( ... ) )` with `assertFileIsReadable()` to use native PHPUnit functionality.

The `assertFileIsReadable()` method was introduced in PHPUnit 5.6. As the minimum supported PHPUnit version has been raised to PHPUnit 5.7.21, it can now be used.

Follow-up to [51543], [51574].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51579 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 14:15:42 +00:00
Sergey Biryukov
14c6bcda56 Tests: Remove redundant @requires tags.
As the minimum supported PHPUnit version has been upped to PHPUnit 5.7.21, these `@requires` tags are now redundant.

Follow-up to [51226], [51234], [51559-51576].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51577 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 11:56:24 +00:00
Sergey Biryukov
f41d9545f9 Tests: Replace expectException() for PHP native errors with calls to the dedicated PHPUnit 8.4+ methods.
The old manner of testing these is soft deprecated as of PHPUnit 8.4, hard deprecated as of PHPUnit 9.0 and will be removed in PHPUnit 10.0.

Most calls like this were already replaced in [51563], however, this particular one could not be changed yet due to the mismatch between the PHPUnit version and the PHP version on which the tests were being run. This is fixed now.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.4.3/ChangeLog-8.4.md#840---2019-10-04
* https://github.com/sebastianbergmann/phpunit/issues/3775

Follow-up to [51559-51575].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51576 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 11:52:05 +00:00
Sergey Biryukov
36c997c4b2 Build/Test Tools: Remove the copied-in PHPUnit 9.x MockObject files.
As the version constraints for PHPUnit now allow the tests to be run on PHPUnit 8.x and 9.x, these files are no longer needed.

Follow-up to [48957], [49037], [51544], [51559-51574].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51575 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 11:44:00 +00:00
Sergey Biryukov
8def694fe4 Build/Test Tools: Loosen the PHPUnit restriction.
**composer.json**:

Remove the PHPUnit dependency in favor of allowing the PHPUnit Polyfills library to manage the supported PHPUnit version. This automatically now widens the supported PHPUnit versions to 5.7.21 to 9.5.8 (current).

Letting the PHPUnit Polyfills handle the version constraints for PHPUnit prevents potential version conflicts in the future, as well as allows WordPress to benefit straight away when a new PHPUnit version would be released and the PHPUnit Polyfills package adds support for that PHPUnit version.

**Test Bootstrap**

Update the supported version number for PHPUnit 5.x, as the minimum PHPUnit 5.x version supported by the PHPUnit Polyfills is PHPUnit 5.7.21, and remove the PHPUnit maximum.

**.gitignore and svn:ignore:**

Add the PHPUnit cache file to the list of files to be ignored.

Since PHPUnit 8, PHPUnit has a built-in caching feature which creates a `.phpunit.result.cache` file. This file should not be committed.

Follow-up to [40536], [40853], [44701], [51559-51573].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51574 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 11:41:53 +00:00
Sergey Biryukov
aae784273f Build/Test Tools: Remove SpeedTrapListener.
Now that the tests can run PHPUnit cross-version and Composer will be used to install the test suite in CI, we could switch out the local copies of the [https://github.com/johnkary/phpunit-speedtrap PHPUnit speedtrap] package in favor of using the Composer package, which would prevent us having to make the WP local copies of the class compatible with later PHPUnit versions.

The SpeedTrap test listener was introduced to identify slow tests and take action on these to make them faster.

In practice, however, no notable action was ever taken based on the output of the test listener in all the years it was in place.

With that in mind, it was decided to remove the SpeedTrap test listeners without replacement.

If – at a future date – contributors would want to take action to speed up slow tests anyway, they can:
* Either add the package to their local install and use the output they receive locally to identify slow tests.
* Or use the PHPUnit native `@small` annotations in combination with the PHPUnit `PHP_Invoker` package as described in the PHPUnit documentation to [https://phpunit.readthedocs.io/en/stable/risky-tests.html#test-execution-timeout run tests with time limits].

Follow-up to [35214], [35226], [35767], [44701], [51559-51572].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51573 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 11:14:39 +00:00
Sergey Biryukov
e8ea993ce7 Build/Test Tools: Handle removal of TestCase::getAnnotations().
The PHPUnit native `TestCase::getAnnotations()` method is used to check for WP flavored deprecation notices, however, this method was not covered by the backward compatibility promise for PHPUnit (and was annotated as excluded).

The method has been removed as part of an internal refactor in commit [68582043e1 sebastianbergmann/phpunit@6858204], which is included in PHPUnit 9.5.0.

For now, a workaround is put in place, but it is recommended that the WP `expectDeprecated()` method should be reevaluated in a future iteration.

Follow-up to [51559-51571].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51572 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 11:00:52 +00:00
Sergey Biryukov
60dcae95ea Tests: Fix tests failing due to assertContains() using strict checking.
Since PHPUnit 8.0.2, the `assertContains()` method, when checking whether a value exists in an array, will do a strict type comparison of the values.

This caused a couple of tests to fail. Using the correct data type in the test fixes that.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* https://github.com/sebastianbergmann/phpunit/issues/3511
* 6205f33595

Follow-up to [51559-51570].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51571 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 10:51:59 +00:00
Sergey Biryukov
fcd4aa4700 Build/Test Tools: Alias the Getopt class conditionally, as the class no longer exists in PHPUnit 9.x.
Most of the aliasing in this `compat.php` file is redundant as PHPUnit 5.7.21+ contains a forward compatibility layer for these classes anyway (= PHPUnit provides both the namespaced and underscore named versions of these classes in PHPUnit 5.7.21+).

All the same, the file and the aliases are left in place for the time being, as plugins/themes using the WP test suite as the basis for their integration tests may rely on it, though WP itself should not really need it anymore, save for maybe one or two classes.

Follow-up to [51559-51569].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51570 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 10:46:54 +00:00
Sergey Biryukov
22060f3b06 Tests: Remove use of assertArraySubset() in Test_WP_Widget_Media::test_constructor().
The `assertArraySubset()` method has been deprecated in PHPUnit 8 and removed in PHPUnit 9.

This replaces the assertions with looping through the array and testing both the key and the value individually.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#800---2019-02-01
* https://github.com/sebastianbergmann/phpunit/issues/3494

Note: There is a polyfill package available for the removed assertion: `dms/phpunit-arraysubset-asserts`, but as the assertion was only used in this one test method, adding this seems redundant.

Follow-up to [51559-51568].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51569 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 10:40:44 +00:00
Sergey Biryukov
ddb409edca Build/Test Tools: Implement use of the void solution.
> PHPUnit 8.0.0 introduced a `void` return type declaration to the "fixture" methods – `setUpBeforeClass()`, `setUp()`, `tearDown()` and `tearDownAfterClass()`. As the `void` return type was not introduced until PHP 7.1, this makes it more difficult to create cross-version compatible tests when using fixtures, due to signature mismatches.
>
> The `Yoast\PHPUnitPolyfills\TestCases\TestCase` overcomes the signature mismatch by having two versions. The correct one will be loaded depending on the PHPUnit version being used.
>
> When using this TestCase, if an individual test, or another TestCase which extends this TestCase, needs to overload any of the "fixture" methods, it should do so by using a snake_case variant of the original fixture method name, i.e. `set_up_before_class()`, `set_up()`, `assert_pre_conditions()`, `assert_post_conditions()`, `tear_down()`, and `tear_down_after_class()`.
>
> The snake_case methods will automatically be called by PHPUnit.
>
> > IMPORTANT: The snake_case methods should not call the PHPUnit parent, i.e. do not use `parent::setUp()` from within an overloaded `set_up()` method. If necessary, DO call `parent::set_up()`.

Reference: https://github.com/Yoast/PHPUnit-Polyfills#testcases

This commit renames all declared fixture methods, and calls to parent versions of those fixture methods, from camelCase to snake_case.

Follow-up to [51559-51567].

Props jrf, hellofromTonya, johnbillion, netweb, dd32, pputzer, SergeyBiryukov.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51568 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 10:29:41 +00:00
Sergey Biryukov
cb6bf02638 Build/Test Tools: Use the PHPUnit Polyfill TestCase as void workaround.
> PHPUnit 8.0.0 introduced a `void` return type declaration to the "fixture" methods – `setUpBeforeClass()`, `setUp()`, `tearDown()` and `tearDownAfterClass()`. As the `void` return type was not introduced until PHP 7.1, this makes it more difficult to create cross-version compatible tests when using fixtures, due to signature mismatches.
>
> The `Yoast\PHPUnitPolyfills\TestCases\TestCase` overcomes the signature mismatch by having two versions. The correct one will be loaded depending on the PHPUnit version being used.
>
> When using this TestCase, if an individual test, or another TestCase which extends this TestCase, needs to overload any of the "fixture" methods, it should do so by using a snake_case variant of the original fixture method name, i.e. `set_up_before_class()`, `set_up()`, `assert_pre_conditions()`, `assert_post_conditions()`, `tear_down()`, and `tear_down_after_class()`.
>
> The snake_case methods will automatically be called by PHPUnit.
>
> > IMPORTANT: The snake_case methods should not call the PHPUnit parent, i.e. do not use `parent::setUp()` from within an overloaded `set_up()` method. If necessary, DO call `parent::set_up()`.

Reference: https://github.com/Yoast/PHPUnit-Polyfills#testcases

This commit:
* Lets the `PHPUnit_Adapter_TestCase` extend the `Yoast\PHPUnitPolyfills\TestCases\TestCase`, which makes this solution for the `void` return type available to the WordPress test suite.
* Removes the individual import and trait `use` statements for the Polyfill traits. These are no longer necessary as the `Yoast\PHPUnitPolyfills\TestCases\TestCase` already includes those.

Follow-up to [51559-51566].

Props jrf, hellofromTonya, johnbillion, netweb, SergeyBiryukov.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51567 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-07 10:20:05 +00:00
Sergey Biryukov
ee2770bda5 Tests: Replace assertNotRegExp() with assertDoesNotMatchRegularExpression().
The `assertRegExp()` and `assertNotRegExp()` methods were hard deprecated in PHPUnit 9.1 and the functionality will be removed in PHPUnit 10.0.

The `assertMatchesRegularExpression()` and `assertDoesNotMatchRegularExpression()` methods were introduced as a replacement in PHPUnit 9.1.

These new PHPUnit methods are polyfilled by the PHPUnit Polyfills and switching to them will future-proof the tests some more.

References:
* https://github.com/sebastianbergmann/phpunit/blob/9.1.5/ChangeLog-9.1.md#910---2020-04-03
* https://github.com/sebastianbergmann/phpunit/issues/4085
* https://github.com/sebastianbergmann/phpunit/issues/4088

Follow-up to [51559-51565].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51566 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-06 21:55:31 +00:00
Sergey Biryukov
457b7b3a61 Tests: Replace assertRegExp() with assertMatchesRegularExpression().
The `assertRegExp()` and `assertNotRegExp()` methods were hard deprecated in PHPUnit 9.1 and the functionality will be removed in PHPUnit 10.0.

The `assertMatchesRegularExpression()` and `assertDoesNotMatchRegularExpression()` methods were introduced as a replacement in PHPUnit 9.1.

These new PHPUnit methods are polyfilled by the PHPUnit Polyfills and switching to them will future-proof the tests some more.

References:
* https://github.com/sebastianbergmann/phpunit/blob/9.1.5/ChangeLog-9.1.md#910---2020-04-03
* https://github.com/sebastianbergmann/phpunit/issues/4085
* https://github.com/sebastianbergmann/phpunit/issues/4088

Follow-up to [51559-51564].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51565 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-06 21:52:06 +00:00
Sergey Biryukov
29d678d08b Tests: Replace assertFileNotExists() with assertFileDoesNotExist().
The `assertFileNotExists()` method was hard deprecated in PHPUnit 9.1 and the functionality will be removed in PHPUnit 10.0.

The `assertFileDoesNotExist()` method was introduced as a replacement in PHPUnit 9.1.

This new PHPUnit method is polyfilled by the PHPUnit Polyfills and switching to it will future-proof the tests some more.

References:
* https://github.com/sebastianbergmann/phpunit/blob/9.1.5/ChangeLog-9.1.md#910---2020-04-03
* https://github.com/sebastianbergmann/phpunit/issues/4076

Follow-up to [51559-51563].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51564 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-06 21:45:32 +00:00
Sergey Biryukov
fe7295b860 Tests: Replace expectException() for PHP native errors with calls to the dedicated PHPUnit 8.4+ methods.
The old manner of testing these is soft deprecated as of PHPUnit 8.4, hard deprecated as of PHPUnit 9.0 and will be removed in PHPUnit 10.0.

These dedicated methods introduced in PHPUnit 8.4 should be used as an alternative:

* `expectDeprecation()`
* `expectDeprecationMessage()`
* `expectDeprecationMessageMatches()`
* `expectNotice()`
* `expectNoticeMessage()`
* `expectNoticeMessageMatches()`
* `expectWarning()`
* `expectWarningMessage()`
* `expectWarningMessageMatches()`
* `expectError()`
* `expectErrorMessage()`
* `expectErrorMessageMatches()`

These new PHPUnit methods are all polyfilled by the PHPUnit Polyfills and switching to these will future-proof the tests some more.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.4.3/ChangeLog-8.4.md#840---2019-10-04
* https://github.com/sebastianbergmann/phpunit/issues/3775

Follow-up to [51559-51562].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51563 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-06 21:38:45 +00:00
Sergey Biryukov
81461004d7 Build/Test Tools: Simplify redundant PHPUnit shim for setExpectedException().
PHPUnit 6 deprecated the `setExpectedException()` method in favor of the `expectException()`, `expectExceptionMessage()`, and `expectExceptionCode()` methods.

`WP_UnitTestCase_Base::setExpectedException()` backfilled the old method. As the PHPUnit Polyfills have a polyfill for the ''new'' method, this backfill can now be simplified.

This backfill ''should'' be removed in a future iteration, but is, for now, left in place so as not to break backward compatibility for plugin/theme test suites which extend the WP native test suite for their integration tests.

Follow-up to [48996], [48997], [51559-51561].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51562 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-06 21:17:20 +00:00
Sergey Biryukov
31a6cd2f78 Build/Test Tools: Change the inheritance order of the abstract test classes.
As things were, the inheritance order of the abstract test classes was as follows:
{{{
WP_UnitTestCase (PHPUnit adapter layer)
    extends WP_UnitTestCase_Base (base test class)
        extends PHPUnit\Framework\TestCase (PHPUnit native class)
}}}

Concrete (child) test classes, as well as more specific abstract TestCases, are/were expected to extend the `WP_UnitTestCase`.

This order is not optimal as it means that the `WP_UnitTestCase_Base` class would not be able to benefit from any polyfills and/or shims in the PHPUnit adapter layer.

With that in mind, this commit changes the inheritance to:
{{{
WP_UnitTestCase (empty class, left in place to not break BC for plugin/theme integration tests)
    extends WP_UnitTestCase_Base (base test class)
        extends PHPUnit_Adapter_TestCase (PHPUnit adapter layer)
            extends PHPUnit\Framework\TestCase (PHPUnit native class)
}}}

The new order allows for the `WP_UnitTestCase_Base` to also benefit from the PHPUnit adapter layer.

For backward compatibility reasons the `WP_UnitTestCase`, which all test classes are (were) expected to extend, is left in place, though it is now an empty class and explicitly `abstract`.

Follow-up to [51559], [51560].

Props jrf, hellofromTonya, johnbillion, netweb, SergeyBiryukov.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51561 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-06 00:44:00 +00:00
Sergey Biryukov
47303b1f95 Build/Test Tools: Unify the PHPUnit adapter TestCases.
This commit:
* Removes the PHPUnit 7 specific `TestCase`.
* Removes all existing polyfills from the PHPUnit 5.x `TestCase`.
* Imports all polyfill traits from the PHPUnit Polyfills package into the `WP_UnitTestCase` class and updates the DocBlock to reflect the actual function of the class.
 * Note: The list of polyfills needs to be verified and updated after each new release of the PHPUnit Polyfills package. Alternatively (recommended), one of the built-in `TestCase` classes from the PHPUnit Polyfills package can be used instead.

* Moves the `require` for the WP `abstract-testcase.php` to the `bootstrap.php` file.
* Adds a `require_once` for the PHPUnit Polyfills autoloader to the `bootstrap.php` file.
 * Note: while this isn't _strictly_ necessary when the tests are run via Composer, having the include in the bootstrap allows for the tests to also be run via a PHPUnit Phar, providing contributors with more flexibility.

Follow-up to [51559].

Props jrf, hellofromTonya, johnbillion, netweb, SergeyBiryukov.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51560 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-06 00:35:01 +00:00
Sergey Biryukov
2bfd2c5da9 Coding Standards: Remove redundant semicolons after closing curly brackets.
Props jrf.
See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51552 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-05 13:14:21 +00:00
Sergey Biryukov
b2be104b9d Coding Standards: Fix incorrect alignment in two comment blocks.
Tabs should only be used for indentation and not for mid-line alignment.

Props jrf.
See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51551 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-05 13:10:05 +00:00
Sergey Biryukov
461f7764e4 Build/Test Tools: Use a custom autoloader for the PHPUnit 9.x mock object classes.
This prevents the classes from being loaded automatically via the `autoload-dev` directives when a Composer-installed PHPUnit 5.x or 6.x version is used, as that would break the test run.

It is expected that this autoloader will be removed soon, as it should no longer be needed when the PHPUnit version constraints are widened.

Notes:
* The autoloader file will be loaded from the Test bootstrap.
* The autoloader will always be registered and directed to queue itself _before_ the Composer autoload file (which will already have been registered).
* The autoloader will only actually load the WP copies of the files/classes when PHP 8.0 in combination with PHPUnit 7.x is detected. In all other cases, the autoloader will bow out, which effectively then defers to the Composer autoload file to load the files as shipped with the installed PHPUnit version.

Follow-up to [48957], [49037], [51543].

Props jrf.
See #47381.

git-svn-id: https://develop.svn.wordpress.org/trunk@51544 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-04 19:24:14 +00:00
Sergey Biryukov
0e442c4615 Build/Test Tools: Remove the Composer lock file from version control.
This makes it easier to run unit tests against multiple different PHP versions.

There is currently no reason to have a `composer.lock` file as:

* External runtime dependencies are not managed via Composer.
* Managed updates of the non-runtime dependencies can be done by locking the version used in the `composer.json` file to a precise version instead of using a `composer.lock` file.
* Having the `composer.lock` file in place makes it a lot more difficult to run the tests against all supported PHP versions.

With these considerations in mind, the lock file is now removed from version control and added to `.gitignore` and `svn:ignore`.

Version constraints for the current dev dependencies are adjusted accordingly:

* PHPUnit now explicitly declares in its version constraints that PHPUnit 5.x, 6.x, and 7.x are supported. The minimum supported version for PHPUnit 5.x has been raised from 5.4 to 5.7, which in practice was already the version used for running the tests on PHP 5.6.
* PHPCompatibilityWP is effectively updated to version 2.1.2 with the positive impact that a few new constants polyfilled in WP 5.8 are now accounted for (excluded from being flagged).
* PHP_CodeSniffer is declared as an explicit dependency to ensure that updates to it will always be explicitly managed instead of inherited.
* The DealerDirect Composer plugin is effectively updated to version 0.7.1 without impact.

Follow-up to [42960], [46290], [47881], [48957].

Props jrf, johnbillion, desrosj, ayeshrajans, aristath, hellofromTonya, SergeyBiryukov.
See #47381.

git-svn-id: https://develop.svn.wordpress.org/trunk@51543 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-04 18:55:38 +00:00
Jonathan Desrosiers
3148181925 Build/Test Tools: Revert changes only included for testing purposes.
Follow up to [51535-51536].

See #52644.

git-svn-id: https://develop.svn.wordpress.org/trunk@51537 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-03 15:14:03 +00:00
Jonathan Desrosiers
ce0396ba76 Build/Test Tools: Expand Slack notifications for GitHub Actions.
This expands Slack notifications to include success, cancelled, and “fixed” GitHub Action workflow run outcomes in addition to failures.

A “fixed” outcome occurs when the previous run for a workflow failed and the current one succeeds. This matches the behavior that was native to TravisCI by setting `on_success` for notifications to `change`.

The message details and where each outcome is posted is controlled by Slack workflows.

The Slack notification logic has also been pulled into a separate workflow to prevent repeating code in every workflow.

See #52644.

git-svn-id: https://develop.svn.wordpress.org/trunk@51535 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-03 13:45:02 +00:00
Sergey Biryukov
2ba4a4817a Themes: Make sure get_theme_mods() always returns an array.
This avoids a "Cannot access offset of type string on string" fatal error in `set_theme_mod()` on PHP 8 if the `theme_mods_$theme_slug` option has an incorrect value, e.g. an empty string instead of an array.

With this change, `set_theme_mod()` should be able to resolve the issue by saving a correct value.

Follow-up to [15736], [15739], [30672], [32629], [32632].

Props xknown.
See #51423.

git-svn-id: https://develop.svn.wordpress.org/trunk@51524 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-01 14:54:52 +00:00
Sergey Biryukov
17fb93149b Code Modernization: Fix "JsonSerializable_Object::jsonSerialize() should be compatible with JsonSerializable::jsonSerialize(): mixed" error on PHP 8.1.
This relates to the [https://wiki.php.net/rfc/internal_method_return_types Return types for internal methods RFC] in PHP 8.1 and in particular, the change made in [https://github.com/php/php-src/pull/7051 PHP PR #7051], which adds a `mixed` return type to the `JsonSerializable::jsonSerialize()` interface method.

WordPress only contains one (test) class which implements the `JsonSerializable` interface and this commit fixes the issue for that class.

As of PHP 8.1, the `jsonSerialize()` method in classes which implement the `JsonSerializable` interface are expected to have a return type declared. The return type should be `mixed` or a more specific type. This complies with the Liskov principle of covariance, which allows the return type of a child overloaded method to be more specific than that of the parent.

The problem with this is that:
1. The `mixed` return type was only introduced in PHP 8.0.
2. Return types in general were only introduced in PHP 7.0.

WordPress still has a minimum PHP version of 5.6, so adding the return type is not feasible for the time being.

The solution chosen for now is to add an attribute to silence the deprecation warning. While attributes are a PHP 8.0+ feature, due to the choice of the `#[]` syntax, in PHP < 8.0, attributes will just be ignored and treated as comments, so there is no drawback to using the attribute.

Props jrf.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51517 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-30 14:46:30 +00:00
Jonathan Desrosiers
12a820379a Build/Test Tools: Revert the test and coding standards changes in [51511].
These were temporary for testing Slack messages when GitHub Action workflows fail.

See #52644.

git-svn-id: https://develop.svn.wordpress.org/trunk@51512 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-29 20:02:53 +00:00
Jonathan Desrosiers
7a60b8eb8b Build/Test Tools: Post a message to #core in Slack when a workflow fails.
This adds an additional step to each GitHub Action workflow file that posts a message to #core in Slack every time a workflow run fails.

A minor test and spacing change is included in this commit in order to that messages are posted correctly and will be reverted after testing.

See #52644.

git-svn-id: https://develop.svn.wordpress.org/trunk@51511 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-29 19:47:43 +00:00
gziolo
ad976addb3 Build: Split packages and blocks to their webpack configs
It aligns with the changes proposed added in Gutenberg: https://github.com/WordPress/gutenberg/pull/33293.

The idea here is to split the growing webpack config into two parts: blocks and  packages.

We need to add handling for JavaScript files that are going to be used with blocks on the frontend. They didn't work quite well with the current setup for entry points created for packages.

As part of the effort, it adds support for `viewScript` in `block.json` metadata file that is later translated to `$view_script` in `WP_Block_Type` class and exposed as `view_script` from the REST API endpoint for block types.

Props youknowriad, desrosj, aristath.
Fixes #53690.



git-svn-id: https://develop.svn.wordpress.org/trunk@51501 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-28 10:05:01 +00:00
Sergey Biryukov
8a0b871a3d Tests: Rename classes in phpunit/tests/widgets/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51493 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-26 19:25:09 +00:00
Sergey Biryukov
7f828b6b00 Tests: Rename classes in phpunit/tests/sitemaps/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51492 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-26 19:09:41 +00:00
Sergey Biryukov
1d838a7885 Tests: Rename classes in phpunit/tests/blocks/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51491 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-26 18:45:48 +00:00
Sergey Biryukov
9da818a068 Tests: Move and fix incorrectly placed tests for block supported styles.
The `Block_Supported_Styles_Test` class is not a `TestCase` to be extended, but an actual concrete test class. In order to run as expected, it should be placed under `phpunit/tests/blocks/` along with the other block tests.

Additionally:
* Add missing visibility keywords to test methods.
* Update the expected results to the currently used format for the tests to pass.
* Remove two outdated tests. The functionality being tested there is no longer available in this manner, so these tests are redundant.

Follow-up to [49226], [49310].

Props jrf, aristath, youknowriad.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51490 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-26 17:39:53 +00:00
Sergey Biryukov
2c0a1f7377 Tests: Use better assertions in WP_UnitTestCase_Base::assertEqualFields():
* Check if the object attribute exists before checking its value.
* Mention the field name in error messages in case of failure.

Follow-up to [51478], [51479], [51480].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51481 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-22 18:49:24 +00:00
Sergey Biryukov
d8c3bc78a1 Tests: Modernize the WP_UnitTestCase_Base::assertEqualFields() method:
* Use `assertSame()` instead of `fail()` to display a proper message in case of failure.
* Add an optional `$message` parameter for consistency with other assertions.

Follow-up to [51478], [51479].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51480 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-22 17:39:03 +00:00
Sergey Biryukov
dc568b181b Tests: Correct placement of the $message parameter in assertDiscardWhitespace().
Follow-up to [51478].

Props johnbillion.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51479 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-22 17:26:00 +00:00
Sergey Biryukov
0975e828f7 Tests: Add a $message parameter for custom assertions in WP_UnitTestCase_Base.
All assertions in PHPUnit have a `$message` parameter. Setting this parameter allows to distinguish which assertion is failing when a test runs multiple assertions, making debugging of the tests easier.

This optional parameter is now added for the assertion methods in the `WP_UnitTestCase_Base` class that were missing it.

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51478 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-22 17:14:44 +00:00
Sergey Biryukov
a5bef1ea91 Tests: Correct class name for WP_Filesystem_Base::find_folder() tests.
A concrete test class should be suffixed with `Test`, not `UnitTestCase(s)`.

Follow-up to [25053].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51476 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-22 16:44:34 +00:00
John Blackbourn
0167d6dd50 Application Passwords: Improve various user-facing and developer-facing terminology.
Fixes #53503, #53691


git-svn-id: https://develop.svn.wordpress.org/trunk@51463 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-19 21:13:36 +00:00
Sergey Biryukov
c70fe62ed1 Tests: Replace assertContains() with assertStringContainsString() when used with strings.
Using the `assertContains()` and `assertNotContains()` methods with string haystacks was deprecated in PHPUnit 8 and removed in PHPUnit 9.

While WordPress test suite currently only supports PHPUnit up to 7.5.x, this allows us to switch to newer assertions ahead of adding full support for PHPUnit 8+.

These methods introduced in PHPUnit 7.5 should be used as an alternative:

* `assertStringContainsString()`
* `assertStringContainsStringIgnoringCase`
* `assertStringNotContainsString()`
* `assertStringNotContainsStringIgnoringCase`

As WordPress currently uses PHPUnit 5.7.x to run tests on PHP 5.6, polyfills for these methods were added to the `WP_UnitTestCase` class for PHPUnit < 7.5.

Follow-up to [51331], [51451], [51461].

Props jrf, dd32, SergeyBiryukov.
See #53363, #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51462 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-19 14:00:11 +00:00
Sergey Biryukov
bb3bf22547 Tests: Use more appropriate assertions in various tests.
This replaces instances of `assertFalse( stripos( ... ) )` with `assertStringNotContainsString()` or `assertStringNotContainsStringIgnoringCase()` to use native PHPUnit functionality.

Going forward, these methods introduced in PHPUnit 7.5 should be used for similar assertions:

* `assertStringContainsString()`
* `assertStringContainsStringIgnoringCase()`
* `assertStringNotContainsString()`
* `assertStringNotContainsStringIgnoringCase()`

As WordPress currently uses PHPUnit 5.7.x to run tests on PHP 5.6, polyfills for these methods are now added to the `WP_UnitTestCase` class for PHPUnit < 7.5.

Follow-up to [51335], [51337], [51367], [51397], [51403], [51404], [51436], [51438], [51448], [51449], [51451], [51453], [51454].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51461 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-19 13:29:45 +00:00
Sergey Biryukov
4a533f4879 Tests: Use more appropriate assertions in various tests.
This replaces instances of `assertTrue( ... > 0 )` with `assertGreaterThan()` to use native PHPUnit functionality.

Follow-up to [51335], [51337], [51367], [51397], [51403], [51404], [51436], [51438], [51448], [51449], [51451], [51453].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51454 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-18 14:10:24 +00:00
Sergey Biryukov
ba94d9b67b Tests: Use more appropriate assertions in rest_sanitize_request_arg() tests.
This replaces instances of `assertSame( true, ... )` with `assertTrue()` to use native PHPUnit functionality.

Follow-up to [38832].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51453 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-18 14:00:35 +00:00