Skip to content

Commit 16fe6df

Browse files
committed
Leverage FileClassLocator
1 parent c253135 commit 16fe6df

File tree

8 files changed

+40
-74
lines changed

8 files changed

+40
-74
lines changed

lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeDriver.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Doctrine\ODM\MongoDB\Mapping\Driver;
66

7-
use ArrayIterator;
87
use Doctrine\Common\Annotations\Reader;
98
use Doctrine\ODM\MongoDB\Events;
109
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
@@ -18,7 +17,6 @@
1817
use Doctrine\Persistence\Mapping\Driver\ClassLocator;
1918
use Doctrine\Persistence\Mapping\Driver\ColocatedMappingDriver;
2019
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
21-
use LogicException;
2220
use MongoDB\BSON\Document;
2321
use MongoDB\Driver\Exception\UnexpectedValueException;
2422
use ReflectionClass;
@@ -33,9 +31,6 @@
3331
use function constant;
3432
use function count;
3533
use function is_array;
36-
use function is_string;
37-
use function property_exists;
38-
use function sprintf;
3934
use function trigger_deprecation;
4035

4136
/**

tests/Doctrine/ODM/MongoDB/Tests/BaseTestCase.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66

77
use Doctrine\ODM\MongoDB\Configuration;
88
use Doctrine\ODM\MongoDB\DocumentManager;
9+
use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
910
use Doctrine\ODM\MongoDB\Proxy\InternalProxy;
1011
use Doctrine\ODM\MongoDB\Tests\Query\Filter\Filter;
1112
use Doctrine\ODM\MongoDB\UnitOfWork;
13+
use Doctrine\Persistence\Mapping\Driver\FileClassLocator;
1214
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
1315
use MongoDB\Client;
1416
use MongoDB\Driver\Manager;
1517
use MongoDB\Driver\Server;
1618
use MongoDB\Model\DatabaseInfo;
1719
use PHPUnit\Framework\TestCase;
1820
use ProxyManager\Proxy\LazyLoadingInterface;
19-
use Stubs\AttributeDriverFactory;
2021

2122
use function array_key_exists;
2223
use function array_map;
24+
use function class_exists;
2325
use function count;
2426
use function explode;
2527
use function getenv;
@@ -124,7 +126,14 @@ public static function isLazyObject(object $document): bool
124126

125127
protected static function createMetadataDriverImpl(): MappingDriver
126128
{
127-
return AttributeDriverFactory::createAttributeDriver([__DIR__ . '/../../../../Documents']);
129+
$paths = [__DIR__ . '/../../../../Documents'];
130+
131+
// Available in Doctrine Persistence 4.1+
132+
if (class_exists(FileClassLocator::class)) {
133+
$paths = FileClassLocator::createFromDirectories($paths);
134+
}
135+
136+
return AttributeDriver::create($paths);
128137
}
129138

130139
protected static function createTestDocumentManager(): DocumentManager

tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractAnnotationDriverTestCase.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Generator;
1515
use PHPUnit\Framework\Attributes\DataProvider;
1616
use stdClass;
17-
use Stubs\AnnotationDriverFactory;
1817

1918
use function assert;
2019

@@ -76,7 +75,7 @@ public function testFieldInheritance(): void
7675
public function testLoadMetadataForNonDocumentThrowsException(): void
7776
{
7877
$cm = new ClassMetadata('stdClass');
79-
$annotationDriver = AnnotationDriverFactory::createAnnotationDriver();
78+
$annotationDriver = AnnotationDriver::create();
8079

8180
$this->expectException(MappingException::class);
8281
$annotationDriver->loadMetadataForClass('stdClass', $cm);
@@ -86,7 +85,7 @@ public function testLoadMetadataForNonDocumentThrowsException(): void
8685
public function testColumnWithMissingTypeDefaultsToString(): void
8786
{
8887
$cm = new ClassMetadata(ColumnWithoutType::class);
89-
$annotationDriver = AnnotationDriverFactory::createAnnotationDriver();
88+
$annotationDriver = AnnotationDriver::create();
9089

9190
$annotationDriver->loadMetadataForClass(stdClass::class, $cm);
9291
self::assertEquals('id', $cm->fieldMappings['id']['type']);

tests/Doctrine/ODM/MongoDB/Tests/Mapping/AnnotationDriverTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
88
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
99
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
10+
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
11+
use Doctrine\Persistence\Mapping\Driver\FileClassLocator;
1012
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
11-
use Stubs\AnnotationDriverFactory;
1213

1314
use function call_user_func;
15+
use function class_exists;
1416
use function restore_error_handler;
1517
use function set_error_handler;
1618
use function sprintf;
@@ -21,7 +23,11 @@ class AnnotationDriverTest extends AbstractAnnotationDriverTestCase
2123
{
2224
protected static function loadDriver(array $paths = []): MappingDriver
2325
{
24-
return AnnotationDriverFactory::createAnnotationDriver($paths);
26+
if (class_exists(FileClassLocator::class)) {
27+
$paths = FileClassLocator::createFromDirectories($paths);
28+
}
29+
30+
return AnnotationDriver::create($paths);
2531
}
2632

2733
public function testIndexesClassAnnotationEmitsDeprecationMessage(): void

tests/Doctrine/ODM/MongoDB/Tests/Mapping/AttributeDriverTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44

55
namespace Doctrine\ODM\MongoDB\Tests\Mapping;
66

7+
use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
8+
use Doctrine\Persistence\Mapping\Driver\FileClassLocator;
79
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
8-
use Stubs\AttributeDriverFactory;
10+
11+
use function class_exists;
912

1013
class AttributeDriverTest extends AbstractAnnotationDriverTestCase
1114
{
1215
protected static function loadDriver(array $paths = []): MappingDriver
1316
{
14-
return AttributeDriverFactory::createAttributeDriver($paths);
17+
if (class_exists(FileClassLocator::class)) {
18+
$paths = FileClassLocator::createFromDirectories($paths);
19+
}
20+
21+
return AttributeDriver::create($paths);
1522
}
1623
}

tests/Doctrine/ODM/MongoDB/Tests/Tools/Console/Command/Schema/UpdateCommandTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
88
use Doctrine\ODM\MongoDB\Tests\Tools\Console\Command\AbstractCommandTestCase;
99
use Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\UpdateCommand;
10+
use Doctrine\Persistence\Mapping\Driver\FileClassLocator;
1011
use Documents\SchemaValidated;
11-
use Stubs\AnnotationDriverFactory;
1212
use Symfony\Component\Console\Command\Command;
1313
use Symfony\Component\Console\Tester\CommandTester;
1414

15+
use function class_exists;
16+
1517
class UpdateCommandTest extends AbstractCommandTestCase
1618
{
1719
protected ?Command $command;
@@ -87,6 +89,12 @@ public function testDisabledValidatorsProcessing(): void
8789

8890
private function createDriver(): AnnotationDriver
8991
{
90-
return AnnotationDriverFactory::createAnnotationDriver([__DIR__ . '/../../../../../../../../Documents/Ecommerce']);
92+
$paths = [__DIR__ . '/../../../../Documents/SchemaValidated'];
93+
// Available in Doctrine Persistence 4.1+
94+
if (class_exists(FileClassLocator::class)) {
95+
$paths = FileClassLocator::createFromDirectories($paths);
96+
}
97+
98+
return AnnotationDriver::create([__DIR__ . '/../../../../../../../../Documents/Ecommerce']);
9199
}
92100
}

tests/Stubs/AnnotationDriverFactory.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/Stubs/AttributeDriverFactory.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)