Skip to content

Refactor autoloading and normalize test structure#709

Open
fadrian06 wants to merge 13 commits into
masterfrom
autoload-rework
Open

Refactor autoloading and normalize test structure#709
fadrian06 wants to merge 13 commits into
masterfrom
autoload-rework

Conversation

@fadrian06

Copy link
Copy Markdown
Contributor

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:

  • Removed the custom flight/autoload.php file and its usage throughout the codebase, switching all autoloading to Composer's vendor/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]
  • Updated composer.json autoload and autoload-dev sections to use PSR-4 autoloading for both source and test code, and removed the files autoload section. (composer.json, composer.jsonL30-R39)

Namespace and Directory Structure Standardization:

  • Renamed test directories and files from kebab-case to snake_case (e.g., named-arguments to named_arguments, server-v2 to server_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]
  • Standardized namespaces in test files and middleware classes from Tests\Server to tests\server and from Tests\PHP8 to tests\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:

  • Removed the custom test bootstrap file and its references, relying on Composer's autoloading for test setup. (phpunit.xml.dist, [1] [2]
  • Updated phpunit.xml.dist to match new directory names and removed exclusions for files/directories that no longer exist. (phpunit.xml.dist, phpunit.xml.distL18-R21)
  • Refactored tests in LoaderTest.php to use reflection for accessing private properties instead of anonymous classes, improving maintainability. (tests/LoaderTest.php, [1] [2]
  • Minor fix in LoaderTest.php to use Closure::fromCallable for registering callables. (tests/LoaderTest.php, tests/LoaderTest.phpL88-R89)

Loader and Internal Improvements:

  • Improved the Loader class to use is_iterable for directory addition and normalize directory separators, enhancing cross-platform compatibility. (flight/core/Loader.php, flight/core/Loader.phpL218-R224)
  • Updated docblocks in Loader for clarity and type safety. (flight/core/Loader.php, flight/core/Loader.phpL51-R53)

Miscellaneous:

  • Updated test server scripts and references to use new directory and namespace conventions. (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.

- 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
Copilot AI review requested due to automatic review settings June 23, 2026 17:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.php and tests/phpunit_autoload.php bootstrap in favor of Composer’s vendor/autoload.php.
  • Standardized test namespaces and moved/renamed test-server assets to PSR-4-friendly paths (tests/server_v2, tests/named_arguments, etc.).
  • Updated Loader internals 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.

Comment thread tests/server_v2/index.php
Comment thread tests/server_v2/index.php Outdated
Comment thread tests/LoaderTest.php
fadrian06 and others added 3 commits June 23, 2026 14:04
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@n0nag0n

n0nag0n commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

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.

@n0nag0n n0nag0n closed this Jun 24, 2026
@fadrian06

Copy link
Copy Markdown
Contributor Author

so if I restore autoload.php, this PR could be merged?

@fadrian06 fadrian06 reopened this Jun 25, 2026
@fadrian06

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Merged the latest master into autoload-rework. The merge resolved automatically without any conflicts — composer.json and tests/named_arguments/FlightTest.php were the only files touched by both branches, and both merged cleanly. The branch is now up to date with master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants