Skip to content

Conversation

@GromNaN
Copy link
Member

@GromNaN GromNaN commented Dec 6, 2025

The ClassLocator abstraction added in #433 should be used for the StaticPHPDriver.

By using the ColocatedMappingDriver trait, we remove code duplication.

  • fix StaticPHPDriverTest::testGetAllClassNames by only scanning /_files/colocated/. Otherwise it loads the Doctrine.Tests.Persistence.Mapping.PHPTestEntityAssert.php file that expects the variable $metadata to be defined. This test passes when all the test suite is run, but not individually.

  • Relax PHPStan type for list of directories in FileClassLocator::createFromDirectories() as we don't care about the array key.

Use the ColocatedMappingDriver that provides this feature
….Mapping.PHPTestEntityAssert.php that asserts $metadata variable existence
@GromNaN GromNaN added this to the 4.2.0 milestone Dec 6, 2025
@GromNaN GromNaN added the Enhancement New feature or request label Dec 6, 2025
@GromNaN GromNaN requested a review from Copilot December 6, 2025 22:10
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 StaticPHPDriver to leverage the ClassLocator abstraction and eliminate code duplication by using the ColocatedMappingDriver trait. The changes enable the driver to accept either directory paths or a ClassLocator instance, simplifying its implementation and improving maintainability.

Key Changes:

  • Refactored StaticPHPDriver to use ColocatedMappingDriver trait, removing ~80 lines of duplicated code
  • Added support for ClassLocator parameter in StaticPHPDriver constructor
  • Fixed test isolation issue in StaticPHPDriverTest::testGetAllClassNames by narrowing the scan path

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Mapping/Driver/StaticPHPDriver.php Replaced custom implementation with ColocatedMappingDriver trait and added ClassLocator support to constructor
src/Mapping/Driver/ColocatedMappingDriver.php Updated addPaths() to use spread operator syntax for array merging
tests/Mapping/StaticPHPDriverTest.php Refactored tests to use colocated test entity, fixed path scanning issue, and added new test for ClassLocator support
tests/Mapping/_files/colocated/Entity.php Added loadMetadata() method to make this a valid test entity for StaticPHPDriver

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


public function testGetAllClassNames(): void
{
$driver = new StaticPHPDriver([__DIR__]);
Copy link
Member Author

Choose a reason for hiding this comment

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

This directory contains Doctrine.Tests.Persistence.Mapping.PHPTestEntityAssert.php that cannot be includes without setting the $metadata variable. Not supported by the StaticPHPDriver.

Comment on lines +84 to +85
* @param string[] $directories
* @param string[] $excludedDirectories Directories to exclude from the search.
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't use the key of the array when iterating. Relaxing this type si that array<int, string> is accepted, which is the result of array_unique.

/**
* {@inheritDoc}
*
* @todo Same code exists in ColocatedMappingDriver, should we re-use it
Copy link
Member Author

Choose a reason for hiding this comment

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

This deleted code is duplicate of FileClassLocator.

* @var array<int, string>
*/
private array $paths = [];
use ColocatedMappingDriver;
Copy link
Member

Choose a reason for hiding this comment

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

This introduces more public methods to the class. Maybe it needs to be documented in UPGRADE.md

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

Labels

Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants