From 4bac151a439fe173ffa84a2eeb44b676b586bb88 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 30 Jan 2022 00:40:41 +0100 Subject: [PATCH] Introduce DoctrineSetup as a replacement for Setup --- .github/workflows/continuous-integration.yml | 2 +- UPGRADE.md | 14 ++ lib/Doctrine/ORM/Configuration.php | 11 + lib/Doctrine/ORM/Tools/DoctrineSetup.php | 199 ++++++++++++++++++ lib/Doctrine/ORM/Tools/Setup.php | 62 ++++-- psalm-baseline.xml | 7 +- psalm.xml | 2 + .../Performance/EntityManagerFactory.php | 9 +- .../Tests/Mocks/EntityManagerMock.php | 3 +- .../Functional/Locking/LockAgentWorker.php | 3 +- .../Tests/ORM/Functional/MergeProxiesTest.php | 6 +- .../Tests/ORM/Tools/DoctrineSetupTest.php | 145 +++++++++++++ tests/Doctrine/Tests/ORM/Tools/SetupTest.php | 4 +- .../Doctrine/Tests/OrmFunctionalTestCase.php | 12 +- tests/Doctrine/Tests/OrmTestCase.php | 11 +- 15 files changed, 444 insertions(+), 46 deletions(-) create mode 100644 lib/Doctrine/ORM/Tools/DoctrineSetup.php create mode 100644 tests/Doctrine/Tests/ORM/Tools/DoctrineSetupTest.php diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index f467510d83..5cc5bad85e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -42,7 +42,7 @@ jobs: uses: "shivammathur/setup-php@v2" with: php-version: "${{ matrix.php-version }}" - extensions: "pdo, pdo_sqlite" + extensions: "apcu, pdo, pdo_sqlite" coverage: "pcov" ini-values: "zend.assertions=1" diff --git a/UPGRADE.md b/UPGRADE.md index 77c8529e7c..ee195c0399 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,19 @@ # Upgrade to 2.12 +## Deprecate `Doctrine\ORM\Configuration::newDefaultAnnotationDriver` + +This functionality has been moved to the new `DoctrineSetup` class. Call +`Doctrine\ORM\Tools\DoctrineSetup::createDefaultAnnotationDriver()` to create +a new annotation driver. + +## Deprecate `Doctrine\ORM\Tools\Setup` + +In our effort to migrate from Doctrine Cache to PSR-6, the `Setup` class which +accepted a Doctrine Cache instance in each method has been deprecated. + +The replacement is `Doctrine\ORM\Tools\DoctrineSetup` which accepts a PSR-6 +cache instead. + ## Deprecate `Doctrine\ORM\Cache\MultiGetRegion` The interface will be merged with `Doctrine\ORM\Cache\Region` in 3.0. diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 8c8fd98568..a341451bfd 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -37,6 +37,7 @@ use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Repository\DefaultRepositoryFactory; use Doctrine\ORM\Repository\RepositoryFactory; +use Doctrine\ORM\Tools\DoctrineSetup; use Doctrine\Persistence\Mapping\Driver\MappingDriver; use Doctrine\Persistence\ObjectRepository; use Psr\Cache\CacheItemPoolInterface; @@ -154,6 +155,8 @@ public function setMetadataDriverImpl(MappingDriver $driverImpl) * Adds a new default annotation driver with a correctly configured annotation reader. If $useSimpleAnnotationReader * is true, the notation `@Entity` will work, otherwise, the notation `@ORM\Entity` will be supported. * + * @deprecated Use {@see DoctrineSetup::createDefaultAnnotationDriver()} instead. + * * @param string|string[] $paths * @param bool $useSimpleAnnotationReader * @psalm-param string|list $paths @@ -162,6 +165,14 @@ public function setMetadataDriverImpl(MappingDriver $driverImpl) */ public function newDefaultAnnotationDriver($paths = [], $useSimpleAnnotationReader = true) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/pull/9443', + '%s is deprecated, call %s::createDefaultAnnotationDriver() instead.', + __METHOD__, + DoctrineSetup::class + ); + AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php'); if ($useSimpleAnnotationReader) { diff --git a/lib/Doctrine/ORM/Tools/DoctrineSetup.php b/lib/Doctrine/ORM/Tools/DoctrineSetup.php new file mode 100644 index 0000000000..45e0488954 --- /dev/null +++ b/lib/Doctrine/ORM/Tools/DoctrineSetup.php @@ -0,0 +1,199 @@ +setMetadataDriverImpl(self::createDefaultAnnotationDriver($paths)); + + return $config; + } + + /** + * Adds a new default annotation driver with a correctly configured annotation reader. + * + * @param string[] $paths + */ + public static function createDefaultAnnotationDriver( + array $paths = [], + ?CacheItemPoolInterface $cache = null + ): AnnotationDriver { + $reader = new AnnotationReader(); + + if ($cache === null && class_exists(ArrayAdapter::class)) { + $cache = new ArrayAdapter(); + } + + if ($cache !== null) { + $reader = new PsrCachedReader($reader, $cache); + } + + return new AnnotationDriver($reader, $paths); + } + + /** + * Creates a configuration with an attribute metadata driver. + * + * @param string[] $paths + */ + public static function createAttributeMetadataConfiguration( + array $paths, + bool $isDevMode = false, + ?string $proxyDir = null, + ?CacheItemPoolInterface $cache = null + ): Configuration { + $config = self::createConfiguration($isDevMode, $proxyDir, $cache); + $config->setMetadataDriverImpl(new AttributeDriver($paths)); + + return $config; + } + + /** + * Creates a configuration with an XML metadata driver. + * + * @param string[] $paths + */ + public static function createXMLMetadataConfiguration( + array $paths, + bool $isDevMode = false, + ?string $proxyDir = null, + ?CacheItemPoolInterface $cache = null + ): Configuration { + $config = self::createConfiguration($isDevMode, $proxyDir, $cache); + $config->setMetadataDriverImpl(new XmlDriver($paths)); + + return $config; + } + + /** + * Creates a configuration with a YAML metadata driver. + * + * @deprecated YAML metadata mapping is deprecated and will be removed in 3.0 + * + * @param string[] $paths + */ + public static function createYAMLMetadataConfiguration( + array $paths, + bool $isDevMode = false, + ?string $proxyDir = null, + ?CacheItemPoolInterface $cache = null + ): Configuration { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/issues/8465', + 'YAML mapping driver is deprecated and will be removed in Doctrine ORM 3.0, please migrate to attribute or XML driver.' + ); + + $config = self::createConfiguration($isDevMode, $proxyDir, $cache); + $config->setMetadataDriverImpl(new YamlDriver($paths)); + + return $config; + } + + /** + * Creates a configuration without a metadata driver. + */ + public static function createConfiguration( + bool $isDevMode = false, + ?string $proxyDir = null, + ?CacheItemPoolInterface $cache = null + ): Configuration { + $proxyDir = $proxyDir ?: sys_get_temp_dir(); + + $cache = self::createCacheInstance($isDevMode, $proxyDir, $cache); + + $config = new Configuration(); + + $config->setMetadataCache($cache); + $config->setQueryCache($cache); + $config->setResultCache($cache); + $config->setProxyDir($proxyDir); + $config->setProxyNamespace('DoctrineProxies'); + $config->setAutoGenerateProxyClasses($isDevMode); + + return $config; + } + + private static function createCacheInstance( + bool $isDevMode, + string $proxyDir, + ?CacheItemPoolInterface $cache + ): CacheItemPoolInterface { + if ($cache !== null) { + return $cache; + } + + if (! class_exists(ArrayAdapter::class)) { + throw new RuntimeException( + 'The Doctrine setup tool cannot configure caches without symfony/cache.' + . ' Please add symfony/cache as explicit dependency or pass your own cache implementation.' + ); + } + + if ($isDevMode) { + return new ArrayAdapter(); + } + + $namespace = 'dc2_' . md5($proxyDir); + + if (extension_loaded('apcu')) { + return new ApcuAdapter($namespace); + } + + if (extension_loaded('memcached')) { + $memcached = new Memcached(); + $memcached->addServer('127.0.0.1', 11211); + + return new MemcachedAdapter($memcached, $namespace); + } + + if (extension_loaded('redis')) { + $redis = new Redis(); + $redis->connect('127.0.0.1'); + + return new RedisAdapter($redis, $namespace); + } + + return new ArrayAdapter(); + } + + private function __construct() + { + } +} diff --git a/lib/Doctrine/ORM/Tools/Setup.php b/lib/Doctrine/ORM/Tools/Setup.php index f6c09f6082..5adde6a204 100644 --- a/lib/Doctrine/ORM/Tools/Setup.php +++ b/lib/Doctrine/ORM/Tools/Setup.php @@ -33,6 +33,8 @@ /** * Convenience class for setting up Doctrine from different installations and configurations. + * + * @deprecated Use {@see DoctrineSetup} instead. */ class Setup { @@ -62,15 +64,23 @@ public static function registerAutoloadDirectory($directory) /** * Creates a configuration with an annotation metadata driver. * - * @param mixed[] $paths - * @param bool $isDevMode - * @param string $proxyDir - * @param bool $useSimpleAnnotationReader + * @param string[] $paths + * @param bool $isDevMode + * @param string|null $proxyDir + * @param bool $useSimpleAnnotationReader * * @return Configuration */ public static function createAnnotationMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, ?Cache $cache = null, $useSimpleAnnotationReader = true) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/pull/9443', + '%s is deprecated and will be removed in Doctrine 3.0, please use %s instead.', + self::class, + DoctrineSetup::class + ); + $config = self::createConfiguration($isDevMode, $proxyDir, $cache); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($paths, $useSimpleAnnotationReader)); @@ -90,6 +100,14 @@ public static function createAttributeMetadataConfiguration( $proxyDir = null, ?Cache $cache = null ): Configuration { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/pull/9443', + '%s is deprecated and will be removed in Doctrine 3.0, please use %s instead.', + self::class, + DoctrineSetup::class + ); + $config = self::createConfiguration($isDevMode, $proxyDir, $cache); $config->setMetadataDriverImpl(new AttributeDriver($paths)); @@ -97,16 +115,24 @@ public static function createAttributeMetadataConfiguration( } /** - * Creates a configuration with a xml metadata driver. + * Creates a configuration with an XML metadata driver. * - * @param mixed[] $paths - * @param bool $isDevMode - * @param string $proxyDir + * @param string[] $paths + * @param bool $isDevMode + * @param string|null $proxyDir * * @return Configuration */ public static function createXMLMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, ?Cache $cache = null) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/pull/9443', + '%s is deprecated and will be removed in Doctrine 3.0, please use %s instead.', + self::class, + DoctrineSetup::class + ); + $config = self::createConfiguration($isDevMode, $proxyDir, $cache); $config->setMetadataDriverImpl(new XmlDriver($paths)); @@ -114,13 +140,13 @@ public static function createXMLMetadataConfiguration(array $paths, $isDevMode = } /** - * Creates a configuration with a yaml metadata driver. + * Creates a configuration with a YAML metadata driver. * * @deprecated YAML metadata mapping is deprecated and will be removed in 3.0 * - * @param mixed[] $paths - * @param bool $isDevMode - * @param string $proxyDir + * @param string[] $paths + * @param bool $isDevMode + * @param string|null $proxyDir * * @return Configuration */ @@ -141,13 +167,21 @@ public static function createYAMLMetadataConfiguration(array $paths, $isDevMode /** * Creates a configuration without a metadata driver. * - * @param bool $isDevMode - * @param string $proxyDir + * @param bool $isDevMode + * @param string|null $proxyDir * * @return Configuration */ public static function createConfiguration($isDevMode = false, $proxyDir = null, ?Cache $cache = null) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/orm', + 'https://github.com/doctrine/orm/pull/9443', + '%s is deprecated and will be removed in Doctrine 3.0, please use %s instead.', + self::class, + DoctrineSetup::class + ); + $proxyDir = $proxyDir ?: sys_get_temp_dir(); $cache = self::createCacheConfiguration($isDevMode, $proxyDir, $cache); diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 7353865119..6ba9d5a468 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -992,10 +992,6 @@ - - YamlDriver - parent::__construct($locator, $fileExtension) - $fileExtension $prefixes @@ -3437,10 +3433,9 @@ - + new ClassLoader('Doctrine', $directory) new ClassLoader('Symfony\Component', $directory . '/Doctrine') - new YamlDriver($paths) require_once $directory . '/Doctrine/Common/ClassLoader.php' diff --git a/psalm.xml b/psalm.xml index ba9fb8c8a9..4e77be393f 100644 --- a/psalm.xml +++ b/psalm.xml @@ -25,6 +25,7 @@ + @@ -51,6 +52,7 @@ + diff --git a/tests/Doctrine/Performance/EntityManagerFactory.php b/tests/Doctrine/Performance/EntityManagerFactory.php index 852d3ef1bf..c1f20f60d6 100644 --- a/tests/Doctrine/Performance/EntityManagerFactory.php +++ b/tests/Doctrine/Performance/EntityManagerFactory.php @@ -13,6 +13,7 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Proxy\ProxyFactory; +use Doctrine\ORM\Tools\DoctrineSetup; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\Mocks\DriverResultMock; @@ -28,10 +29,10 @@ public static function getEntityManager(array $schemaClassNames): EntityManagerI $config->setProxyDir(__DIR__ . '/../Tests/Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); $config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([ + $config->setMetadataDriverImpl(DoctrineSetup::createDefaultAnnotationDriver([ realpath(__DIR__ . '/Models/Cache'), realpath(__DIR__ . '/Models/GeoNames'), - ], true)); + ])); $entityManager = EntityManager::create( [ @@ -54,11 +55,11 @@ public static function makeEntityManagerWithNoResultsConnection(): EntityManager $config->setProxyDir(__DIR__ . '/../Tests/Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); $config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([ + $config->setMetadataDriverImpl(DoctrineSetup::createDefaultAnnotationDriver([ realpath(__DIR__ . '/Models/Cache'), realpath(__DIR__ . '/Models/Generic'), realpath(__DIR__ . '/Models/GeoNames'), - ], true)); + ])); // A connection that doesn't really do anything $connection = new class ([], new Driver(), null, new EventManager()) extends Connection diff --git a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php index 51ca576ae3..2f1cd9dd56 100644 --- a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php @@ -8,6 +8,7 @@ use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Proxy\ProxyFactory; +use Doctrine\ORM\Tools\DoctrineSetup; use Doctrine\ORM\UnitOfWork; /** @@ -60,7 +61,7 @@ public static function create($conn, ?Configuration $config = null, ?EventManage $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([], false)); + $config->setMetadataDriverImpl(DoctrineSetup::createDefaultAnnotationDriver()); } if ($eventManager === null) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php index f9d9ac06a4..48c918943f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php @@ -9,6 +9,7 @@ use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Tools\DoctrineSetup; use GearmanWorker; use InvalidArgumentException; use Symfony\Component\Cache\Adapter\ArrayAdapter; @@ -118,7 +119,7 @@ protected function createEntityManager(Connection $conn): EntityManagerInterface $config->setProxyNamespace('MyProject\Proxies'); $config->setAutoGenerateProxyClasses(true); - $annotDriver = $config->newDefaultAnnotationDriver([__DIR__ . '/../../../Models/'], false); + $annotDriver = DoctrineSetup::createDefaultAnnotationDriver([__DIR__ . '/../../../Models/']); $config->setMetadataDriverImpl($annotDriver); $config->setMetadataCache(new ArrayAdapter()); diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php index 1ef346b307..71f607ce6d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php @@ -10,6 +10,7 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Proxy\Proxy; +use Doctrine\ORM\Tools\DoctrineSetup; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\DbalExtensions\Connection; use Doctrine\Tests\DbalExtensions\QueryLog; @@ -240,9 +241,8 @@ private function createEntityManager(): EntityManagerInterface $config->setProxyDir(realpath(__DIR__ . '/../../Proxies')); $config->setProxyNamespace('Doctrine\Tests\Proxies'); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver( - [realpath(__DIR__ . '/../../Models/Cache')], - false + $config->setMetadataDriverImpl(DoctrineSetup::createDefaultAnnotationDriver( + [realpath(__DIR__ . '/../../Models/Cache')] )); // always runs on sqlite to prevent multi-connection race-conditions with the test suite diff --git a/tests/Doctrine/Tests/ORM/Tools/DoctrineSetupTest.php b/tests/Doctrine/Tests/ORM/Tools/DoctrineSetupTest.php new file mode 100644 index 0000000000..0ec3c83ff7 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Tools/DoctrineSetupTest.php @@ -0,0 +1,145 @@ +getProxyDir()); + self::assertEquals('DoctrineProxies', $config->getProxyNamespace()); + self::assertInstanceOf(AnnotationDriver::class, $config->getMetadataDriverImpl()); + } + + public function testNewDefaultAnnotationDriver(): void + { + $paths = [__DIR__]; + $reflectionClass = new ReflectionClass(AnnotatedDummy::class); + + $annotationDriver = DoctrineSetup::createDefaultAnnotationDriver($paths); + $reader = $annotationDriver->getReader(); + $annotation = $reader->getMethodAnnotation( + $reflectionClass->getMethod('namespacedAnnotationMethod'), + AnnotationNamespace\PrePersist::class + ); + self::assertInstanceOf(AnnotationNamespace\PrePersist::class, $annotation); + } + + /** + * @requires PHP 8.0 + */ + public function testAttributeConfiguration(): void + { + $config = DoctrineSetup::createAttributeMetadataConfiguration([], true); + + self::assertInstanceOf(Configuration::class, $config); + self::assertEquals(sys_get_temp_dir(), $config->getProxyDir()); + self::assertEquals('DoctrineProxies', $config->getProxyNamespace()); + self::assertInstanceOf(AttributeDriver::class, $config->getMetadataDriverImpl()); + } + + public function testXMLConfiguration(): void + { + $config = DoctrineSetup::createXMLMetadataConfiguration([], true); + + self::assertInstanceOf(Configuration::class, $config); + self::assertInstanceOf(XmlDriver::class, $config->getMetadataDriverImpl()); + } + + public function testYAMLConfiguration(): void + { + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8465'); + $config = DoctrineSetup::createYAMLMetadataConfiguration([], true); + + self::assertInstanceOf(Configuration::class, $config); + self::assertInstanceOf(YamlDriver::class, $config->getMetadataDriverImpl()); + } + + /** + * @requires extension apcu + */ + public function testCacheNamespaceShouldBeGeneratedForApcu(): void + { + $config = DoctrineSetup::createConfiguration(false, '/foo'); + $cache = $config->getMetadataCache(); + + $namespaceProperty = new ReflectionProperty(AbstractAdapter::class, 'namespace'); + $namespaceProperty->setAccessible(true); + + self::assertInstanceOf(ApcuAdapter::class, $cache); + self::assertSame('dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf:', $namespaceProperty->getValue($cache)); + } + + /** + * @group DDC-1350 + */ + public function testConfigureProxyDir(): void + { + $config = DoctrineSetup::createAnnotationMetadataConfiguration([], true, '/foo'); + self::assertEquals('/foo', $config->getProxyDir()); + } + + /** + * @group DDC-1350 + */ + public function testConfigureCache(): void + { + $cache = new ArrayAdapter(); + $config = DoctrineSetup::createAnnotationMetadataConfiguration([], true, null, $cache); + + self::assertSame($cache, $config->getResultCache()); + self::assertSame($cache, $config->getResultCacheImpl()->getPool()); + self::assertSame($cache, $config->getQueryCache()); + self::assertSame($cache, $config->getQueryCacheImpl()->getPool()); + self::assertSame($cache, $config->getMetadataCache()); + self::assertSame($cache, $config->getMetadataCacheImpl()->getPool()); + } + + /** + * @group DDC-3190 + */ + public function testConfigureCacheCustomInstance(): void + { + $cache = new ArrayAdapter(); + $config = DoctrineSetup::createConfiguration(true, null, $cache); + + self::assertSame($cache, $config->getResultCache()); + self::assertSame($cache, $config->getResultCacheImpl()->getPool()); + self::assertSame($cache, $config->getQueryCache()); + self::assertSame($cache, $config->getQueryCacheImpl()->getPool()); + self::assertSame($cache, $config->getMetadataCache()); + self::assertSame($cache, $config->getMetadataCacheImpl()->getPool()); + } +} + +class AnnotatedDummy +{ + /** @AnnotationNamespace\PrePersist */ + public function namespacedAnnotationMethod(): void + { + } +} diff --git a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php index 3622a17816..408e6e1896 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php @@ -11,7 +11,7 @@ use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Doctrine\ORM\Tools\Setup; -use Doctrine\Tests\OrmTestCase; +use PHPUnit\Framework\TestCase; use Symfony\Component\Cache\Adapter\ArrayAdapter; use function count; @@ -21,7 +21,7 @@ use function spl_autoload_unregister; use function sys_get_temp_dir; -class SetupTest extends OrmTestCase +class SetupTest extends TestCase { /** @var int */ private $originalAutoloaderCount; diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 9d000d9025..0afc395b89 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -19,6 +19,7 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Exception\ORMException; use Doctrine\ORM\Tools\DebugUnitOfWorkListener; +use Doctrine\ORM\Tools\DoctrineSetup; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Persistence\Mapping\Driver\MappingDriver; use Doctrine\Tests\DbalExtensions\QueryLog; @@ -763,13 +764,10 @@ protected function getEntityManager( } $config->setMetadataDriverImpl( - $mappingDriver ?? $config->newDefaultAnnotationDriver( - [ - realpath(__DIR__ . '/Models/Cache'), - realpath(__DIR__ . '/Models/GeoNames'), - ], - false - ) + $mappingDriver ?? DoctrineSetup::createDefaultAnnotationDriver([ + realpath(__DIR__ . '/Models/Cache'), + realpath(__DIR__ . '/Models/GeoNames'), + ]) ); $conn = $connection ?: static::$sharedConn; diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index 476c30177e..4dae7add5a 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -14,6 +14,7 @@ use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger; use Doctrine\ORM\Configuration; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Tools\DoctrineSetup; use Doctrine\Tests\Mocks\EntityManagerMock; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Cache\Adapter\ArrayAdapter; @@ -87,16 +88,12 @@ protected function getTestEntityManager( $config = new Configuration(); $config->setMetadataCache($metadataCache); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([], false)); $config->setQueryCache(self::getSharedQueryCache()); $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver( - [ - realpath(__DIR__ . '/Models/Cache'), - ], - false - )); + $config->setMetadataDriverImpl(DoctrineSetup::createDefaultAnnotationDriver([ + realpath(__DIR__ . '/Models/Cache'), + ])); if ($this->isSecondLevelCacheEnabled) { $cacheConfig = new CacheConfiguration();