Skip to content

Conversation

@huangdijia
Copy link
Member

Summary

  • Optimized ClassLoader detection by using spl_autoload_functions() instead of checking hardcoded autoload file paths
  • This approach is more reliable and works regardless of the project structure
  • Simplified code by removing unnecessary file path checks

Changes

  • Modified src/testing/phpunit-patch.php to iterate through registered autoload functions
  • Changed from checking predefined paths to dynamically detecting the Composer ClassLoader instance

Benefits

  • More robust detection that works in various project setups
  • Cleaner, more maintainable code
  • Eliminates assumptions about vendor directory location

Changed from checking hardcoded autoload file paths to using spl_autoload_functions() to detect the Composer ClassLoader. This approach is more reliable and works regardless of the project structure.
@huangdijia huangdijia requested review from Copilot and limingxinleo and removed request for limingxinleo November 4, 2025 15:33
Copy link

Copilot AI left a comment

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 refactors the PHPUnit patch initialization logic to use registered autoloaders instead of checking hardcoded file paths. The change improves flexibility by allowing the code to work in different project structures without relying on specific vendor directory locations.

  • Replaces hardcoded file path checking with spl_autoload_functions() to dynamically discover the Composer ClassLoader
  • Simplifies the null check for the $classLoader variable
  • Removes the explicit instanceof check when testing for null

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@limingxinleo limingxinleo merged commit 82d87d0 into hyperf:3.2 Nov 5, 2025
76 checks passed
@huangdijia huangdijia deleted the refactor/phpunit-patch-autoloader-detection branch November 5, 2025 05:53
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