From 532360e3e6290635be879448baba5e5388484386 Mon Sep 17 00:00:00 2001 From: Nicolas Olive Date: Mon, 4 Mar 2024 12:07:53 +0100 Subject: [PATCH] support doctrine/orm 3 --- bin/console | 2 + composer.json | 6 +- .../Functional/TestBundle/Entity/Product.php | 2 +- .../FakeDoctrineManagerRegistry.php | 25 ++--- .../ObjectMapper/FakeEntityManager.php | 105 ++++++++---------- src/PhpUnit/RefreshDatabaseTrait.php | 1 - 6 files changed, 65 insertions(+), 76 deletions(-) diff --git a/bin/console b/bin/console index d37a941..af9b900 100755 --- a/bin/console +++ b/bin/console @@ -10,6 +10,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + // Debug only set_time_limit(0); diff --git a/composer.json b/composer.json index a222fbf..05a2cd2 100644 --- a/composer.json +++ b/composer.json @@ -32,9 +32,9 @@ "require": { "php": "^8.2", - "doctrine/doctrine-bundle": "^2.5", - "doctrine/data-fixtures": "^1.5", - "doctrine/orm": "^2.10.0", + "doctrine/doctrine-bundle": "^2.11", + "doctrine/data-fixtures": "^1.7", + "doctrine/orm": "^2.19 || ^3", "doctrine/persistence": "^2.2 || ^3.0", "psr/log": "^1.0 || ^2.0 || ^3.0", "symfony/finder": "^6.4 || ^7.0", diff --git a/fixtures/Functional/TestBundle/Entity/Product.php b/fixtures/Functional/TestBundle/Entity/Product.php index 5730de9..edba7dd 100644 --- a/fixtures/Functional/TestBundle/Entity/Product.php +++ b/fixtures/Functional/TestBundle/Entity/Product.php @@ -26,7 +26,7 @@ class Product #[ORM\Column(type: 'string', length: 100)] protected $name; - #[ORM\Column(type: 'decimal', scale: 2)] + #[ORM\Column(type: 'decimal', precision: 10, scale: 2)] protected $price; #[ORM\Column(type: 'text')] diff --git a/fixtures/Persistence/FakeDoctrineManagerRegistry.php b/fixtures/Persistence/FakeDoctrineManagerRegistry.php index 3c80240..75d3f9c 100644 --- a/fixtures/Persistence/FakeDoctrineManagerRegistry.php +++ b/fixtures/Persistence/FakeDoctrineManagerRegistry.php @@ -26,57 +26,52 @@ public function getDefaultConnectionName(): string $this->__call(__METHOD__, func_get_args()); } - public function getConnection($name = null) + public function getConnection($name = null): void { $this->__call(__METHOD__, func_get_args()); } - public function getConnections() + public function getConnections(): void { $this->__call(__METHOD__, func_get_args()); } - public function getConnectionNames() + public function getConnectionNames(): void { $this->__call(__METHOD__, func_get_args()); } - public function getDefaultManagerName() + public function getDefaultManagerName(): void { $this->__call(__METHOD__, func_get_args()); } - public function getManager($name = null) + public function getManager($name = null): void { $this->__call(__METHOD__, func_get_args()); } - public function getManagers() + public function getManagers(): void { $this->__call(__METHOD__, func_get_args()); } - public function resetManager($name = null) + public function resetManager($name = null): void { $this->__call(__METHOD__, func_get_args()); } - public function getAliasNamespace($alias) + public function getManagerNames(): void { $this->__call(__METHOD__, func_get_args()); } - public function getManagerNames() + public function getRepository($persistentObject, $persistentManagerName = null): void { $this->__call(__METHOD__, func_get_args()); } - public function getRepository($persistentObject, $persistentManagerName = null) - { - $this->__call(__METHOD__, func_get_args()); - } - - public function getManagerForClass($class) + public function getManagerForClass($class): void { $this->__call(__METHOD__, func_get_args()); } diff --git a/fixtures/Persistence/ObjectMapper/FakeEntityManager.php b/fixtures/Persistence/ObjectMapper/FakeEntityManager.php index 72fbce1..a68b849 100644 --- a/fixtures/Persistence/ObjectMapper/FakeEntityManager.php +++ b/fixtures/Persistence/ObjectMapper/FakeEntityManager.php @@ -13,8 +13,21 @@ namespace Hautelook\AliceBundle\Persistence\ObjectMapper; +use Doctrine\Common\EventManager; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\LockMode; +use Doctrine\ORM\Cache; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Internal\Hydration\AbstractHydrator; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\ORM\NativeQuery; +use Doctrine\ORM\Proxy\ProxyFactory; +use Doctrine\ORM\Query; +use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\ORM\QueryBuilder; use function func_get_args; use Hautelook\AliceBundle\NotCallableTrait; @@ -22,202 +35,182 @@ class FakeEntityManager implements EntityManagerInterface { use NotCallableTrait; - public function getCache() + public function getCache(): ?Cache { $this->__call(__METHOD__, func_get_args()); } - public function getConnection() + public function getConnection(): Connection { $this->__call(__METHOD__, func_get_args()); } - public function getExpressionBuilder() + public function getExpressionBuilder(): Expr { $this->__call(__METHOD__, func_get_args()); } - public function beginTransaction() + public function beginTransaction(): void { $this->__call(__METHOD__, func_get_args()); } - public function transactional($func) + public function wrapInTransaction($func): mixed { $this->__call(__METHOD__, func_get_args()); } - public function commit() + public function commit(): void { $this->__call(__METHOD__, func_get_args()); } - public function rollback() + public function rollback(): void { $this->__call(__METHOD__, func_get_args()); } - public function createQuery($dql = '') + public function createQuery($dql = ''): Query { $this->__call(__METHOD__, func_get_args()); } - public function createNamedQuery($name) + public function createNativeQuery($sql, ResultSetMapping $rsm): NativeQuery { $this->__call(__METHOD__, func_get_args()); } - public function createNativeQuery($sql, ResultSetMapping $rsm) + public function createQueryBuilder(): QueryBuilder { $this->__call(__METHOD__, func_get_args()); } - public function createNamedNativeQuery($name) + public function getReference($entityName, $id): ?object { $this->__call(__METHOD__, func_get_args()); } - public function createQueryBuilder() + public function close(): void { $this->__call(__METHOD__, func_get_args()); } - public function getReference($entityName, $id) + public function copy($entity, $deep = false): void { $this->__call(__METHOD__, func_get_args()); } - public function getPartialReference($entityName, $identifier) + public function lock($entity, $lockMode, $lockVersion = null): void { $this->__call(__METHOD__, func_get_args()); } - public function close() + public function getEventManager(): EventManager { $this->__call(__METHOD__, func_get_args()); } - public function copy($entity, $deep = false) + public function getConfiguration(): \Doctrine\ORM\Configuration { $this->__call(__METHOD__, func_get_args()); } - public function lock($entity, $lockMode, $lockVersion = null) + public function isOpen(): bool { $this->__call(__METHOD__, func_get_args()); } - public function getEventManager() + public function getUnitOfWork(): \Doctrine\ORM\UnitOfWork { $this->__call(__METHOD__, func_get_args()); } - public function getConfiguration() + public function newHydrator($hydrationMode): AbstractHydrator { $this->__call(__METHOD__, func_get_args()); } - public function isOpen() + public function getProxyFactory(): ProxyFactory { $this->__call(__METHOD__, func_get_args()); } - public function getUnitOfWork() + public function getFilters(): Query\FilterCollection { $this->__call(__METHOD__, func_get_args()); } - public function getHydrator($hydrationMode) + public function isFiltersStateClean(): bool { $this->__call(__METHOD__, func_get_args()); } - public function newHydrator($hydrationMode) + public function hasFilters(): bool { $this->__call(__METHOD__, func_get_args()); } - public function getProxyFactory() + public function find($className, $id, LockMode|int|null $lockMode = null, int|null $lockVersion = null): ?object { $this->__call(__METHOD__, func_get_args()); } - public function getFilters() + public function persist($object): void { $this->__call(__METHOD__, func_get_args()); } - public function isFiltersStateClean() + public function remove($object): void { $this->__call(__METHOD__, func_get_args()); } - public function hasFilters() + public function merge($object): void { $this->__call(__METHOD__, func_get_args()); } - public function find($className, $id) + public function clear($objectName = null): void { $this->__call(__METHOD__, func_get_args()); } - public function persist($object) + public function detach($object): void { $this->__call(__METHOD__, func_get_args()); } - public function remove($object) + public function refresh($object, LockMode|int|null $lockMode = null): void { $this->__call(__METHOD__, func_get_args()); } - public function merge($object) + public function flush(): void { $this->__call(__METHOD__, func_get_args()); } - public function clear($objectName = null) + public function getRepository($className): EntityRepository { $this->__call(__METHOD__, func_get_args()); } - public function detach($object) + public function getMetadataFactory(): ClassMetadataFactory { $this->__call(__METHOD__, func_get_args()); } - public function refresh($object) + public function initializeObject($obj): void { $this->__call(__METHOD__, func_get_args()); } - public function flush() + public function contains($object): void { $this->__call(__METHOD__, func_get_args()); } - public function getRepository($className) - { - $this->__call(__METHOD__, func_get_args()); - } - - public function getMetadataFactory() - { - $this->__call(__METHOD__, func_get_args()); - } - - public function initializeObject($obj) - { - $this->__call(__METHOD__, func_get_args()); - } - - public function contains($object) - { - $this->__call(__METHOD__, func_get_args()); - } - - public function getClassMetadata($className) + public function getClassMetadata($className): ClassMetadata { $this->__call(__METHOD__, func_get_args()); } diff --git a/src/PhpUnit/RefreshDatabaseTrait.php b/src/PhpUnit/RefreshDatabaseTrait.php index 1b64101..cbed298 100644 --- a/src/PhpUnit/RefreshDatabaseTrait.php +++ b/src/PhpUnit/RefreshDatabaseTrait.php @@ -43,7 +43,6 @@ protected static function bootKernel(array $options = []): KernelInterface ->get('doctrine') ->getConnection(FixtureStore::getConnectionName()); - $connection->setNestTransactionsWithSavepoints(true); $connection->beginTransaction(); return $kernel;