From 514a3bed4a4b69d77ddfca6cfc6825c02e569147 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 24 Sep 2023 04:53:43 +0200 Subject: [PATCH 1/4] Tests: move mock acf class to `Doubles` directory --- .phpcs.xml.dist | 2 +- composer.json | 2 +- tests/php/unit/Dependencies/acf-dependency-test.php | 2 +- tests/php/unit/{Dependencies => Doubles}/acf.php | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename tests/php/unit/{Dependencies => Doubles}/acf.php (100%) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 5eba467f..6c4926b6 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -15,7 +15,7 @@ . tests/js/system/data/acf*\.php$ - tests/php/unit/Dependencies/acf\.php$ + tests/php/unit/Doubles/acf\.php$ diff --git a/composer.json b/composer.json index a681b3da..aaa90e67 100644 --- a/composer.json +++ b/composer.json @@ -64,7 +64,7 @@ "tests/js/system/data/test-data-loader-functions.php" ], "exclude-from-classmap": [ - "/tests/php/unit/Dependencies/acf.php" + "/tests/php/unit/Doubles/acf.php" ] }, "config": { diff --git a/tests/php/unit/Dependencies/acf-dependency-test.php b/tests/php/unit/Dependencies/acf-dependency-test.php index df50b554..b1f93678 100644 --- a/tests/php/unit/Dependencies/acf-dependency-test.php +++ b/tests/php/unit/Dependencies/acf-dependency-test.php @@ -31,7 +31,7 @@ public function testNoACFClassExists() { public function testACFClassExists() { $testee = new Yoast_ACF_Analysis_Dependency_ACF(); - require_once __DIR__ . \DIRECTORY_SEPARATOR . 'acf.php'; + require_once \dirname( __DIR__ ) . '/Doubles/acf.php'; $this->assertTrue( $testee->is_met() ); } diff --git a/tests/php/unit/Dependencies/acf.php b/tests/php/unit/Doubles/acf.php similarity index 100% rename from tests/php/unit/Dependencies/acf.php rename to tests/php/unit/Doubles/acf.php From a99d754114e71d1032b5e3af932d337920ed199a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 29 Sep 2023 15:29:33 +0200 Subject: [PATCH 2/4] Tests: move unit tests to `tests\Unit` subdirectory --- .phpcs.xml.dist | 11 +++++------ composer.json | 4 ++-- phpunit.xml.dist | 2 +- .../Configuration/configuration-test.php | 2 +- .../unit => Unit}/Configuration/string-store-test.php | 2 +- .../Dependencies/acf-dependency-test.php | 2 +- .../Dependencies/yoast-seo-dependency-test.php | 2 +- tests/{php/unit => Unit}/Doubles/acf.php | 0 .../{php/unit => Unit}/Doubles/failing-dependency.php | 2 +- .../{php/unit => Unit}/Doubles/passing-dependency.php | 2 +- tests/{php/unit => Unit}/assets-test.php | 2 +- tests/{php/unit => Unit}/main-test.php | 2 +- tests/{php/unit => Unit}/registry-test.php | 2 +- tests/{php/unit => Unit}/requirements-test.php | 6 +++--- 14 files changed, 20 insertions(+), 21 deletions(-) rename tests/{php/unit => Unit}/Configuration/configuration-test.php (99%) rename tests/{php/unit => Unit}/Configuration/string-store-test.php (98%) rename tests/{php/unit => Unit}/Dependencies/acf-dependency-test.php (95%) rename tests/{php/unit => Unit}/Dependencies/yoast-seo-dependency-test.php (97%) rename tests/{php/unit => Unit}/Doubles/acf.php (100%) rename tests/{php/unit => Unit}/Doubles/failing-dependency.php (91%) rename tests/{php/unit => Unit}/Doubles/passing-dependency.php (91%) rename tests/{php/unit => Unit}/assets-test.php (96%) rename tests/{php/unit => Unit}/main-test.php (95%) rename tests/{php/unit => Unit}/registry-test.php (97%) rename tests/{php/unit => Unit}/requirements-test.php (93%) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 6c4926b6..ee341a60 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -15,7 +15,7 @@ . tests/js/system/data/acf*\.php$ - tests/php/unit/Doubles/acf\.php$ + tests/Unit/Doubles/acf\.php$ @@ -84,11 +84,11 @@ - + - + @@ -113,8 +113,7 @@ - /integration-tests/bootstrap\.php$ - /tests/bootstrap\.php$ + /tests/Unit/bootstrap\.php$ @@ -139,7 +138,7 @@ by WPCS. This will most likely be fixed once PHPCS 3.5.0 has been released and WPCS has upgraded to that version. --> - /tests/php/unit/Dependencies/yoast-seo-dependency-test\.php$ + /tests/Unit/Dependencies/yoast-seo-dependency-test\.php$ diff --git a/composer.json b/composer.json index aaa90e67..d4cfff94 100644 --- a/composer.json +++ b/composer.json @@ -58,13 +58,13 @@ }, "autoload-dev": { "classmap": [ - "tests/php/unit" + "tests/Unit" ], "files": [ "tests/js/system/data/test-data-loader-functions.php" ], "exclude-from-classmap": [ - "/tests/php/unit/Doubles/acf.php" + "/tests/Unit/Doubles/acf.php" ] }, "config": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b4c56431..828e45d4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,7 +16,7 @@ > - tests/php/unit + tests/Unit diff --git a/tests/php/unit/Configuration/configuration-test.php b/tests/Unit/Configuration/configuration-test.php similarity index 99% rename from tests/php/unit/Configuration/configuration-test.php rename to tests/Unit/Configuration/configuration-test.php index c1b36c48..71841b3d 100644 --- a/tests/php/unit/Configuration/configuration-test.php +++ b/tests/Unit/Configuration/configuration-test.php @@ -1,6 +1,6 @@ Date: Thu, 2 Nov 2023 17:50:26 +0100 Subject: [PATCH 3/4] Tests: rename some mock classes ... to comply with the YoastCS naming conventions. These weren't being flagged so far as the tests are using a non-conventional directory layout. --- .phpcs.xml.dist | 8 ++++++++ ...ng-dependency.php => failing-dependency-mock.php} | 4 ++-- ...ng-dependency.php => passing-dependency-mock.php} | 4 ++-- tests/Unit/requirements-test.php | 12 ++++++------ 4 files changed, 18 insertions(+), 10 deletions(-) rename tests/Unit/Doubles/{failing-dependency.php => failing-dependency-mock.php} (78%) rename tests/Unit/Doubles/{passing-dependency.php => passing-dependency-mock.php} (78%) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index ee341a60..f55dd4a2 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -80,6 +80,14 @@ + + + + + + + + diff --git a/tests/Unit/Doubles/failing-dependency.php b/tests/Unit/Doubles/failing-dependency-mock.php similarity index 78% rename from tests/Unit/Doubles/failing-dependency.php rename to tests/Unit/Doubles/failing-dependency-mock.php index 74daee9a..a71d2826 100644 --- a/tests/Unit/Doubles/failing-dependency.php +++ b/tests/Unit/Doubles/failing-dependency-mock.php @@ -5,9 +5,9 @@ use Yoast_ACF_Analysis_Dependency; /** - * Class Failing_Dependency. + * Class Failing_Dependency_Mock. */ -class Failing_Dependency implements Yoast_ACF_Analysis_Dependency { +class Failing_Dependency_Mock implements Yoast_ACF_Analysis_Dependency { /** * Checks if this dependency is met. diff --git a/tests/Unit/Doubles/passing-dependency.php b/tests/Unit/Doubles/passing-dependency-mock.php similarity index 78% rename from tests/Unit/Doubles/passing-dependency.php rename to tests/Unit/Doubles/passing-dependency-mock.php index 3a34c257..ab064cd6 100644 --- a/tests/Unit/Doubles/passing-dependency.php +++ b/tests/Unit/Doubles/passing-dependency-mock.php @@ -5,9 +5,9 @@ use Yoast_ACF_Analysis_Dependency; /** - * Class Passing_Dependency. + * Class Passing_Dependency_Mock. */ -class Passing_Dependency implements Yoast_ACF_Analysis_Dependency { +class Passing_Dependency_Mock implements Yoast_ACF_Analysis_Dependency { /** * Checks if this dependency is met. diff --git a/tests/Unit/requirements-test.php b/tests/Unit/requirements-test.php index 201f3b5a..54e58599 100644 --- a/tests/Unit/requirements-test.php +++ b/tests/Unit/requirements-test.php @@ -3,8 +3,8 @@ namespace Yoast\WP\ACF\Tests\Unit; use Brain\Monkey\Functions; -use Yoast\WP\ACF\Tests\Unit\Doubles\Failing_Dependency; -use Yoast\WP\ACF\Tests\Unit\Doubles\Passing_Dependency; +use Yoast\WP\ACF\Tests\Unit\Doubles\Failing_Dependency_Mock; +use Yoast\WP\ACF\Tests\Unit\Doubles\Passing_Dependency_Mock; use Yoast\WPTestUtils\BrainMonkey\TestCase; use Yoast_ACF_Analysis_Requirements; @@ -44,7 +44,7 @@ public function testNoDependencies() { */ public function testPassingDependency() { $testee = new Yoast_ACF_Analysis_Requirements(); - $testee->add_dependency( new Passing_Dependency() ); + $testee->add_dependency( new Passing_Dependency_Mock() ); $this->assertTrue( $testee->are_met() ); } @@ -59,7 +59,7 @@ public function testPassingDependency() { */ public function testFailingDependency() { $testee = new Yoast_ACF_Analysis_Requirements(); - $testee->add_dependency( new Failing_Dependency() ); + $testee->add_dependency( new Failing_Dependency_Mock() ); $this->assertFalse( $testee->are_met() ); } @@ -74,8 +74,8 @@ public function testFailingDependency() { */ public function testMixedDependencies() { $testee = new Yoast_ACF_Analysis_Requirements(); - $testee->add_dependency( new Failing_Dependency() ); - $testee->add_dependency( new Passing_Dependency() ); + $testee->add_dependency( new Failing_Dependency_Mock() ); + $testee->add_dependency( new Passing_Dependency_Mock() ); $this->assertFalse( $testee->are_met() ); } From e34da0ee997c87a7ad5b90dba05f4d1ef341c74f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 29 Sep 2023 15:44:02 +0200 Subject: [PATCH 4/4] Tests: use PSR-4 * Ensure all test class names reflect the name of the class under test. * Ensure all test class file names match the name of the test class. * Change the Composer `autoload-dev` directive to use PSR-4 autoloading. * Update the `phpunit.xml.dist` file to match. * Update the `.phpcs.xml.dist` file to match. --- .phpcs.xml.dist | 9 +++++++-- composer.json | 9 +++------ phpunit.xml.dist | 2 +- tests/Unit/{assets-test.php => Assets_Test.php} | 0 .../{configuration-test.php => Configuration_Test.php} | 0 .../{string-store-test.php => String_Store_Test.php} | 0 .../{acf-dependency-test.php => Dependency_ACF_Test.php} | 4 ++-- ...dependency-test.php => Dependency_Yoast_SEO_Test.php} | 4 ++-- ...g-dependency-mock.php => Failing_Dependency_Mock.php} | 0 ...g-dependency-mock.php => Passing_Dependency_Mock.php} | 0 tests/Unit/{main-test.php => Main_Test.php} | 0 tests/Unit/{registry-test.php => Registry_Test.php} | 0 .../{requirements-test.php => Requirements_Test.php} | 0 13 files changed, 15 insertions(+), 13 deletions(-) rename tests/Unit/{assets-test.php => Assets_Test.php} (100%) rename tests/Unit/Configuration/{configuration-test.php => Configuration_Test.php} (100%) rename tests/Unit/Configuration/{string-store-test.php => String_Store_Test.php} (100%) rename tests/Unit/Dependencies/{acf-dependency-test.php => Dependency_ACF_Test.php} (93%) rename tests/Unit/Dependencies/{yoast-seo-dependency-test.php => Dependency_Yoast_SEO_Test.php} (96%) rename tests/Unit/Doubles/{failing-dependency-mock.php => Failing_Dependency_Mock.php} (100%) rename tests/Unit/Doubles/{passing-dependency-mock.php => Passing_Dependency_Mock.php} (100%) rename tests/Unit/{main-test.php => Main_Test.php} (100%) rename tests/Unit/{registry-test.php => Registry_Test.php} (100%) rename tests/Unit/{requirements-test.php => Requirements_Test.php} (100%) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index f55dd4a2..ff47fb41 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -90,7 +90,7 @@ - + @@ -146,7 +146,12 @@ by WPCS. This will most likely be fixed once PHPCS 3.5.0 has been released and WPCS has upgraded to that version. --> - /tests/Unit/Dependencies/yoast-seo-dependency-test\.php$ + /tests/Unit/Dependencies/Dependency_Yoast_SEO_Test\.php$ + + + + + /tests/Unit/*\.php$ diff --git a/composer.json b/composer.json index d4cfff94..4458af1a 100644 --- a/composer.json +++ b/composer.json @@ -57,14 +57,11 @@ ] }, "autoload-dev": { - "classmap": [ - "tests/Unit" - ], + "psr-4": { + "Yoast\\WP\\ACF\\Tests\\": "tests/" + }, "files": [ "tests/js/system/data/test-data-loader-functions.php" - ], - "exclude-from-classmap": [ - "/tests/Unit/Doubles/acf.php" ] }, "config": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 828e45d4..1d2b560a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,7 +16,7 @@ > - tests/Unit + tests/Unit diff --git a/tests/Unit/assets-test.php b/tests/Unit/Assets_Test.php similarity index 100% rename from tests/Unit/assets-test.php rename to tests/Unit/Assets_Test.php diff --git a/tests/Unit/Configuration/configuration-test.php b/tests/Unit/Configuration/Configuration_Test.php similarity index 100% rename from tests/Unit/Configuration/configuration-test.php rename to tests/Unit/Configuration/Configuration_Test.php diff --git a/tests/Unit/Configuration/string-store-test.php b/tests/Unit/Configuration/String_Store_Test.php similarity index 100% rename from tests/Unit/Configuration/string-store-test.php rename to tests/Unit/Configuration/String_Store_Test.php diff --git a/tests/Unit/Dependencies/acf-dependency-test.php b/tests/Unit/Dependencies/Dependency_ACF_Test.php similarity index 93% rename from tests/Unit/Dependencies/acf-dependency-test.php rename to tests/Unit/Dependencies/Dependency_ACF_Test.php index 0e754daa..727d5d4b 100644 --- a/tests/Unit/Dependencies/acf-dependency-test.php +++ b/tests/Unit/Dependencies/Dependency_ACF_Test.php @@ -6,11 +6,11 @@ use Yoast_ACF_Analysis_Dependency_ACF; /** - * Class ACF_Dependency_Test. + * Class Dependency_ACF_Test. * * @covers Yoast_ACF_Analysis_Dependency_ACF */ -class ACF_Dependency_Test extends TestCase { +class Dependency_ACF_Test extends TestCase { /** * Tests the situation where no ACF class exists. diff --git a/tests/Unit/Dependencies/yoast-seo-dependency-test.php b/tests/Unit/Dependencies/Dependency_Yoast_SEO_Test.php similarity index 96% rename from tests/Unit/Dependencies/yoast-seo-dependency-test.php rename to tests/Unit/Dependencies/Dependency_Yoast_SEO_Test.php index b6568b15..5b1db4a2 100644 --- a/tests/Unit/Dependencies/yoast-seo-dependency-test.php +++ b/tests/Unit/Dependencies/Dependency_Yoast_SEO_Test.php @@ -6,11 +6,11 @@ use Yoast_ACF_Analysis_Dependency_Yoast_SEO; /** - * Class Yoast_SEO_Dependency_Test. + * Class Dependency_Yoast_SEO_Test. * * @covers Yoast_ACF_Analysis_Dependency_Yoast_SEO */ -class Yoast_SEO_Dependency_Test extends TestCase { +class Dependency_Yoast_SEO_Test extends TestCase { /** * Whether or not to preserve the global state. diff --git a/tests/Unit/Doubles/failing-dependency-mock.php b/tests/Unit/Doubles/Failing_Dependency_Mock.php similarity index 100% rename from tests/Unit/Doubles/failing-dependency-mock.php rename to tests/Unit/Doubles/Failing_Dependency_Mock.php diff --git a/tests/Unit/Doubles/passing-dependency-mock.php b/tests/Unit/Doubles/Passing_Dependency_Mock.php similarity index 100% rename from tests/Unit/Doubles/passing-dependency-mock.php rename to tests/Unit/Doubles/Passing_Dependency_Mock.php diff --git a/tests/Unit/main-test.php b/tests/Unit/Main_Test.php similarity index 100% rename from tests/Unit/main-test.php rename to tests/Unit/Main_Test.php diff --git a/tests/Unit/registry-test.php b/tests/Unit/Registry_Test.php similarity index 100% rename from tests/Unit/registry-test.php rename to tests/Unit/Registry_Test.php diff --git a/tests/Unit/requirements-test.php b/tests/Unit/Requirements_Test.php similarity index 100% rename from tests/Unit/requirements-test.php rename to tests/Unit/Requirements_Test.php