From 76e7eaece548acb1023920bbcdb5d6c6020a0bad Mon Sep 17 00:00:00 2001 From: Gregoire PARIS Date: Fri, 8 Aug 2025 11:57:26 +0200 Subject: [PATCH] Revert "Feature: allow `ColocatedMappingDriver` to accept iterable source file path names" This reverts commit a6cb5a1dc910b7804dd80633483fcd0e40e1fde6. A better implementation is incoming, with fixes. This reverts makes the branch releaseable again, and will make the incoming pull request easier to review. --- .../Mapping/Driver/ColocatedMappingDriver.php | 12 ++--- src/Persistence/Mapping/MappingException.php | 2 +- .../Mapping/ColocatedMappingDriverTest.php | 44 ++++--------------- 3 files changed, 14 insertions(+), 44 deletions(-) diff --git a/src/Persistence/Mapping/Driver/ColocatedMappingDriver.php b/src/Persistence/Mapping/Driver/ColocatedMappingDriver.php index 13e04e3f..a7661364 100644 --- a/src/Persistence/Mapping/Driver/ColocatedMappingDriver.php +++ b/src/Persistence/Mapping/Driver/ColocatedMappingDriver.php @@ -33,9 +33,6 @@ */ trait ColocatedMappingDriver { - /** @var iterable */ - private iterable $sourceFilePathNames; - /** * The paths where to look for mapping files. * @@ -54,7 +51,7 @@ trait ColocatedMappingDriver protected string $fileExtension = '.php'; /** - * Cache for {@see getAllClassNames()}. + * Cache for getAllClassNames(). * * @var array|null * @phpstan-var list|null @@ -82,7 +79,7 @@ public function getPaths(): array } /** - * Append exclude lookup paths to a metadata driver. + * Append exclude lookup paths to metadata driver. * * @param string[] $paths */ @@ -135,7 +132,7 @@ public function getAllClassNames(): array return $this->classNames; } - if ($this->paths === [] && ! isset($this->sourceFilePathNames)) { + if ($this->paths === []) { throw MappingException::pathRequiredForDriver(static::class); } @@ -160,8 +157,7 @@ public function getAllClassNames(): array $filesIterator->append($iterator); } - /** @var iterable $sourceFilePathNames */ - $sourceFilePathNames = $this->sourceFilePathNames ?? $this->pathNameIterator($filesIterator); + $sourceFilePathNames = $this->pathNameIterator($filesIterator); $includedFiles = []; foreach ($sourceFilePathNames as $sourceFile) { diff --git a/src/Persistence/Mapping/MappingException.php b/src/Persistence/Mapping/MappingException.php index 3037ddfc..7a25fdf2 100644 --- a/src/Persistence/Mapping/MappingException.php +++ b/src/Persistence/Mapping/MappingException.php @@ -30,7 +30,7 @@ public static function classNotFoundInNamespaces( public static function pathRequiredForDriver(string $driverClassName): self { return new self(sprintf( - 'Specifying source file paths to your entities is required when using %s to retrieve all class names.', + 'Specifying the paths to your entities is required when using %s to retrieve all class names.', $driverClassName, )); } diff --git a/tests/Persistence/Mapping/ColocatedMappingDriverTest.php b/tests/Persistence/Mapping/ColocatedMappingDriverTest.php index f0d8d4ea..7ddadf7a 100644 --- a/tests/Persistence/Mapping/ColocatedMappingDriverTest.php +++ b/tests/Persistence/Mapping/ColocatedMappingDriverTest.php @@ -13,15 +13,13 @@ use Generator; use PHPUnit\Framework\TestCase; -use function assert; -use function is_array; use function sort; class ColocatedMappingDriverTest extends TestCase { public function testAddGetPaths(): void { - $driver = $this->createPathDriver(__DIR__ . '/_files/colocated'); + $driver = $this->createDriver(__DIR__ . '/_files/colocated'); self::assertSame([ __DIR__ . '/_files/colocated', ], $driver->getPaths()); @@ -37,7 +35,7 @@ public function testAddGetPaths(): void public function testAddGetExcludePaths(): void { - $driver = $this->createPathDriver(__DIR__ . '/_files/colocated'); + $driver = $this->createDriver(__DIR__ . '/_files/colocated'); self::assertSame([], $driver->getExcludePaths()); $driver->addExcludePaths(['/test/path1', '/test/path2']); @@ -50,7 +48,7 @@ public function testAddGetExcludePaths(): void public function testGetSetFileExtension(): void { - $driver = $this->createPathDriver(__DIR__ . '/_files/colocated'); + $driver = $this->createDriver(__DIR__ . '/_files/colocated'); self::assertSame('.php', $driver->getFileExtension()); $driver->setFileExtension('.php1'); @@ -59,9 +57,9 @@ public function testGetSetFileExtension(): void } /** @dataProvider pathProvider */ - public function testGetAllClassNamesForPath(string $path): void + public function testGetAllClassNames(string $path): void { - $driver = $this->createPathDriver($path); + $driver = $this->createDriver($path); $classes = $driver->getAllClassNames(); @@ -69,18 +67,6 @@ public function testGetAllClassNamesForPath(string $path): void self::assertSame([Entity::class, EntityFixture::class], $classes); } - public function testGetAllClassNamesForIterableFilePathNames(): void - { - $driver = $this->createFilePathNamesDriver([ - __DIR__ . '/_files/colocated/Entity.php', - __DIR__ . '/_files/colocated/TestClass.php', - ]); - - $classes = $driver->getAllClassNames(); - - self::assertSame([Entity::class], $classes, 'The driver should only return the class names from the provided file path names, excluding transient class names.'); - } - /** @return Generator */ public static function pathProvider(): Generator { @@ -88,32 +74,20 @@ public static function pathProvider(): Generator yield 'winding path' => [__DIR__ . '/../Mapping/_files/colocated']; } - private function createPathDriver(string $path): MyDriver + private function createDriver(string $path): MyDriver { return new MyDriver([$path]); } - - /** @param list $paths */ - private function createFilePathNamesDriver(array $paths): MyDriver - { - return new MyDriver($paths, true); - } } final class MyDriver implements MappingDriver { use ColocatedMappingDriver; - /** @param iterable $paths Source file path names */ - public function __construct(iterable $paths, bool $sourceFilePathNames = false) + /** @param non-empty-list $paths One or multiple paths where mapping classes can be found. */ + public function __construct(array $paths) { - if (! $sourceFilePathNames) { - assert(is_array($paths)); - - $this->addPaths($paths); - } else { - $this->sourceFilePathNames = $paths; - } + $this->addPaths($paths); } /**