Skip to content

Commit c392605

Browse files
authored
Merge pull request #431 from greg0ire/revert-a6cb5a
Revert "Feature: allow `ColocatedMappingDriver` to accept iterable source file path names
2 parents beef6b3 + 76e7eae commit c392605

File tree

3 files changed

+14
-44
lines changed

3 files changed

+14
-44
lines changed

src/Persistence/Mapping/Driver/ColocatedMappingDriver.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
*/
3434
trait ColocatedMappingDriver
3535
{
36-
/** @var iterable<string> */
37-
private iterable $sourceFilePathNames;
38-
3936
/**
4037
* The paths where to look for mapping files.
4138
*
@@ -54,7 +51,7 @@ trait ColocatedMappingDriver
5451
protected string $fileExtension = '.php';
5552

5653
/**
57-
* Cache for {@see getAllClassNames()}.
54+
* Cache for getAllClassNames().
5855
*
5956
* @var array<int, string>|null
6057
* @phpstan-var list<class-string>|null
@@ -82,7 +79,7 @@ public function getPaths(): array
8279
}
8380

8481
/**
85-
* Append exclude lookup paths to a metadata driver.
82+
* Append exclude lookup paths to metadata driver.
8683
*
8784
* @param string[] $paths
8885
*/
@@ -135,7 +132,7 @@ public function getAllClassNames(): array
135132
return $this->classNames;
136133
}
137134

138-
if ($this->paths === [] && ! isset($this->sourceFilePathNames)) {
135+
if ($this->paths === []) {
139136
throw MappingException::pathRequiredForDriver(static::class);
140137
}
141138

@@ -160,8 +157,7 @@ public function getAllClassNames(): array
160157
$filesIterator->append($iterator);
161158
}
162159

163-
/** @var iterable<string> $sourceFilePathNames */
164-
$sourceFilePathNames = $this->sourceFilePathNames ?? $this->pathNameIterator($filesIterator);
160+
$sourceFilePathNames = $this->pathNameIterator($filesIterator);
165161
$includedFiles = [];
166162

167163
foreach ($sourceFilePathNames as $sourceFile) {

src/Persistence/Mapping/MappingException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function classNotFoundInNamespaces(
3030
public static function pathRequiredForDriver(string $driverClassName): self
3131
{
3232
return new self(sprintf(
33-
'Specifying source file paths to your entities is required when using %s to retrieve all class names.',
33+
'Specifying the paths to your entities is required when using %s to retrieve all class names.',
3434
$driverClassName,
3535
));
3636
}

tests/Persistence/Mapping/ColocatedMappingDriverTest.php

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
use Generator;
1414
use PHPUnit\Framework\TestCase;
1515

16-
use function assert;
17-
use function is_array;
1816
use function sort;
1917

2018
class ColocatedMappingDriverTest extends TestCase
2119
{
2220
public function testAddGetPaths(): void
2321
{
24-
$driver = $this->createPathDriver(__DIR__ . '/_files/colocated');
22+
$driver = $this->createDriver(__DIR__ . '/_files/colocated');
2523
self::assertSame([
2624
__DIR__ . '/_files/colocated',
2725
], $driver->getPaths());
@@ -37,7 +35,7 @@ public function testAddGetPaths(): void
3735

3836
public function testAddGetExcludePaths(): void
3937
{
40-
$driver = $this->createPathDriver(__DIR__ . '/_files/colocated');
38+
$driver = $this->createDriver(__DIR__ . '/_files/colocated');
4139
self::assertSame([], $driver->getExcludePaths());
4240

4341
$driver->addExcludePaths(['/test/path1', '/test/path2']);
@@ -50,7 +48,7 @@ public function testAddGetExcludePaths(): void
5048

5149
public function testGetSetFileExtension(): void
5250
{
53-
$driver = $this->createPathDriver(__DIR__ . '/_files/colocated');
51+
$driver = $this->createDriver(__DIR__ . '/_files/colocated');
5452
self::assertSame('.php', $driver->getFileExtension());
5553

5654
$driver->setFileExtension('.php1');
@@ -59,61 +57,37 @@ public function testGetSetFileExtension(): void
5957
}
6058

6159
/** @dataProvider pathProvider */
62-
public function testGetAllClassNamesForPath(string $path): void
60+
public function testGetAllClassNames(string $path): void
6361
{
64-
$driver = $this->createPathDriver($path);
62+
$driver = $this->createDriver($path);
6563

6664
$classes = $driver->getAllClassNames();
6765

6866
sort($classes);
6967
self::assertSame([Entity::class, EntityFixture::class], $classes);
7068
}
7169

72-
public function testGetAllClassNamesForIterableFilePathNames(): void
73-
{
74-
$driver = $this->createFilePathNamesDriver([
75-
__DIR__ . '/_files/colocated/Entity.php',
76-
__DIR__ . '/_files/colocated/TestClass.php',
77-
]);
78-
79-
$classes = $driver->getAllClassNames();
80-
81-
self::assertSame([Entity::class], $classes, 'The driver should only return the class names from the provided file path names, excluding transient class names.');
82-
}
83-
8470
/** @return Generator<string, array{string}> */
8571
public static function pathProvider(): Generator
8672
{
8773
yield 'straigthforward path' => [__DIR__ . '/_files/colocated'];
8874
yield 'winding path' => [__DIR__ . '/../Mapping/_files/colocated'];
8975
}
9076

91-
private function createPathDriver(string $path): MyDriver
77+
private function createDriver(string $path): MyDriver
9278
{
9379
return new MyDriver([$path]);
9480
}
95-
96-
/** @param list<string> $paths */
97-
private function createFilePathNamesDriver(array $paths): MyDriver
98-
{
99-
return new MyDriver($paths, true);
100-
}
10181
}
10282

10383
final class MyDriver implements MappingDriver
10484
{
10585
use ColocatedMappingDriver;
10686

107-
/** @param iterable<string> $paths Source file path names */
108-
public function __construct(iterable $paths, bool $sourceFilePathNames = false)
87+
/** @param non-empty-list<string> $paths One or multiple paths where mapping classes can be found. */
88+
public function __construct(array $paths)
10989
{
110-
if (! $sourceFilePathNames) {
111-
assert(is_array($paths));
112-
113-
$this->addPaths($paths);
114-
} else {
115-
$this->sourceFilePathNames = $paths;
116-
}
90+
$this->addPaths($paths);
11791
}
11892

11993
/**

0 commit comments

Comments
 (0)