From 4a702d2cc28a78fbab828f7dab08cdfd13618d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Ceslav=20Przywara?= Date: Fri, 1 Mar 2024 19:24:18 +0100 Subject: [PATCH] Make integration tests run on PHPUnit 10 --- tests/integration/phpunit.xml | 10 +--------- .../src/Cases/Helpers/HaveIBeenPwnedTest.php | 9 ++++----- tests/integration/src/Cases/Helpers/IsTest.php | 2 +- tests/integration/src/Cases/Helpers/UtilsTest.php | 2 +- tests/integration/src/Cases/Modules/Cron/JobTest.php | 2 +- .../Cases/Modules/ExternalBlocklist/ManagerTest.php | 6 +++--- .../src/Cases/Modules/Hardening/ActiveTest.php | 6 +++--- .../src/Cases/Modules/Hardening/InactiveTest.php | 6 +++--- .../src/Cases/Modules/Login/GatekeeperTest.php | 2 +- tests/integration/src/TestCase.php | 11 +++++++++++ 10 files changed, 29 insertions(+), 27 deletions(-) diff --git a/tests/integration/phpunit.xml b/tests/integration/phpunit.xml index 91e8477..3670e5f 100644 --- a/tests/integration/phpunit.xml +++ b/tests/integration/phpunit.xml @@ -1,13 +1,5 @@ - + ./src/Cases diff --git a/tests/integration/src/Cases/Helpers/HaveIBeenPwnedTest.php b/tests/integration/src/Cases/Helpers/HaveIBeenPwnedTest.php index af1856b..5d7bd05 100644 --- a/tests/integration/src/Cases/Helpers/HaveIBeenPwnedTest.php +++ b/tests/integration/src/Cases/Helpers/HaveIBeenPwnedTest.php @@ -7,19 +7,19 @@ use BlueChip\Security\Helpers\HaveIBeenPwned; use BlueChip\Security\Tests\Integration\Constants; use BlueChip\Security\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\Group; /** * Test integration with Pwned Passwords API. * * @internal These tests result in external requests to https://api.pwnedpasswords.com being made! */ -class HaveIBeenPwnedTest extends TestCase +final class HaveIBeenPwnedTest extends TestCase { /** * Test that pwned password is reported as such. - * - * @group external */ + #[Group('external')] public function testPwnedPassword() { $result = HaveIBeenPwned::hasPasswordBeenPwned(Constants::PWNED_PASSWORD); @@ -35,9 +35,8 @@ public function testPwnedPassword() /** * Test that safe password is reported as such. - * - * @group external */ + #[Group('external')] public function testSafePassword() { $result = HaveIBeenPwned::hasPasswordBeenPwned(Constants::SAFE_PASSWORD); diff --git a/tests/integration/src/Cases/Helpers/IsTest.php b/tests/integration/src/Cases/Helpers/IsTest.php index 6f298b3..d8ab84f 100644 --- a/tests/integration/src/Cases/Helpers/IsTest.php +++ b/tests/integration/src/Cases/Helpers/IsTest.php @@ -8,7 +8,7 @@ use BlueChip\Security\Helpers\Is; use BlueChip\Security\Tests\Integration\TestCase; -class IsTest extends TestCase +final class IsTest extends TestCase { /** * Test Is::admin() method and `bc-security/filter:is-admin` filter. diff --git a/tests/integration/src/Cases/Helpers/UtilsTest.php b/tests/integration/src/Cases/Helpers/UtilsTest.php index d8910e4..f8b200c 100644 --- a/tests/integration/src/Cases/Helpers/UtilsTest.php +++ b/tests/integration/src/Cases/Helpers/UtilsTest.php @@ -7,7 +7,7 @@ use BlueChip\Security\Helpers\Utils; use BlueChip\Security\Tests\Integration\TestCase; -class UtilsTest extends TestCase +final class UtilsTest extends TestCase { /** * Ensure that blocking access results in wp_die() being called with proper response code. diff --git a/tests/integration/src/Cases/Modules/Cron/JobTest.php b/tests/integration/src/Cases/Modules/Cron/JobTest.php index 0498394..ce66e19 100644 --- a/tests/integration/src/Cases/Modules/Cron/JobTest.php +++ b/tests/integration/src/Cases/Modules/Cron/JobTest.php @@ -7,7 +7,7 @@ use BlueChip\Security\Modules\Cron; use BlueChip\Security\Tests\Integration\TestCase; -class JobTest extends TestCase +final class JobTest extends TestCase { private const HOOK = 'test-job'; diff --git a/tests/integration/src/Cases/Modules/ExternalBlocklist/ManagerTest.php b/tests/integration/src/Cases/Modules/ExternalBlocklist/ManagerTest.php index 63833b3..f0c5fed 100644 --- a/tests/integration/src/Cases/Modules/ExternalBlocklist/ManagerTest.php +++ b/tests/integration/src/Cases/Modules/ExternalBlocklist/ManagerTest.php @@ -12,13 +12,14 @@ use BlueChip\Security\Setup\IpAddress; use BlueChip\Security\Tests\Integration\Constants; use BlueChip\Security\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\Group; /** * Test integration of external blocklists. * * @internal These tests result in external requests! */ -class ManagerTest extends TestCase +final class ManagerTest extends TestCase { protected function prepareTest(): void { @@ -32,9 +33,8 @@ protected function prepareTest(): void /** * Test external blocklist populated with IP prefixes for Amazon Web Services. - * - * @group external */ + #[Group('external')] public function testAmazonWebServicesBlocklist() { // Refresh external blocklist. diff --git a/tests/integration/src/Cases/Modules/Hardening/ActiveTest.php b/tests/integration/src/Cases/Modules/Hardening/ActiveTest.php index 5c099d4..aab5b84 100644 --- a/tests/integration/src/Cases/Modules/Hardening/ActiveTest.php +++ b/tests/integration/src/Cases/Modules/Hardening/ActiveTest.php @@ -5,11 +5,12 @@ namespace BlueChip\Security\Tests\Integration\Cases\Modules\Hardening; use BlueChip\Security\Tests\Integration\Constants; +use PHPUnit\Framework\Attributes\Group; /** * Test hardening with all options on. */ -class ActiveTest extends TestCase +final class ActiveTest extends TestCase { protected function prepareTest(): void { @@ -40,9 +41,8 @@ public function testHardeningActive(): void /** * Test user editation with password change. - * - * @group external */ + #[Group('external')] public function testPasswordChange(): void { // Test strong password - should pass. diff --git a/tests/integration/src/Cases/Modules/Hardening/InactiveTest.php b/tests/integration/src/Cases/Modules/Hardening/InactiveTest.php index 895da35..47fef52 100644 --- a/tests/integration/src/Cases/Modules/Hardening/InactiveTest.php +++ b/tests/integration/src/Cases/Modules/Hardening/InactiveTest.php @@ -5,11 +5,12 @@ namespace BlueChip\Security\Tests\Integration\Cases\Modules\Hardening; use BlueChip\Security\Tests\Integration\Constants; +use PHPUnit\Framework\Attributes\Group; /** * Test hardening with all options off. */ -class InactiveTest extends TestCase +final class InactiveTest extends TestCase { protected function prepareTest(): void { @@ -40,9 +41,8 @@ public function testHardeningInactive(): void /** * Test user editation with password change. - * - * @group external */ + #[Group('external')] public function testPasswordChange(): void { // Test strong password - should pass. diff --git a/tests/integration/src/Cases/Modules/Login/GatekeeperTest.php b/tests/integration/src/Cases/Modules/Login/GatekeeperTest.php index f1d84ae..d0cbd25 100644 --- a/tests/integration/src/Cases/Modules/Login/GatekeeperTest.php +++ b/tests/integration/src/Cases/Modules/Login/GatekeeperTest.php @@ -9,7 +9,7 @@ use BlueChip\Security\Tests\Integration\Constants; use BlueChip\Security\Tests\Integration\TestCase; -class GatekeeperTest extends TestCase +final class GatekeeperTest extends TestCase { /** * @internal WP test suite already includes user with username `admin`, so there is no need to explicitly create it. diff --git a/tests/integration/src/TestCase.php b/tests/integration/src/TestCase.php index 7b33381..d0381fd 100644 --- a/tests/integration/src/TestCase.php +++ b/tests/integration/src/TestCase.php @@ -11,6 +11,17 @@ */ abstract class TestCase extends \WP_UnitTestCase { + /** + * @internal Overriding this method from \WP_UnitTestCase_Base class allows our tests to run on PHPUnit 10. + * + * @link https://core.trac.wordpress.org/ticket/59486#comment:6 + */ + public function expectDeprecated(): void + { + return; + } + + /** * Allow to load the plugin with context customised for particular test suite. */