From 1c150e6d064738a52cf9942e287615ab58f19ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 14 Aug 2026 12:04:22 -0400 Subject: [PATCH] Move production files under src/ directory Reorganize the library's production code (autoloaded classes, traits, bootstrap helpers, and the built-in Unit/Integration/Fixtures) under a dedicated `src/` directory to clearly separate shipped code from the package's own test suite, tooling, and configuration. Updated configuration and path references to follow the move: - composer.json: PSR-4 `WPMedia\PHPUnit\` now maps to `src/`; added an autoload-dev PSR-4 mapping for the `WPMedia\PHPUnit\Tests\` namespace. - wpmedia-phpunit: require `src/BootstrapManager.php`. - BootstrapManager: adjust __DIR__-based resolution of the consumer's vendor/bin/phpunit and root directory for the extra directory level. - src/{Unit,Integration}/phpunit.xml.dist: bump the relative Tests paths by one level. - Tests/{Unit,Integration}/init-tests.php: require the bootstrap from `src/`. - phpstan.neon.dist / phpstan-baseline.neon / phpcs.xml.dist: point the analyzed paths at `src/`. Verified: unit suite (95 tests, 297 assertions), PHPCS and PHPStan all pass. Co-Authored-By: Claude Opus 4.8 --- Tests/Integration/init-tests.php | 2 +- Tests/Unit/init-tests.php | 2 +- composer.json | 3 +- phpcs.xml.dist | 6 +- phpstan-baseline.neon | 64 +++++++++---------- phpstan.neon.dist | 18 +++--- ArrayTrait.php => src/ArrayTrait.php | 0 .../BootstrapManager.php | 6 +- {Fixtures => src/Fixtures}/polyfills.php | 0 .../Integration}/AdminTestCase.php | 0 .../Integration}/AjaxTestCase.php | 0 {Integration => src/Integration}/ApiTrait.php | 0 .../Integration}/HttpRequestTrait.php | 0 .../Integration}/RESTTrait.php | 0 .../Integration}/RESTVfsTestCase.php | 0 .../Integration}/RESTfulTestCase.php | 0 {Integration => src/Integration}/TestCase.php | 0 .../VirtualFilesystemTestCase.php | 0 .../Integration}/bootstrap.php | 0 .../Integration}/phpunit.xml.dist | 4 +- TestCaseTrait.php => src/TestCaseTrait.php | 0 {Unit => src/Unit}/TestCase.php | 0 .../Unit}/VirtualFilesystemTestCase.php | 0 {Unit => src/Unit}/bootstrap.php | 0 {Unit => src/Unit}/phpunit.xml.dist | 4 +- .../VirtualFilesystemDirect.php | 0 .../VirtualFilesystemTestTrait.php | 0 .../bootstrap-functions.php | 0 wpmedia-phpunit | 2 +- 29 files changed, 56 insertions(+), 55 deletions(-) rename ArrayTrait.php => src/ArrayTrait.php (100%) rename BootstrapManager.php => src/BootstrapManager.php (95%) rename {Fixtures => src/Fixtures}/polyfills.php (100%) rename {Integration => src/Integration}/AdminTestCase.php (100%) rename {Integration => src/Integration}/AjaxTestCase.php (100%) rename {Integration => src/Integration}/ApiTrait.php (100%) rename {Integration => src/Integration}/HttpRequestTrait.php (100%) rename {Integration => src/Integration}/RESTTrait.php (100%) rename {Integration => src/Integration}/RESTVfsTestCase.php (100%) rename {Integration => src/Integration}/RESTfulTestCase.php (100%) rename {Integration => src/Integration}/TestCase.php (100%) rename {Integration => src/Integration}/VirtualFilesystemTestCase.php (100%) rename {Integration => src/Integration}/bootstrap.php (100%) rename {Integration => src/Integration}/phpunit.xml.dist (83%) rename TestCaseTrait.php => src/TestCaseTrait.php (100%) rename {Unit => src/Unit}/TestCase.php (100%) rename {Unit => src/Unit}/VirtualFilesystemTestCase.php (100%) rename {Unit => src/Unit}/bootstrap.php (100%) rename {Unit => src/Unit}/phpunit.xml.dist (84%) rename VirtualFilesystemDirect.php => src/VirtualFilesystemDirect.php (100%) rename VirtualFilesystemTestTrait.php => src/VirtualFilesystemTestTrait.php (100%) rename bootstrap-functions.php => src/bootstrap-functions.php (100%) diff --git a/Tests/Integration/init-tests.php b/Tests/Integration/init-tests.php index df07cd6..7e2de5b 100644 --- a/Tests/Integration/init-tests.php +++ b/Tests/Integration/init-tests.php @@ -6,4 +6,4 @@ define( 'WPMEDIA_PHPUNIT_ROOT_DIR', dirname( dirname( __DIR__ ) ) ); define( 'WPMEDIA_PHPUNIT_ROOT_TEST_DIR', __DIR__ ); -require_once WPMEDIA_PHPUNIT_ROOT_DIR . '/Integration/bootstrap.php'; \ No newline at end of file +require_once WPMEDIA_PHPUNIT_ROOT_DIR . '/src/Integration/bootstrap.php'; \ No newline at end of file diff --git a/Tests/Unit/init-tests.php b/Tests/Unit/init-tests.php index 3fa337b..42e081f 100644 --- a/Tests/Unit/init-tests.php +++ b/Tests/Unit/init-tests.php @@ -6,4 +6,4 @@ define( 'WPMEDIA_PHPUNIT_ROOT_DIR', dirname( dirname( __DIR__ ) ) ); define( 'WPMEDIA_PHPUNIT_ROOT_TEST_DIR', __DIR__ ); -require_once WPMEDIA_PHPUNIT_ROOT_DIR . '/Unit/bootstrap.php'; \ No newline at end of file +require_once WPMEDIA_PHPUNIT_ROOT_DIR . '/src/Unit/bootstrap.php'; \ No newline at end of file diff --git a/composer.json b/composer.json index baa9325..d099d8a 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,10 @@ "yoast/wp-test-utils": "^1.0.0" }, "autoload": { - "psr-4": { "WPMedia\\PHPUnit\\": "." } + "psr-4": { "WPMedia\\PHPUnit\\": "src/" } }, "autoload-dev": { + "psr-4": { "WPMedia\\PHPUnit\\Tests\\": "Tests/" }, "files": [ "vendor/antecedent/patchwork/Patchwork.php" ] diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 3286c3e..9cc0e68 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -8,10 +8,10 @@ (see issue #39). A job that only `uses:` a reusable workflow cannot carry `continue-on-error`, so the ruleset is scoped instead of failing CI on the ~20 pre-existing files that have not been touched yet. Add files here as they are brought up to standard - opportunistically, and widen this to the full source tree (the six root files plus - Integration/, Unit/, Fixtures/, Tests/) once the codebase is fully compliant. + opportunistically, and widen this to the full source tree (src/ plus Tests/) once the + codebase is fully compliant. --> - Integration/HttpRequestTrait.php + src/Integration/HttpRequestTrait.php vendor/* diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4f28f85..53298e5 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4,103 +4,103 @@ parameters: rawMessage: Offset 'WPMEDIA_PHPUNIT_ROOT_DIR' does not exist on string. identifier: offsetAccess.notFound count: 1 - path: BootstrapManager.php + path: src/BootstrapManager.php - rawMessage: 'Parameter #1 $root of static method WPMedia\PHPUnit\BootstrapManager::getRootDir() expects string, array|bool given.' identifier: argument.type count: 1 - path: BootstrapManager.php + path: src/BootstrapManager.php - rawMessage: 'Strict comparison using === between false and string will always evaluate to false.' identifier: identical.alwaysFalse count: 1 - path: BootstrapManager.php + path: src/BootstrapManager.php - rawMessage: 'Call to WPMedia\PHPUnit\Integration\AdminTestCase::initBeforeClass() on a separate line has no effect.' identifier: staticMethod.resultUnused count: 1 - path: Integration/AdminTestCase.php + path: src/Integration/AdminTestCase.php - rawMessage: Constant AUTH_COOKIE not found. identifier: constant.notFound count: 1 - path: Integration/AdminTestCase.php + path: src/Integration/AdminTestCase.php - rawMessage: Constant LOGGED_IN_COOKIE not found. identifier: constant.notFound count: 1 - path: Integration/AdminTestCase.php + path: src/Integration/AdminTestCase.php - rawMessage: Constant PASS_COOKIE not found. identifier: constant.notFound count: 1 - path: Integration/AdminTestCase.php + path: src/Integration/AdminTestCase.php - rawMessage: Constant SECURE_AUTH_COOKIE not found. identifier: constant.notFound count: 1 - path: Integration/AdminTestCase.php + path: src/Integration/AdminTestCase.php - rawMessage: Constant USER_COOKIE not found. identifier: constant.notFound count: 1 - path: Integration/AdminTestCase.php + path: src/Integration/AdminTestCase.php - rawMessage: 'Method WPMedia\PHPUnit\Integration\AjaxTestCase::getApiCredential() should return string but returns bool.' identifier: return.type count: 1 - path: Integration/AjaxTestCase.php + path: src/Integration/AjaxTestCase.php - rawMessage: 'Class WP_REST_Request referenced with incorrect case: WP_Rest_Request.' identifier: class.nameCase count: 1 - path: Integration/RESTTrait.php + path: src/Integration/RESTTrait.php - rawMessage: 'Class WP_REST_Request referenced with incorrect case: WP_Rest_Request.' identifier: class.nameCase count: 1 - path: Integration/RESTVfsTestCase.php + path: src/Integration/RESTVfsTestCase.php - rawMessage: Variable $wp_rest_server in PHPDoc tag @var does not exist. identifier: varTag.variableNotFound count: 1 - path: Integration/RESTVfsTestCase.php + path: src/Integration/RESTVfsTestCase.php - rawMessage: 'Class WP_REST_Request referenced with incorrect case: WP_Rest_Request.' identifier: class.nameCase count: 1 - path: Integration/RESTfulTestCase.php + path: src/Integration/RESTfulTestCase.php - rawMessage: 'Method WPMedia\PHPUnit\Integration\RESTfulTestCase::getApiCredential() should return string but returns bool.' identifier: return.type count: 1 - path: Integration/RESTfulTestCase.php + path: src/Integration/RESTfulTestCase.php - rawMessage: Variable $wp_rest_server in PHPDoc tag @var does not exist. identifier: varTag.variableNotFound count: 1 - path: Integration/RESTfulTestCase.php + path: src/Integration/RESTfulTestCase.php - rawMessage: Constant WPMEDIA_PHPUNIT_ROOT_DIR not found. identifier: constant.notFound count: 1 - path: Integration/bootstrap.php + path: src/Integration/bootstrap.php - rawMessage: Constant WPMEDIA_PHPUNIT_ROOT_DIR not found. @@ -178,88 +178,88 @@ parameters: rawMessage: 'Call to function is_array() with array will always evaluate to true.' identifier: function.alreadyNarrowedType count: 1 - path: Unit/VirtualFilesystemTestCase.php + path: src/Unit/VirtualFilesystemTestCase.php - rawMessage: 'Call to function is_null() with string will always evaluate to false.' identifier: function.impossibleType count: 2 - path: Unit/VirtualFilesystemTestCase.php + path: src/Unit/VirtualFilesystemTestCase.php - rawMessage: Constant WPMEDIA_PHPUNIT_ROOT_DIR not found. identifier: constant.notFound count: 1 - path: Unit/bootstrap.php + path: src/Unit/bootstrap.php - rawMessage: Binary operation "+" between non-empty-string and non-empty-string results in an error. identifier: binaryOp.invalid count: 3 - path: VirtualFilesystemDirect.php + path: src/VirtualFilesystemDirect.php - rawMessage: 'Call to function is_null() with bool|org\bovigo\vfs\vfsStreamFile will always evaluate to false.' identifier: function.impossibleType count: 1 - path: VirtualFilesystemDirect.php + path: src/VirtualFilesystemDirect.php - rawMessage: 'Call to function is_string() with string will always evaluate to true.' identifier: function.alreadyNarrowedType count: 1 - path: VirtualFilesystemDirect.php + path: src/VirtualFilesystemDirect.php - rawMessage: Instanceof between org\bovigo\vfs\vfsStreamDirectory and org\bovigo\vfs\vfsStreamDirectory will always evaluate to true. identifier: instanceof.alwaysTrue count: 1 - path: VirtualFilesystemDirect.php + path: src/VirtualFilesystemDirect.php - rawMessage: 'Method WPMedia\PHPUnit\VirtualFilesystemDirect::getDir() should return org\bovigo\vfs\vfsStreamDirectory|null but returns org\bovigo\vfs\vfsStreamContent.' identifier: return.type count: 1 - path: VirtualFilesystemDirect.php + path: src/VirtualFilesystemDirect.php - rawMessage: 'Method WPMedia\PHPUnit\VirtualFilesystemDirect::getFile() should return org\bovigo\vfs\vfsStreamFile|null but returns org\bovigo\vfs\vfsStreamContent.' identifier: return.type count: 1 - path: VirtualFilesystemDirect.php + path: src/VirtualFilesystemDirect.php - rawMessage: 'Method WPMedia\PHPUnit\VirtualFilesystemDirect::getnumchmodfromh() should return int but returns string.' identifier: return.type count: 1 - path: VirtualFilesystemDirect.php + path: src/VirtualFilesystemDirect.php - rawMessage: 'Method WPMedia\PHPUnit\VirtualFilesystemDirect::setFilemtime() should return int but returns null.' identifier: return.type count: 1 - path: VirtualFilesystemDirect.php + path: src/VirtualFilesystemDirect.php - rawMessage: 'PHPDoc tag @param references unknown parameter: $filectime' identifier: parameter.notFound count: 1 - path: VirtualFilesystemDirect.php + path: src/VirtualFilesystemDirect.php - rawMessage: 'Property WPMedia\PHPUnit\VirtualFilesystemDirect::$filesystem (org\bovigo\vfs\vfsStreamDirectory) does not accept null.' identifier: assign.propertyType count: 1 - path: VirtualFilesystemDirect.php + path: src/VirtualFilesystemDirect.php - rawMessage: 'Property WPMedia\PHPUnit\VirtualFilesystemDirect::$root (string) does not accept null.' identifier: assign.propertyType count: 1 - path: VirtualFilesystemDirect.php + path: src/VirtualFilesystemDirect.php - rawMessage: Constant WPMEDIA_PHPUNIT_ROOT_DIR not found. identifier: constant.notFound count: 3 - path: bootstrap-functions.php + path: src/bootstrap-functions.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 7de0661..2080dd3 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -5,15 +5,15 @@ parameters: level: 5 inferPrivatePropertyTypeFromConstructor: true paths: - - ArrayTrait.php - - BootstrapManager.php - - TestCaseTrait.php - - VirtualFilesystemDirect.php - - VirtualFilesystemTestTrait.php - - bootstrap-functions.php - - Integration/ - - Unit/ - - Fixtures/ + - src/ArrayTrait.php + - src/BootstrapManager.php + - src/TestCaseTrait.php + - src/VirtualFilesystemDirect.php + - src/VirtualFilesystemTestTrait.php + - src/bootstrap-functions.php + - src/Integration/ + - src/Unit/ + - src/Fixtures/ - Tests/ scanFiles: - vendor/php-stubs/wordpress-stubs/wordpress-stubs.php diff --git a/ArrayTrait.php b/src/ArrayTrait.php similarity index 100% rename from ArrayTrait.php rename to src/ArrayTrait.php diff --git a/BootstrapManager.php b/src/BootstrapManager.php similarity index 95% rename from BootstrapManager.php rename to src/BootstrapManager.php index 26a4d57..d43ece9 100644 --- a/BootstrapManager.php +++ b/src/BootstrapManager.php @@ -16,7 +16,7 @@ public static function runTestSuite( $which_testsuite ) { $_SERVER['argc'] = $GLOBALS['argc'] = count( $GLOBALS['argv'] ); // Find and load PHPUnit. - foreach ( [ dirname( dirname( __DIR__ ) ), __DIR__ . '/vendor' ] as $root ) { + foreach ( [ dirname( dirname( dirname( __DIR__ ) ) ), dirname( __DIR__ ) . '/vendor' ] as $root ) { if ( is_readable( "{$root}/bin/phpunit" ) ) { require_once "{$root}/bin/phpunit"; return; @@ -179,11 +179,11 @@ protected static function getArg( $key ) { */ protected static function getRootDir( $root ) { if ( false === $root ) { - return dirname( dirname( dirname( __DIR__ ) ) ); + return dirname( dirname( dirname( dirname( __DIR__ ) ) ) ); } if ( '.' === $root['WPMEDIA_PHPUNIT_ROOT_DIR'] ) { - return __DIR__; + return dirname( __DIR__ ); } return ltrim( $root['WPMEDIA_PHPUNIT_ROOT_DIR'], '/\\' ); diff --git a/Fixtures/polyfills.php b/src/Fixtures/polyfills.php similarity index 100% rename from Fixtures/polyfills.php rename to src/Fixtures/polyfills.php diff --git a/Integration/AdminTestCase.php b/src/Integration/AdminTestCase.php similarity index 100% rename from Integration/AdminTestCase.php rename to src/Integration/AdminTestCase.php diff --git a/Integration/AjaxTestCase.php b/src/Integration/AjaxTestCase.php similarity index 100% rename from Integration/AjaxTestCase.php rename to src/Integration/AjaxTestCase.php diff --git a/Integration/ApiTrait.php b/src/Integration/ApiTrait.php similarity index 100% rename from Integration/ApiTrait.php rename to src/Integration/ApiTrait.php diff --git a/Integration/HttpRequestTrait.php b/src/Integration/HttpRequestTrait.php similarity index 100% rename from Integration/HttpRequestTrait.php rename to src/Integration/HttpRequestTrait.php diff --git a/Integration/RESTTrait.php b/src/Integration/RESTTrait.php similarity index 100% rename from Integration/RESTTrait.php rename to src/Integration/RESTTrait.php diff --git a/Integration/RESTVfsTestCase.php b/src/Integration/RESTVfsTestCase.php similarity index 100% rename from Integration/RESTVfsTestCase.php rename to src/Integration/RESTVfsTestCase.php diff --git a/Integration/RESTfulTestCase.php b/src/Integration/RESTfulTestCase.php similarity index 100% rename from Integration/RESTfulTestCase.php rename to src/Integration/RESTfulTestCase.php diff --git a/Integration/TestCase.php b/src/Integration/TestCase.php similarity index 100% rename from Integration/TestCase.php rename to src/Integration/TestCase.php diff --git a/Integration/VirtualFilesystemTestCase.php b/src/Integration/VirtualFilesystemTestCase.php similarity index 100% rename from Integration/VirtualFilesystemTestCase.php rename to src/Integration/VirtualFilesystemTestCase.php diff --git a/Integration/bootstrap.php b/src/Integration/bootstrap.php similarity index 100% rename from Integration/bootstrap.php rename to src/Integration/bootstrap.php diff --git a/Integration/phpunit.xml.dist b/src/Integration/phpunit.xml.dist similarity index 83% rename from Integration/phpunit.xml.dist rename to src/Integration/phpunit.xml.dist index 2e7d75d..bb7a3d2 100644 --- a/Integration/phpunit.xml.dist +++ b/src/Integration/phpunit.xml.dist @@ -15,8 +15,8 @@ - ../../../../Tests/Integration/ - ../../../../Tests/Integration/bootstrap.php + ../../../../../Tests/Integration/ + ../../../../../Tests/Integration/bootstrap.php diff --git a/TestCaseTrait.php b/src/TestCaseTrait.php similarity index 100% rename from TestCaseTrait.php rename to src/TestCaseTrait.php diff --git a/Unit/TestCase.php b/src/Unit/TestCase.php similarity index 100% rename from Unit/TestCase.php rename to src/Unit/TestCase.php diff --git a/Unit/VirtualFilesystemTestCase.php b/src/Unit/VirtualFilesystemTestCase.php similarity index 100% rename from Unit/VirtualFilesystemTestCase.php rename to src/Unit/VirtualFilesystemTestCase.php diff --git a/Unit/bootstrap.php b/src/Unit/bootstrap.php similarity index 100% rename from Unit/bootstrap.php rename to src/Unit/bootstrap.php diff --git a/Unit/phpunit.xml.dist b/src/Unit/phpunit.xml.dist similarity index 84% rename from Unit/phpunit.xml.dist rename to src/Unit/phpunit.xml.dist index db32386..5beeab0 100644 --- a/Unit/phpunit.xml.dist +++ b/src/Unit/phpunit.xml.dist @@ -15,8 +15,8 @@ - ../../../../Tests/Unit/ - ../../../../Tests/Unit/bootstrap.php + ../../../../../Tests/Unit/ + ../../../../../Tests/Unit/bootstrap.php diff --git a/VirtualFilesystemDirect.php b/src/VirtualFilesystemDirect.php similarity index 100% rename from VirtualFilesystemDirect.php rename to src/VirtualFilesystemDirect.php diff --git a/VirtualFilesystemTestTrait.php b/src/VirtualFilesystemTestTrait.php similarity index 100% rename from VirtualFilesystemTestTrait.php rename to src/VirtualFilesystemTestTrait.php diff --git a/bootstrap-functions.php b/src/bootstrap-functions.php similarity index 100% rename from bootstrap-functions.php rename to src/bootstrap-functions.php diff --git a/wpmedia-phpunit b/wpmedia-phpunit index 5cf50db..74b8118 100755 --- a/wpmedia-phpunit +++ b/wpmedia-phpunit @@ -5,7 +5,7 @@ namespace WPMedia\PHPUnit; $_SERVER['argv'][1] = strtolower( $_SERVER['argv'][1] ); if ( ! class_exists( __NAMESPACE__ . '\BootstrapManager' ) ) { - require 'BootstrapManager.php'; + require __DIR__ . '/src/BootstrapManager.php'; } BootstrapManager::setupConstants( $_SERVER['argv'][1] ); BootstrapManager::runTestSuite( $_SERVER['argv'][1] );