Skip to content

Conversation

@ttsuru
Copy link
Contributor

@ttsuru ttsuru commented Oct 2, 2025

Summary

This PR completes the migration to PHPUnit 9+ architecture and simplifies the dispatcher infrastructure by removing legacy compatibility code. The test suite now fully utilizes modern PHPUnit interfaces and all tests pass on PHPUnit 9.6+ across PHP 8.0-8.5.

Changes

PHPUnit 9+ Architecture

Test Suite Infrastructure:

  • Refactored CakeTestLoader to implement TestSuiteLoader interface with composition pattern
  • Fixed critical infinite recursion bug in CakeTestLoader::reload() method that would cause stack overflow
  • Updated CakeBaseReporter from extending PHPUnit_TextUI_ResultPrinter to implementing ResultPrinter interface
  • Added missing interface methods: write(), addWarning(), addRiskyTest() to maintain PHPUnit 9+ compatibility
  • Removed legacy CakeTestRunner class - functionality moved to CakeTestSuiteCommand::run()
  • Updated all PHPUnit class references from PHPUnit_Framework_* to PHPUnit\Framework\* namespace
  • Added type declarations throughout TestSuite classes for PHP 8.0+ strict typing

Test Fixes:

  • Fixed TestShellTest assertions using callback-based output verification instead of deprecated withConsecutive()
  • Updated HtmlCoverageReportTest to use CakeHtmlReporter instead of abstract CakeBaseReporter
  • Fixed ProjectTaskTest assertions to match new dispatcher structure (VENDORS constant)
  • Removed PHPUnit version checks that prevented tests from running on PHPUnit 9+

Dispatcher Simplification (Breaking Change)

Removed Files:

  • app/Console/cake.bat and app/Console/cake.php (Windows-specific wrappers no longer needed)
  • lib/Cake/Console/cake.bat and lib/Cake/Console/cake.php
  • Legacy app/index.php, root index.php, and .htaccess files
  • vendors/empty placeholder file

Simplified Logic:

  • Removed manual CAKE_CORE_INCLUDE_PATH detection from dispatcher files
  • Removed include_path manipulation logic (Composer autoload handles this)
  • Removed legacy app/Vendor/cakephp/cakephp path detection
  • Added clear error messages when Composer dependencies are missing
  • Changed include to require_once in bootstrap files for consistency

Legacy Code Removal

PHP Version Checks:

  • Removed PHP 5.3/5.4 version checks from ErrorHandler, Debugger, CakeSocket
  • Removed PHP 5.4 fallback logic in CakeNumber::_numberFormat()
  • Removed PHP 5.3.2/5.6.0 SSL/TLS configuration checks in CakeSocket
  • Removed obsolete Debugger workarounds for PHP versions below 5.3

Modernization:

  • Updated strpos() to str_ends_with() in CakeTestLoader
  • Fixed indentation in basics.php to standardize whitespace
  • Removed get_magic_quotes_gpc exclusion from phpcs.xml (function removed in PHP 7.4)

Performance Improvements

JSON Output Optimization:

  • JsonView now only applies JSON_PRETTY_PRINT when debug mode is enabled
  • Reduces JSON encoding overhead in production environments

Autoloading Enhancement:

  • Added class existence check to App::load() to prevent unnecessary file loading
  • Replaced direct ShellDispatcher require with App::load() in test bootstrap
  • Added class_exists() guard to prevent double definition errors

Code Quality

Coding Standards:

  • Added trailing commas to trigger_error() calls for consistency
  • Added CakeHtmlReporter to unused variable exclusion list in phpcs.xml
  • Added missing PHPUnit\Runner\Version import to test template header

Documentation:

  • Updated all GitHub URLs from cakephp to friendsofcake2 in home.ctp templates
  • Removed upstream CONTRIBUTING.md (fork has different contribution guidelines)
  • Updated CHANGELOG.md and README.md with comprehensive migration instructions

Why These Changes?

PHPUnit 9+ Compatibility

PHPUnit 9 introduced significant architectural changes, including the removal of base classes like PHPUnit_TextUI_ResultPrinter in favor of interfaces. Our test infrastructure was still using the old architecture, which prevented proper operation with modern PHPUnit versions.

Simplified Maintenance

Removing legacy PHP version checks and compatibility code reduces maintenance burden and makes the codebase easier to understand. Since this fork requires PHP 8.0+, there's no need to maintain code paths for PHP 5.x.

Improved Performance

The App::load() enhancement and JSON output optimization provide measurable performance improvements in production scenarios without affecting functionality.

Better Developer Experience

Clearer error messages when Composer dependencies are missing help developers quickly identify and fix configuration issues.

Breaking Changes

⚠️ Non-Composer installation is no longer supported

Projects must use Composer for dependency management. Manual installation paths and include_path manipulation have been removed from dispatcher files.

Migration Required:

  1. Copy updated dispatcher files:
cp vendors/friendsofcake2/cakephp/lib/Cake/Console/Templates/skel/webroot/index.php app/webroot/index.php
cp vendors/friendsofcake2/cakephp/lib/Cake/Console/Templates/skel/webroot/test.php app/webroot/test.php
cp vendors/friendsofcake2/cakephp/lib/Cake/Console/Templates/skel/Console/cake app/Console/cake
  1. Remove old dispatcher files:
