Refactor autoloading and normalize test structure#709
Conversation
- removed autoload-dev.classmap - normalize Tests/* namespace to tests - rename tests/server-v2 to tests/server_v2 - remove tests/phpunit_autoload.php - update tests files namespaces - update tests/server/index.php and tests/server_v2/index.php to use composer autoloader - extract tests/server_v2/AuthCheck.php
There was a problem hiding this comment.
Pull request overview
This PR modernizes FlightPHP/Core’s bootstrapping by removing the bespoke framework/test autoloaders and standardizing the test tree so everything loads via Composer (PSR-4), with accompanying namespace and path updates.
Changes:
- Removed the custom
flight/autoload.phpandtests/phpunit_autoload.phpbootstrap in favor of Composer’svendor/autoload.php. - Standardized test namespaces and moved/renamed test-server assets to PSR-4-friendly paths (
tests/server_v2,tests/named_arguments, etc.). - Updated
Loaderinternals and related tests to improve portability (iterable support + directory separator normalization).
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
composer.json |
Switches to PSR-4 autoloading (plus classmap for global Flight) and updates test-server script paths. |
index.php |
Uses Composer autoloader instead of directly including flight/Flight.php. |
flight/Flight.php |
Removes framework-level require of the old custom autoloader. |
flight/core/Loader.php |
Improves directory registration (is_iterable) and normalizes directory separators; docblock tweaks. |
flight/autoload.php |
Deleted custom autoloader. |
phpunit.xml.dist |
Removes bootstrap file reference; updates excluded test directory name. |
tests/phpunit_autoload.php |
Deleted custom PHPUnit bootstrap. |
tests/EventSystemTest.php |
Normalizes test namespace to match new autoload-dev PSR-4 mapping. |
tests/LoaderTest.php |
Updates callable registration and replaces helper subclasses with reflection-based assertions. |
tests/named_arguments/FlightTest.php |
Updates namespace to match renamed directory and PSR-4 mapping. |
tests/named_arguments/ExampleClass.php |
Adds namespace for PSR-4 compatibility. |
tests/server/index.php |
Updates middleware class imports and switches to Composer autoload. |
tests/server/AuthCheck.php |
Namespace updated for PSR-4 mapping consistency. |
tests/server/LayoutMiddleware.php |
Namespace updated for PSR-4 mapping consistency. |
tests/server/OverwriteBodyMiddleware.php |
Namespace updated for PSR-4 mapping consistency. |
tests/server/Pascal_Snake_Case.php |
Namespace updated for PSR-4 mapping consistency. |
tests/server-v2/index.php |
Deleted old v2 test server entrypoint. |
tests/server_v2/index.php |
Adds the new v2 test server entrypoint under the normalized directory name. |
tests/server_v2/AuthCheck.php |
Extracts v2 middleware into a PSR-4-loadable class. |
tests/server_v2/template.phtml |
Adds a template file for the v2 test server. |
Comments suppressed due to low confidence (1)
tests/named_arguments/ExampleClass.php:8
- The PHPCS ignore for a missing namespace is now stale (the file declares a namespace). Keeping this suppression can hide future PHPCS issues and is misleading.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
This one I can't approve and merge. What you have done long term is correct and the right way to go, but because this was setup the way it is, people who have downloaded the zip rely on that autoload.php file for their workflows. Some of the main selling points of Flight is that it is simple and easy to implement, no dependencies, and no breaking changes are introduced to keep it backwards compatible. |
|
so if I restore autoload.php, this PR could be merged? |
|
@copilot resolve the merge conflicts in this pull request |
Merged the latest |
This pull request refactors the project’s autoloading and test structure to modernize dependency management, standardize naming conventions, and improve test reliability. The most significant changes include removing the custom autoloader in favor of Composer's autoloader, updating namespaces and directory structures for consistency, and cleaning up test and configuration files.
Autoloading and Dependency Management:
flight/autoload.phpfile and its usage throughout the codebase, switching all autoloading to Composer'svendor/autoload.php. This simplifies dependency management and aligns with modern PHP practices. (composer.json,index.php,flight/Flight.php,tests/server/index.php,tests/phpunit_autoload.php, [1] [2] [3] [4] [5]composer.jsonautoload and autoload-dev sections to use PSR-4 autoloading for both source and test code, and removed thefilesautoload section. (composer.json, composer.jsonL30-R39)Namespace and Directory Structure Standardization:
named-argumentstonamed_arguments,server-v2toserver_v2) and updated namespaces accordingly for consistency and PSR-4 compatibility. (composer.json,phpunit.xml.dist,tests/named_arguments/ExampleClass.php,tests/named_arguments/FlightTest.php,tests/server_v2/AuthCheck.php, [1] [2] [3] [4] [5] [6]Tests\Servertotests\serverand fromTests\PHP8totests\named_arguments. (tests/EventSystemTest.php,tests/server/AuthCheck.php,tests/server/LayoutMiddleware.php,tests/server/OverwriteBodyMiddleware.php,tests/server/Pascal_Snake_Case.php, [1] [2] [3] [4] [5]Test and Configuration Improvements:
phpunit.xml.dist, [1] [2]phpunit.xml.distto match new directory names and removed exclusions for files/directories that no longer exist. (phpunit.xml.dist, phpunit.xml.distL18-R21)LoaderTest.phpto use reflection for accessing private properties instead of anonymous classes, improving maintainability. (tests/LoaderTest.php, [1] [2]LoaderTest.phpto useClosure::fromCallablefor registering callables. (tests/LoaderTest.php, tests/LoaderTest.phpL88-R89)Loader and Internal Improvements:
Loaderclass to useis_iterablefor directory addition and normalize directory separators, enhancing cross-platform compatibility. (flight/core/Loader.php, flight/core/Loader.phpL218-R224)Loaderfor clarity and type safety. (flight/core/Loader.php, flight/core/Loader.phpL51-R53)Miscellaneous:
composer.json,tests/server/index.php, [1] [2]These changes collectively modernize the codebase, improve consistency, and make the project easier to maintain and extend.