From f3f453286fa9926db3b489d6afabb0a0add7efe2 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 24 Oct 2022 00:15:56 +0200 Subject: [PATCH] Deprecate EntityManager::create() (#9961) --- UPGRADE.md | 7 ++++ ...-conversion-using-custom-mapping-types.rst | 2 +- .../cookbook/dql-user-defined-functions.rst | 4 +-- .../resolve-target-entity-listener.rst | 5 ++- docs/en/cookbook/sql-table-prefixes.rst | 4 +-- docs/en/reference/advanced-configuration.rst | 22 ++++++------ docs/en/reference/configuration.rst | 20 ++++++----- .../reference/dql-doctrine-query-language.rst | 12 +++---- docs/en/reference/events.rst | 4 +-- docs/en/tutorials/getting-started.rst | 9 ++--- lib/Doctrine/ORM/EntityManager.php | 29 +++++++++++++--- psalm.xml | 1 + .../Performance/EntityManagerFactory.php | 9 ++--- .../Tests/Mocks/EntityManagerMock.php | 34 +++++++++++-------- .../Doctrine/Tests/ORM/EntityManagerTest.php | 17 +++++++++- .../Functional/Locking/LockAgentWorker.php | 2 +- .../Tests/ORM/Functional/MergeProxiesTest.php | 2 +- .../ORM/Functional/Ticket/DDC3634Test.php | 2 +- .../ORM/Functional/Ticket/GH7869Test.php | 2 +- .../ORM/Mapping/ClassMetadataFactoryTest.php | 2 +- .../Tests/ORM/PersistentCollectionTest.php | 2 +- .../Tests/ORM/Proxy/ProxyFactoryTest.php | 2 +- .../ORM/Tools/ConvertDoctrine1SchemaTest.php | 2 +- .../Export/ClassMetadataExporterTestCase.php | 2 +- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 4 +-- .../Doctrine/Tests/OrmFunctionalTestCase.php | 2 +- tests/Doctrine/Tests/OrmTestCase.php | 2 +- 27 files changed, 126 insertions(+), 79 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 052f761cabb..1bbe5fd1e93 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -27,6 +27,13 @@ It will be removed in 3.0. Use one of the dedicated event classes instead: # Upgrade to 2.13 +## Deprecated `EntityManager::create()` + +The constructor of `EntityManager` is now public and should be used instead of the `create()` method. +However, the constructor expects a `Connection` while `create()` accepted an array with connection parameters. +You can pass that array to DBAL's `Doctrine\DBAL\DriverManager::getConnection()` method to bootstrap the +connection. + ## Deprecated `QueryBuilder` methods and constants. 1. The `QueryBuilder::getState()` method has been deprecated as the builder state is an internal concern. diff --git a/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst b/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst index 040b0c078ff..67a14c8aa7f 100644 --- a/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst +++ b/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst @@ -196,7 +196,7 @@ Example usage addCustomNumericFunction($name, $class); $config->addCustomDatetimeFunction($name, $class); - $em = EntityManager::create($dbParams, $config); + $em = new EntityManager($connection, $config); The ``$name`` is the name the function will be referred to in the DQL query. ``$class`` is a string of a class-name which has to @@ -247,5 +247,3 @@ vendor sql functions and extend the DQL languages scope. Code for this Extension to DQL and other Doctrine Extensions can be found `in the GitHub DoctrineExtensions repository `_. - - diff --git a/docs/en/cookbook/resolve-target-entity-listener.rst b/docs/en/cookbook/resolve-target-entity-listener.rst index 82771684b81..e3c5550b102 100644 --- a/docs/en/cookbook/resolve-target-entity-listener.rst +++ b/docs/en/cookbook/resolve-target-entity-listener.rst @@ -127,7 +127,8 @@ the targetEntity resolution will occur reliably: // Add the ResolveTargetEntityListener $evm->addEventListener(Doctrine\ORM\Events::loadClassMetadata, $rtel); - $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config, $evm); + $connection = \Doctrine\DBAL\DriverManager::createConnection($connectionOptions, $config, $evm); + $em = new \Doctrine\ORM\EntityManager($connection, $config, $evm); Final Thoughts -------------- @@ -136,5 +137,3 @@ With the ``ResolveTargetEntityListener``, we are able to decouple our bundles, keeping them usable by themselves, but still being able to define relationships between different objects. By using this method, I've found my bundles end up being easier to maintain independently. - - diff --git a/docs/en/cookbook/sql-table-prefixes.rst b/docs/en/cookbook/sql-table-prefixes.rst index dc4ae6952df..f1c2c4486ff 100644 --- a/docs/en/cookbook/sql-table-prefixes.rst +++ b/docs/en/cookbook/sql-table-prefixes.rst @@ -81,6 +81,4 @@ before the prefix has been set. $tablePrefix = new \DoctrineExtensions\TablePrefix('prefix_'); $evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix); - $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config, $evm); - - + $em = new \Doctrine\ORM\EntityManager($connection, $config, $evm); diff --git a/docs/en/reference/advanced-configuration.rst b/docs/en/reference/advanced-configuration.rst index a487c9e7ea3..0aacc76dd2d 100644 --- a/docs/en/reference/advanced-configuration.rst +++ b/docs/en/reference/advanced-configuration.rst @@ -41,12 +41,12 @@ steps of configuration. $config->setAutoGenerateProxyClasses(false); } - $connectionOptions = array( + $connection = DriverManager::getConnection([ 'driver' => 'pdo_sqlite', - 'path' => 'database.sqlite' - ); + 'path' => 'database.sqlite', + ], $config); - $em = EntityManager::create($connectionOptions, $config); + $em = new EntityManager($connection, $config); Doctrine and Caching -------------------- @@ -276,15 +276,13 @@ proxy sets an exclusive file lock which can cause serious performance bottlenecks in systems with regular concurrent requests. -Connection Options ------------------- +Connection +---------- -The ``$connectionOptions`` passed as the first argument to -``EntityManager::create()`` has to be either an array or an -instance of ``Doctrine\DBAL\Connection``. If an array is passed it -is directly passed along to the DBAL Factory -``Doctrine\DBAL\DriverManager::getConnection()``. The DBAL -configuration is explained in the +The ``$connection`` passed as the first argument to he constructor of +``EntityManager`` has to be an instance of ``Doctrine\DBAL\Connection``. +You can use the factory ``Doctrine\DBAL\DriverManager::getConnection()`` +to create such a connection. The DBAL configuration is explained in the `DBAL section `_. Proxy Objects diff --git a/docs/en/reference/configuration.rst b/docs/en/reference/configuration.rst index 57bfd154924..831ae91a16a 100644 --- a/docs/en/reference/configuration.rst +++ b/docs/en/reference/configuration.rst @@ -41,22 +41,24 @@ access point to ORM functionality provided by Doctrine. // bootstrap.php require_once "vendor/autoload.php"; + use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\ORMSetup; - $paths = array("/path/to/entity-files"); + $paths = ['/path/to/entity-files']; $isDevMode = false; // the connection configuration - $dbParams = array( + $dbParams = [ 'driver' => 'pdo_mysql', 'user' => 'root', 'password' => '', 'dbname' => 'foo', - ); + ]; $config = ORMSetup::createAttributeMetadataConfiguration($paths, $isDevMode); - $entityManager = EntityManager::create($dbParams, $config); + $connection = DriverManager::getConnection($dbParams, $config); + $entityManager = new EntityManager($connection, $config); .. note:: @@ -68,18 +70,20 @@ Or if you prefer XML: .. code-block:: php createQuery('SELECT u FROM ForumUser u WHERE (u.username = :name OR u.username = :name2) AND u.id = :id'); - $query->setParameters(array( + $query->setParameters([ 'name' => 'Bob', 'name2' => 'Alice', 'id' => 321, - )); + ]); $users = $query->getResult(); // array of ForumUser objects With COUNT DISTINCT: @@ -794,7 +794,7 @@ You can register custom DQL functions in your ORM Configuration: $config->addCustomNumericFunction($name, $class); $config->addCustomDatetimeFunction($name, $class); - $em = EntityManager::create($dbParams, $config); + $em = new EntityManager($connection, $config); The functions have to return either a string, numeric or datetime value depending on the registered function type. As an example we @@ -806,8 +806,8 @@ classes have to implement the base class : addEventListener([Events::preUpdate], new MyEventListener()); $eventManager->addEventSubscriber(new MyEventSubscriber()); - $entityManager = EntityManager::create($dbOpts, $config, $eventManager); + $entityManager = new EntityManager($connection, $config, $eventManager); You can also retrieve the event manager instance after the EntityManager was created: @@ -1016,7 +1016,7 @@ Implementing your own resolver: // Configure the listener resolver only before instantiating the EntityManager $configurations->setEntityListenerResolver(new MyEntityListenerResolver); - EntityManager::create(.., $configurations, ..); + $entityManager = new EntityManager(.., $configurations, ..); .. _reference-events-load-class-metadata: diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 998687a4085..d638c8ecec4 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -136,6 +136,7 @@ step: 'pdo_sqlite', 'path' => __DIR__ . '/db.sqlite', - ); + ], $config) // obtaining the entity manager - $entityManager = EntityManager::create($conn, $config); + $entityManager = new EntityManager($connection, $config); .. note:: The YAML driver is deprecated and will be removed in version 3.0. diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 0e59a760197..1956ad75166 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -60,8 +60,8 @@ * $paths = ['/path/to/entity/mapping/files']; * * $config = ORMSetup::createAttributeMetadataConfiguration($paths); - * $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; - * $entityManager = EntityManager::create($dbParams, $config); + * $connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true], $config); + * $entityManager = new EntityManager($connection, $config); * * For more information see * {@link http://docs.doctrine-project.org/projects/doctrine-orm/en/stable/reference/configuration.html} @@ -156,7 +156,7 @@ class EntityManager implements EntityManagerInterface * Creates a new EntityManager that operates on the given database connection * and uses the given Configuration and EventManager implementations. */ - public function __construct(Connection $conn, Configuration $config) + public function __construct(Connection $conn, Configuration $config, ?EventManager $eventManager = null) { if (! $config->getMetadataDriverImpl()) { throw MissingMappingDriverImplementation::create(); @@ -164,7 +164,7 @@ public function __construct(Connection $conn, Configuration $config) $this->conn = $conn; $this->config = $config; - $this->eventManager = $conn->getEventManager(); + $this->eventManager = $eventManager ?? $conn->getEventManager(); $metadataFactoryClassName = $config->getClassMetadataFactoryName(); @@ -952,6 +952,8 @@ public function initializeObject($obj) /** * Factory method to create EntityManager instances. * + * @deprecated Use {@see DriverManager::getConnection()} to bootstrap the connection and call the constructor. + * * @param mixed[]|Connection $connection An array with the connection parameters or an existing Connection instance. * @param Configuration $config The Configuration instance to use. * @param EventManager|null $eventManager The EventManager instance to use. @@ -964,6 +966,15 @@ public function initializeObject($obj) */ public static function create($connection, Configuration $config, ?EventManager $eventManager = null) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/pull/9961', + '%s() is deprecated. To boostrap a DBAL connection, call %s::getConnection() instead. Use the constructor to create an instance of %s.', + __METHOD__, + DriverManager::class, + self::class + ); + $connection = static::createConnection($connection, $config, $eventManager); return new EntityManager($connection, $config); @@ -972,6 +983,8 @@ public static function create($connection, Configuration $config, ?EventManager /** * Factory method to create Connection instances. * + * @deprecated Use {@see DriverManager::getConnection()} to bootstrap the connection. + * * @param mixed[]|Connection $connection An array with the connection parameters or an existing Connection instance. * @param Configuration $config The Configuration instance to use. * @param EventManager|null $eventManager The EventManager instance to use. @@ -984,6 +997,14 @@ public static function create($connection, Configuration $config, ?EventManager */ protected static function createConnection($connection, Configuration $config, ?EventManager $eventManager = null) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/orm', + 'https://github.com/doctrine/orm/pull/9961', + '%s() is deprecated, call %s::getConnection() instead.', + __METHOD__, + DriverManager::class + ); + if (is_array($connection)) { return DriverManager::getConnection($connection, $config, $eventManager ?: new EventManager()); } diff --git a/psalm.xml b/psalm.xml index faf62afc479..949204d6cac 100644 --- a/psalm.xml +++ b/psalm.xml @@ -77,6 +77,7 @@ + diff --git a/tests/Doctrine/Performance/EntityManagerFactory.php b/tests/Doctrine/Performance/EntityManagerFactory.php index be81291cacf..b3e023e661f 100644 --- a/tests/Doctrine/Performance/EntityManagerFactory.php +++ b/tests/Doctrine/Performance/EntityManagerFactory.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\PDO\SQLite\Driver; +use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Result; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; @@ -34,11 +35,11 @@ public static function getEntityManager(array $schemaClassNames): EntityManagerI realpath(__DIR__ . '/Models/GeoNames'), ])); - $entityManager = EntityManager::create( - [ + $entityManager = new EntityManager( + DriverManager::getConnection([ 'driverClass' => Driver::class, 'memory' => true, - ], + ], $config), $config ); @@ -71,6 +72,6 @@ public function executeQuery(string $sql, array $params = [], $types = [], ?Quer } }; - return EntityManager::create($connection, $config, $connection->getEventManager()); + return new EntityManager($connection, $config); } } diff --git a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php index ec59144f2ac..8c3e8356904 100644 --- a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php @@ -4,13 +4,17 @@ namespace Doctrine\Tests\Mocks; +use BadMethodCallException; use Doctrine\Common\EventManager; +use Doctrine\DBAL\Connection; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\ORMSetup; use Doctrine\ORM\Proxy\ProxyFactory; use Doctrine\ORM\UnitOfWork; +use function sprintf; + /** * Special EntityManager mock used for testing purposes. */ @@ -22,10 +26,19 @@ class EntityManagerMock extends EntityManager /** @var ProxyFactory|null */ private $_proxyFactoryMock; - /** - * {@inheritdoc} - */ - public function getUnitOfWork() + public function __construct(Connection $conn, ?Configuration $config = null, ?EventManager $eventManager = null) + { + if ($config === null) { + $config = new Configuration(); + $config->setProxyDir(__DIR__ . '/../Proxies'); + $config->setProxyNamespace('Doctrine\Tests\Proxies'); + $config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver()); + } + + parent::__construct($conn, $config, $eventManager); + } + + public function getUnitOfWork(): UnitOfWork { return $this->_uowMock ?? parent::getUnitOfWork(); } @@ -51,19 +64,10 @@ public function getProxyFactory(): ProxyFactory } /** - * Mock factory method to create an EntityManager. - * * {@inheritdoc} */ - public static function create($conn, ?Configuration $config = null, ?EventManager $eventManager = null) + public static function create($connection, Configuration $config, ?EventManager $eventManager = null): self { - if ($config === null) { - $config = new Configuration(); - $config->setProxyDir(__DIR__ . '/../Proxies'); - $config->setProxyNamespace('Doctrine\Tests\Proxies'); - $config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver()); - } - - return new EntityManagerMock($conn, $config); + throw new BadMethodCallException(sprintf('Call to deprecated method %s().', __METHOD__)); } } diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index b3505f08b65..7aeb1b512f5 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -31,6 +31,7 @@ use function get_class; use function random_int; +use function sys_get_temp_dir; use function uniqid; class EntityManagerTest extends OrmTestCase @@ -258,12 +259,26 @@ public function transactionalCallback($em): string public function testCreateInvalidConnection(): void { + $config = new Configuration(); + $config->setMetadataDriverImpl($this->createMock(MappingDriver::class)); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid $connection argument of type int given: "1".'); + EntityManager::create(1, $config); + } + public function testNamedConstructorDeprecation(): void + { $config = new Configuration(); $config->setMetadataDriverImpl($this->createMock(MappingDriver::class)); - EntityManager::create(1, $config); + $config->setProxyDir(sys_get_temp_dir()); + $config->setProxyNamespace(__NAMESPACE__ . '\\MyProxies'); + + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/9961'); + + $em = EntityManager::create(['driver' => 'pdo_sqlite', 'memory' => true], $config); + + self::assertInstanceOf(Connection::class, $em->getConnection()); } /** @group #5796 */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php index 7eab7208450..129f8d9cd72 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php @@ -123,7 +123,7 @@ protected function createEntityManager(Connection $conn): EntityManagerInterface $config->setQueryCache(new ArrayAdapter()); - return EntityManager::create($conn, $config); + return new EntityManager($conn, $config); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php index 2acf9843c38..5d66c1316a4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php @@ -257,7 +257,7 @@ private function createEntityManager(): EntityManagerInterface $config ); - $entityManager = EntityManager::create($connection, $config); + $entityManager = new EntityManager($connection, $config); (new SchemaTool($entityManager))->createSchema([$entityManager->getClassMetadata(DateTimeModel::class)]); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php index d0c9d647da6..3fa0adb5f19 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php @@ -47,7 +47,7 @@ public function testSavesVeryLargeIntegerAutoGeneratedValue(): void { $veryLargeId = PHP_INT_MAX . PHP_INT_MAX; - $entityManager = EntityManager::create( + $entityManager = new EntityManager( new DDC3634LastInsertIdMockingConnection($veryLargeId, $this->_em->getConnection()), $this->_em->getConfiguration() ); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php index 213670b6e56..11a5eec69e2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php @@ -33,7 +33,7 @@ public function testDQLDeferredEagerLoad(): void $connection->method('getEventManager') ->willReturn(new EventManager()); - $em = new class (EntityManagerMock::create($connection)) extends EntityManagerDecorator { + $em = new class (new EntityManagerMock($connection)) extends EntityManagerDecorator { /** @var int */ public $getClassMetadataCalls = 0; diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index fc951dfd000..a2b74bdbf5c 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -300,7 +300,7 @@ protected function createEntityManager(MappingDriver $metadataDriver, $conn = nu $config->setMetadataDriverImpl($metadataDriver); - return EntityManagerMock::create($conn, $config); + return new EntityManagerMock($conn, $config); } protected function createTestFactory(): ClassMetadataFactoryTestSubject diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index 704799c9e34..ffa7b65f7cc 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -56,7 +56,7 @@ protected function setUp(): void $connection->method('executeQuery') ->willReturn($this->createMock(Result::class)); - $this->_emMock = EntityManagerMock::create($connection); + $this->_emMock = new EntityManagerMock($connection); $this->setUpPersistentCollection(); } diff --git a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php index 18b47d334d4..46c1350552f 100644 --- a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php @@ -55,7 +55,7 @@ protected function setUp(): void $connection->method('getEventManager') ->willReturn(new EventManager()); - $this->emMock = EntityManagerMock::create($connection); + $this->emMock = new EntityManagerMock($connection); $this->uowMock = new UnitOfWorkMock($this->emMock); $this->emMock->setUnitOfWork($this->uowMock); $this->proxyFactory = new ProxyFactory($this->emMock, sys_get_temp_dir(), 'Proxies', ProxyFactory::AUTOGENERATE_ALWAYS); diff --git a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php index 0b92773e2cb..d89218f821a 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php @@ -46,7 +46,7 @@ protected function createEntityManager(MappingDriver $metadataDriver): EntityMan $config->setProxyNamespace('Doctrine\Tests\Proxies'); $config->setMetadataDriverImpl($metadataDriver); - return EntityManagerMock::create($connection, $config); + return new EntityManagerMock($connection, $config); } public function testTest(): void diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/ClassMetadataExporterTestCase.php b/tests/Doctrine/Tests/ORM/Tools/Export/ClassMetadataExporterTestCase.php index 2676ceff061..6d27b3c47f9 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/ClassMetadataExporterTestCase.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/ClassMetadataExporterTestCase.php @@ -66,7 +66,7 @@ protected function createEntityManager($metadataDriver): EntityManagerMock $config->setProxyNamespace('Doctrine\Tests\Proxies'); $config->setMetadataDriverImpl($metadataDriver); - return EntityManagerMock::create($connection, $config); + return new EntityManagerMock($connection, $config); } protected function createMetadataDriver(string $type, string $path): MappingDriver diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 2a12de35c27..b23452c8e87 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -116,7 +116,7 @@ protected function setUp(): void $this->eventManager = $this->getMockBuilder(EventManager::class)->getMock(); $this->_connectionMock = new Connection([], $driver, null, $this->eventManager); - $this->_emMock = EntityManagerMock::create($this->_connectionMock); + $this->_emMock = new EntityManagerMock($this->_connectionMock); // SUT $this->_unitOfWork = new UnitOfWorkMock($this->_emMock); $this->_emMock->setUnitOfWork($this->_unitOfWork); @@ -841,7 +841,7 @@ public function testCommitThrowOptimisticLockExceptionWhenConnectionCommitReturn $this->_connectionMock = $this->getMockBuilderWithOnlyMethods(ConnectionMock::class, ['commit']) ->setConstructorArgs([[], $driver]) ->getMock(); - $this->_emMock = EntityManagerMock::create($this->_connectionMock); + $this->_emMock = new EntityManagerMock($this->_connectionMock); $this->_unitOfWork = new UnitOfWorkMock($this->_emMock); $this->_emMock->setUnitOfWork($this->_unitOfWork); diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 4e96d5e410d..f0bdef69d38 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -830,7 +830,7 @@ protected function getEntityManager( $evm->addEventListener(['onFlush'], new DebugUnitOfWorkListener()); } - return EntityManager::create($conn, $config); + return new EntityManager($conn, $config); } final protected function createSchemaManager(): AbstractSchemaManager diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index 2a99c60aa2d..8cc988c6931 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -107,7 +107,7 @@ protected function getTestEntityManager(?Connection $connection = null): EntityM ], $config); } - return EntityManagerMock::create($connection, $config); + return new EntityManagerMock($connection, $config); } protected function enableSecondLevelCache(bool $log = true): void