rm -f app/Console/cake.bat app/Console/cake.php
  1. Run Composer:
composer install

Impact: Applications already using Composer (recommended setup) require only file updates. Applications using manual installation will need to migrate to Composer.

Files Changed

  • Major refactoring of TestSuite infrastructure
  • Significant code simplification through legacy code removal

ttsuru added 2 commits October 2, 2025 20:24
- Removed manual CAKE_CORE_INCLUDE_PATH detection from dispatcher files
- Removed include_path manipulation logic (Composer autoload handles this)
- Removed legacy app/Vendor/cakephp/cakephp path detection
- Added clear error messages when Composer vendors directory or autoload.php is missing
- Added clear error message when CakePHP core is not installed via Composer
- Retained PHP built-in server support for development convenience
- Updated both app/ and skel/ template files for consistency

Breaking Change: Non-Composer installation is no longer supported.
Projects must use Composer for dependency management.

Migration: Copy updated dispatcher files from vendors/friendsofcake2/cakephp/lib/Cake/Console/Templates/skel/
to your application (webroot/index.php, webroot/test.php, Console/cake).

Updated documentation:
- Added CHANGELOG entry for dispatcher improvements
- Added README installation instructions for copying dispatcher files
- Added Composer-only requirement to Breaking Changes section
- Simplify PHPUnit framework detection using modern TestCase class
- Remove unused CakeTestRunner class and associated run() method
- Update type hints from PHPUnit_Framework_* to PHPUnit\Framework\*
- Add use statements for PHPUnit classes to improve code clarity
- Add vendor/ paths to App::path() for better Composer compatibility
- Fix trailing commas in trigger_error calls for consistency
- Remove index.php from phpcs.xml scope
@codecov
Copy link

codecov bot commented Oct 2, 2025

ttsuru added 7 commits October 2, 2025 21:39
Add allow-plugins configuration for dealerdirect/phpcodesniffer-composer-installer
to comply with Composer 2.2+ plugin security requirements.
- Refactor CakeTestLoader to implement TestSuiteLoader interface with composition
- Update ProjectTaskTest assertions to match new VENDORS constant
- Fix FolderTest to use WWW_ROOT instead of APP for index.php path
- Update load() method signature to match PHPUnit interface requirements
… checks

TestSuite improvements:
- Fix critical infinite recursion bug in CakeTestLoader::reload()
- Change CakeBaseReporter from extending PHPUnit_TextUI_ResultPrinter to implementing ResultPrinter interface
- Add type declarations throughout TestSuite classes for PHP 8.0+ compatibility
- Add run() method to CakeTestSuiteCommand with proper test file resolution
- Update HtmlCoverageReportTest to use CakeHtmlReporter instead of CakeBaseReporter
- Add missing interface methods (write, addWarning, addRiskyTest) to CakeBaseReporter

Remove legacy PHP version checks:
- Remove PHP 5.3/5.4 compatibility code from ErrorHandler, Debugger, CakeSocket
- Remove PHP 5.4 fallback in CakeNumber::_numberFormat()
- Remove PHP version checks from CakeTimeTest
- Remove PHPUnit version check from test files

Code style improvements:
- Fix indentation in basics.php (standardize whitespace)
- Change include to require_once in bootstrap files for consistency
- Remove get_magic_quotes_gpc exclusion from phpcs.xml (function removed in PHP 7.4)
- Add CakeHtmlReporter to unused variable exclusion list

Other changes:
- Update test assertions to match new dispatcher structure
- Simplify home.ctp formatting
- Change GitHub organization URLs from cakephp to friendsofcake2 in home.ctp
- Update changelog, issues, wiki, and plugin repository links
- Remove upstream CONTRIBUTING.md as this is a fork with different contribution guidelines
JsonView:
- Only apply JSON_PRETTY_PRINT when debug mode is enabled
- Improves performance in production environments

App::load():
- Add class_exists check at the beginning to prevent unnecessary loading
- Improves performance when class is already loaded

Test bootstrap:
- Replace direct ShellDispatcher require with App::load()
- More consistent with CakePHP's autoloading patterns
TestShellTest.php:
- Remove PHPUnit version check (test now works with PHPUnit 9+)
- Fix testAvailableWithEmptyList to expect 2 out() calls (message + help)
- Improve testAvailableCoreCategory to use callback for output verification
- Verify actual output content using array capture instead of withConsecutive

header.php:
- Add missing PHPUnit\Runner\Version import
CHANGELOG.md:
- Add comprehensive PHPUnit 9+ migration section
- Document removal of legacy PHP version checks
- Add JSON output optimization improvements
- Document App::load() enhancement
- Add coding standards and GitHub URLs update sections
- Reorganize sections for better readability

README.md:
- Add PR #14 link to Composer-Only Installation breaking change
- Document removal of app/Console/cake.bat and cake.php files
- Add migration step to remove old dispatcher files
@ttsuru ttsuru changed the title Improve dispatcher Complete PHPUnit 9+ Migration and Dispatcher Simplification Oct 2, 2025
@ttsuru ttsuru merged commit 06663d6 into master Oct 2, 2025
35 of 36 checks passed
@ttsuru ttsuru deleted the improve-dispatcher branch October 2, 2025 17:13
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.

2 participants