From 18acdb68f59a7b1a631bbe5babb00f60c1c4a0ac Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 3 Sep 2022 14:45:20 +0000 Subject: [PATCH] Tests: Restore `@covers` tags for PHP polyfill tests in `phpunit/tests/compat/`. These tags were previously removed to avoid notices when generating the code coverage report on PHP versions where these functions are natively available and not user-defined: {{{ "@covers ::array_key_first" is invalid "@covers ::array_key_last" is invalid "@covers ::hash_hmac" is invalid "@covers ::is_countable" is invalid "@covers ::is_iterable" is invalid "@covers ::mb_strlen" is invalid "@covers ::mb_substr" is invalid "@covers ::str_contains" is invalid "@covers ::str_ends_with" is invalid "@covers ::str_starts_with" is invalid }}} It has been pointed out that those tests do cover the WP implementation of those functions and should be marked as such with a `@covers` tag. The reason PHPUnit displays notices about it, is that code coverage is only run on PHP 7.4 instead of multiple PHP versions. For those PHP versions which don't natively contain the function, the WP polyfill is being tested and should be seen as covered by tests. The reason the tests are also run on PHP versions in which the function already exists in PHP natively, is to make sure that the polyfill test expectations line up with the PHP native behaviour, even though at that point, they are no longer testing the WP polyfill, but the PHP native function. With the above in mind, while those PHPUnit notices add some noise to the code coverage report, in this case, they should be ignored and the `@covers` tags should be brought back. As a potential future enhancement, the code coverage script could be updated to run against the highest and lowest supported PHP versions and with some variations of extensions enabled or disabled to ensure those tests actually test the polyfills. Follow-up to [51852], [52038], [52039], [52040], [54049], [54060]. Props jrf. See #39265, #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@54064 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/compat/arrayKeyFirst.php | 2 +- tests/phpunit/tests/compat/arrayKeyLast.php | 2 +- tests/phpunit/tests/compat/hashHmac.php | 1 + tests/phpunit/tests/compat/isCountable.php | 2 +- tests/phpunit/tests/compat/isIterable.php | 2 +- tests/phpunit/tests/compat/mbStrlen.php | 1 + tests/phpunit/tests/compat/mbSubstr.php | 1 + tests/phpunit/tests/compat/strContains.php | 2 +- tests/phpunit/tests/compat/strEndsWith.php | 2 +- tests/phpunit/tests/compat/strStartsWith.php | 2 +- 10 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/tests/compat/arrayKeyFirst.php b/tests/phpunit/tests/compat/arrayKeyFirst.php index 2feae8e250..613845aba0 100644 --- a/tests/phpunit/tests/compat/arrayKeyFirst.php +++ b/tests/phpunit/tests/compat/arrayKeyFirst.php @@ -3,7 +3,7 @@ /** * @group compat * - * @coversNothing + * @covers ::array_key_first */ class Tests_Compat_arrayKeyFirst extends WP_UnitTestCase { diff --git a/tests/phpunit/tests/compat/arrayKeyLast.php b/tests/phpunit/tests/compat/arrayKeyLast.php index c41e05ca0f..77510c8320 100644 --- a/tests/phpunit/tests/compat/arrayKeyLast.php +++ b/tests/phpunit/tests/compat/arrayKeyLast.php @@ -3,7 +3,7 @@ /** * @group compat * - * @coversNothing + * @covers ::array_key_last */ class Tests_Compat_ArrayKeyLast extends WP_UnitTestCase { diff --git a/tests/phpunit/tests/compat/hashHmac.php b/tests/phpunit/tests/compat/hashHmac.php index 81053b043b..f9a61d5fac 100644 --- a/tests/phpunit/tests/compat/hashHmac.php +++ b/tests/phpunit/tests/compat/hashHmac.php @@ -3,6 +3,7 @@ /** * @group compat * + * @covers ::hash_hmac * @covers ::_hash_hmac */ class Tests_Compat_hashHmac extends WP_UnitTestCase { diff --git a/tests/phpunit/tests/compat/isCountable.php b/tests/phpunit/tests/compat/isCountable.php index e533cd7afa..66bf3c8c6c 100644 --- a/tests/phpunit/tests/compat/isCountable.php +++ b/tests/phpunit/tests/compat/isCountable.php @@ -3,7 +3,7 @@ /** * @group compat * - * @coversNothing + * @covers ::is_countable */ class Tests_Compat_isCountable extends WP_UnitTestCase { diff --git a/tests/phpunit/tests/compat/isIterable.php b/tests/phpunit/tests/compat/isIterable.php index e78b7c3913..e09bb18278 100644 --- a/tests/phpunit/tests/compat/isIterable.php +++ b/tests/phpunit/tests/compat/isIterable.php @@ -3,7 +3,7 @@ /** * @group compat * - * @coversNothing + * @covers ::is_iterable */ class Tests_Compat_isIterable extends WP_UnitTestCase { diff --git a/tests/phpunit/tests/compat/mbStrlen.php b/tests/phpunit/tests/compat/mbStrlen.php index 39117abb87..e34b44534b 100644 --- a/tests/phpunit/tests/compat/mbStrlen.php +++ b/tests/phpunit/tests/compat/mbStrlen.php @@ -4,6 +4,7 @@ * @group compat * @group security-153 * + * @covers ::mb_strlen * @covers ::_mb_strlen */ class Tests_Compat_mbStrlen extends WP_UnitTestCase { diff --git a/tests/phpunit/tests/compat/mbSubstr.php b/tests/phpunit/tests/compat/mbSubstr.php index 142459dd78..f03f5f0f19 100644 --- a/tests/phpunit/tests/compat/mbSubstr.php +++ b/tests/phpunit/tests/compat/mbSubstr.php @@ -4,6 +4,7 @@ * @group compat * @group security-153 * + * @covers ::mb_substr * @covers ::_mb_substr */ class Tests_Compat_mbSubstr extends WP_UnitTestCase { diff --git a/tests/phpunit/tests/compat/strContains.php b/tests/phpunit/tests/compat/strContains.php index 6a794851d7..c49cb19f23 100644 --- a/tests/phpunit/tests/compat/strContains.php +++ b/tests/phpunit/tests/compat/strContains.php @@ -3,7 +3,7 @@ /** * @group compat * - * @coversNothing + * @covers ::str_contains */ class Tests_Compat_strContains extends WP_UnitTestCase { diff --git a/tests/phpunit/tests/compat/strEndsWith.php b/tests/phpunit/tests/compat/strEndsWith.php index 18f9d6f824..75522d6f49 100644 --- a/tests/phpunit/tests/compat/strEndsWith.php +++ b/tests/phpunit/tests/compat/strEndsWith.php @@ -3,7 +3,7 @@ /** * @group compat * - * @coversNothing + * @covers ::str_ends_with */ class Tests_Compat_StrEndsWith extends WP_UnitTestCase { diff --git a/tests/phpunit/tests/compat/strStartsWith.php b/tests/phpunit/tests/compat/strStartsWith.php index cbe926c662..9e12ced33b 100644 --- a/tests/phpunit/tests/compat/strStartsWith.php +++ b/tests/phpunit/tests/compat/strStartsWith.php @@ -3,7 +3,7 @@ /** * @group compat * - * @coversNothing + * @covers ::str_starts_with */ class Tests_Compat_StrStartsWith extends WP_UnitTestCase {