diff --git a/UPGRADE.md b/UPGRADE.md index dd4aa66f901..01d4dd7704b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,12 @@ # Upgrade to 2.11 +## Rename `AbstractIdGenerator::generate()` to `generateId()` + +Implementations of `AbstractIdGenerator` have to override the method +`generateId()` without calling the parent implementation. Not doing so is +deprecated. Calling `generate()` on any `AbstractIdGenerator` implementation +is deprecated. + ## Deprecated: `Setup::registerAutoloadDirectory()` Use Composer's autoloader instead. diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 3ae7f812b9c..20eb08e8ab0 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -39,7 +39,7 @@ class EntityRepository implements ObjectRepository, Selectable /** @var string */ protected $_entityName; - /** @var EntityManager */ + /** @var EntityManagerInterface */ protected $_em; /** @var ClassMetadata */ @@ -282,7 +282,7 @@ public function getClassName() } /** - * @return EntityManager + * @return EntityManagerInterface */ protected function getEntityManager() { diff --git a/lib/Doctrine/ORM/Event/LifecycleEventArgs.php b/lib/Doctrine/ORM/Event/LifecycleEventArgs.php index 21a6ccdb98f..24a0bf22d5f 100644 --- a/lib/Doctrine/ORM/Event/LifecycleEventArgs.php +++ b/lib/Doctrine/ORM/Event/LifecycleEventArgs.php @@ -4,7 +4,7 @@ namespace Doctrine\ORM\Event; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\Event\LifecycleEventArgs as BaseLifecycleEventArgs; /** @@ -28,7 +28,7 @@ public function getEntity() /** * Retrieves associated EntityManager. * - * @return EntityManager + * @return EntityManagerInterface */ public function getEntityManager() { diff --git a/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php b/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php index e7e81fa5b8c..815575cf2b7 100644 --- a/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php +++ b/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php @@ -4,14 +4,14 @@ namespace Doctrine\ORM\Event; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Persistence\Event\LoadClassMetadataEventArgs as BaseLoadClassMetadataEventArgs; /** * Class that holds event arguments for a loadMetadata event. * - * @method __construct(ClassMetadata $classMetadata, EntityManager $objectManager) + * @method __construct(ClassMetadata $classMetadata, EntityManagerInterface $objectManager) * @method ClassMetadata getClassMetadata() */ class LoadClassMetadataEventArgs extends BaseLoadClassMetadataEventArgs @@ -19,7 +19,7 @@ class LoadClassMetadataEventArgs extends BaseLoadClassMetadataEventArgs /** * Retrieve associated EntityManager. * - * @return EntityManager + * @return EntityManagerInterface */ public function getEntityManager() { diff --git a/lib/Doctrine/ORM/Event/PostFlushEventArgs.php b/lib/Doctrine/ORM/Event/PostFlushEventArgs.php index e7eae7d4464..1e7c06b6a7f 100644 --- a/lib/Doctrine/ORM/Event/PostFlushEventArgs.php +++ b/lib/Doctrine/ORM/Event/PostFlushEventArgs.php @@ -5,7 +5,6 @@ namespace Doctrine\ORM\Event; use Doctrine\Common\EventArgs; -use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; /** @@ -15,7 +14,7 @@ */ class PostFlushEventArgs extends EventArgs { - /** @var EntityManager */ + /** @var EntityManagerInterface */ private $em; public function __construct(EntityManagerInterface $em) @@ -26,7 +25,7 @@ public function __construct(EntityManagerInterface $em) /** * Retrieves associated EntityManager. * - * @return EntityManager + * @return EntityManagerInterface */ public function getEntityManager() { diff --git a/lib/Doctrine/ORM/Event/PreFlushEventArgs.php b/lib/Doctrine/ORM/Event/PreFlushEventArgs.php index 3847afe44b5..c7d2fef4885 100644 --- a/lib/Doctrine/ORM/Event/PreFlushEventArgs.php +++ b/lib/Doctrine/ORM/Event/PreFlushEventArgs.php @@ -5,7 +5,6 @@ namespace Doctrine\ORM\Event; use Doctrine\Common\EventArgs; -use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; /** @@ -15,7 +14,7 @@ */ class PreFlushEventArgs extends EventArgs { - /** @var EntityManager */ + /** @var EntityManagerInterface */ private $em; public function __construct(EntityManagerInterface $em) @@ -24,7 +23,7 @@ public function __construct(EntityManagerInterface $em) } /** - * @return EntityManager + * @return EntityManagerInterface */ public function getEntityManager() { diff --git a/lib/Doctrine/ORM/Id/AbstractIdGenerator.php b/lib/Doctrine/ORM/Id/AbstractIdGenerator.php index 397d5ea1123..dcbac46fcad 100644 --- a/lib/Doctrine/ORM/Id/AbstractIdGenerator.php +++ b/lib/Doctrine/ORM/Id/AbstractIdGenerator.php @@ -4,19 +4,50 @@ namespace Doctrine\ORM\Id; +use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; +use InvalidArgumentException; + +use function get_debug_type; abstract class AbstractIdGenerator { /** * Generates an identifier for an entity. * + * @deprecated Call {@see generateId()} instead. + * * @param object|null $entity * * @return mixed */ abstract public function generate(EntityManager $em, $entity); + /** + * Generates an identifier for an entity. + * + * @param object|null $entity + * + * @return mixed + */ + public function generateId(EntityManagerInterface $em, $entity) + { + Deprecation::trigger( + 'doctrine/orm', + 'TODO', + 'Not implementing %s in %s is deprecated.', + __FUNCTION__, + get_debug_type($this) + ); + + if (! $em instanceof EntityManager) { + throw new InvalidArgumentException('Unsupported entity manager implementation.'); + } + + return $this->generate($em, $entity); + } + /** * Gets whether this generator is a post-insert generator which means that * {@link generate()} must be called after the entity has been inserted diff --git a/lib/Doctrine/ORM/Id/AssignedGenerator.php b/lib/Doctrine/ORM/Id/AssignedGenerator.php index 52a4c49f1a1..fc0c57c3c4e 100644 --- a/lib/Doctrine/ORM/Id/AssignedGenerator.php +++ b/lib/Doctrine/ORM/Id/AssignedGenerator.php @@ -4,7 +4,7 @@ namespace Doctrine\ORM\Id; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Exception\EntityMissingAssignedId; use function get_class; @@ -14,14 +14,16 @@ */ class AssignedGenerator extends AbstractIdGenerator { + use LegacyIdGeneratorProxy; + /** * Returns the identifier assigned to the given entity. * - * {@inheritDoc} + * {@inheritdoc} * * @throws EntityMissingAssignedId */ - public function generate(EntityManager $em, $entity) + public function generateId(EntityManagerInterface $em, $entity) { $class = $em->getClassMetadata(get_class($entity)); $idFields = $class->getIdentifierFieldNames(); diff --git a/lib/Doctrine/ORM/Id/BigIntegerIdentityGenerator.php b/lib/Doctrine/ORM/Id/BigIntegerIdentityGenerator.php index 4d8391335ce..4cdfc9555e8 100644 --- a/lib/Doctrine/ORM/Id/BigIntegerIdentityGenerator.php +++ b/lib/Doctrine/ORM/Id/BigIntegerIdentityGenerator.php @@ -4,7 +4,7 @@ namespace Doctrine\ORM\Id; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; /** * Id generator that obtains IDs from special "identity" columns. These are columns @@ -13,6 +13,8 @@ */ class BigIntegerIdentityGenerator extends AbstractIdGenerator { + use LegacyIdGeneratorProxy; + /** * The name of the sequence to pass to lastInsertId(), if any. * @@ -33,7 +35,7 @@ public function __construct($sequenceName = null) /** * {@inheritDoc} */ - public function generate(EntityManager $em, $entity) + public function generateId(EntityManagerInterface $em, $entity) { return (string) $em->getConnection()->lastInsertId($this->sequenceName); } diff --git a/lib/Doctrine/ORM/Id/IdentityGenerator.php b/lib/Doctrine/ORM/Id/IdentityGenerator.php index 84ba4eeeab2..40b8479c6fc 100644 --- a/lib/Doctrine/ORM/Id/IdentityGenerator.php +++ b/lib/Doctrine/ORM/Id/IdentityGenerator.php @@ -4,7 +4,7 @@ namespace Doctrine\ORM\Id; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; /** * Id generator that obtains IDs from special "identity" columns. These are columns @@ -13,6 +13,8 @@ */ class IdentityGenerator extends AbstractIdGenerator { + use LegacyIdGeneratorProxy; + /** * The name of the sequence to pass to lastInsertId(), if any. * @@ -33,7 +35,7 @@ public function __construct($sequenceName = null) /** * {@inheritDoc} */ - public function generate(EntityManager $em, $entity) + public function generateId(EntityManagerInterface $em, $entity) { return (int) $em->getConnection()->lastInsertId($this->sequenceName); } diff --git a/lib/Doctrine/ORM/Id/LegacyIdGeneratorProxy.php b/lib/Doctrine/ORM/Id/LegacyIdGeneratorProxy.php new file mode 100644 index 00000000000..dcd8ddc15d5 --- /dev/null +++ b/lib/Doctrine/ORM/Id/LegacyIdGeneratorProxy.php @@ -0,0 +1,32 @@ +generateId($em, $entity); + } +} diff --git a/lib/Doctrine/ORM/Id/SequenceGenerator.php b/lib/Doctrine/ORM/Id/SequenceGenerator.php index 9b194859d38..0fb4487b1ad 100644 --- a/lib/Doctrine/ORM/Id/SequenceGenerator.php +++ b/lib/Doctrine/ORM/Id/SequenceGenerator.php @@ -5,7 +5,7 @@ namespace Doctrine\ORM\Id; use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Serializable; use function serialize; @@ -16,6 +16,8 @@ */ class SequenceGenerator extends AbstractIdGenerator implements Serializable { + use LegacyIdGeneratorProxy; + /** * The allocation size of the sequence. * @@ -51,7 +53,7 @@ public function __construct($sequenceName, $allocationSize) /** * {@inheritDoc} */ - public function generate(EntityManager $em, $entity) + public function generateId(EntityManagerInterface $em, $entity) { if ($this->_maxValue === null || $this->_nextValue === $this->_maxValue) { // Allocate new values diff --git a/lib/Doctrine/ORM/Id/TableGenerator.php b/lib/Doctrine/ORM/Id/TableGenerator.php index c65b5272617..8bd2d02ff50 100644 --- a/lib/Doctrine/ORM/Id/TableGenerator.php +++ b/lib/Doctrine/ORM/Id/TableGenerator.php @@ -4,7 +4,7 @@ namespace Doctrine\ORM\Id; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; /** * Id generator that uses a single-row database table and a hi/lo algorithm. @@ -13,6 +13,8 @@ */ class TableGenerator extends AbstractIdGenerator { + use LegacyIdGeneratorProxy; + /** @var string */ private $_tableName; @@ -43,8 +45,8 @@ public function __construct($tableName, $sequenceName = 'default', $allocationSi /** * {@inheritDoc} */ - public function generate( - EntityManager $em, + public function generateId( + EntityManagerInterface $em, $entity ) { if ($this->_maxValue === null || $this->_nextValue === $this->_maxValue) { diff --git a/lib/Doctrine/ORM/Id/UuidGenerator.php b/lib/Doctrine/ORM/Id/UuidGenerator.php index e701c52fbbe..50d44c0af0f 100644 --- a/lib/Doctrine/ORM/Id/UuidGenerator.php +++ b/lib/Doctrine/ORM/Id/UuidGenerator.php @@ -7,7 +7,7 @@ use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\Deprecations\Deprecation; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Exception\NotSupported; use function method_exists; @@ -19,6 +19,8 @@ */ class UuidGenerator extends AbstractIdGenerator { + use LegacyIdGeneratorProxy; + public function __construct() { Deprecation::trigger( @@ -38,7 +40,7 @@ public function __construct() * * @throws NotSupported */ - public function generate(EntityManager $em, $entity) + public function generateId(EntityManagerInterface $em, $entity) { $connection = $em->getConnection(); $sql = 'SELECT ' . $connection->getDatabasePlatform()->getGuidExpression(); diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 4a32448fbc8..76b5d012321 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -274,7 +274,7 @@ public function executeInserts() $stmt->executeStatement(); if ($isPostInsertId) { - $generatedId = $idGenerator->generate($this->em, $entity); + $generatedId = $idGenerator->generateId($this->em, $entity); $id = [$this->class->identifier[0] => $generatedId]; $postInsertIds[] = [ 'generatedId' => $generatedId, diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index 5c59168eb75..ed58ab18c5e 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -158,7 +158,7 @@ public function executeInserts() $rootTableStmt->executeStatement(); if ($isPostInsertId) { - $generatedId = $idGenerator->generate($this->em, $entity); + $generatedId = $idGenerator->generateId($this->em, $entity); $id = [$this->class->identifier[0] => $generatedId]; $postInsertIds[] = [ 'generatedId' => $generatedId, diff --git a/lib/Doctrine/ORM/Query/FilterCollection.php b/lib/Doctrine/ORM/Query/FilterCollection.php index cedbd8a8d5e..7e9ac71bab9 100644 --- a/lib/Doctrine/ORM/Query/FilterCollection.php +++ b/lib/Doctrine/ORM/Query/FilterCollection.php @@ -5,7 +5,6 @@ namespace Doctrine\ORM\Query; use Doctrine\ORM\Configuration; -use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\Filter\SQLFilter; use InvalidArgumentException; @@ -40,7 +39,7 @@ class FilterCollection /** * The EntityManager that "owns" this FilterCollection instance. * - * @var EntityManager + * @var EntityManagerInterface */ private $em; diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 927cb845b33..4e5f0f0d758 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -979,7 +979,7 @@ private function persistNew(ClassMetadata $class, $entity): void $idGen = $class->idGenerator; if (! $idGen->isPostInsertGenerator()) { - $idValue = $idGen->generate($this->em, $entity); + $idValue = $idGen->generateId($this->em, $entity); if (! $idGen instanceof AssignedGenerator) { $idValue = [$class->getSingleIdentifierFieldName() => $this->convertSingleFieldIdentifierToPHPValue($class, $idValue)]; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 255f15da3c2..80301bd8d1c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -181,34 +181,29 @@ parameters: path: lib/Doctrine/ORM/EntityManagerInterface.php - - message: "#^Method Doctrine\\\\ORM\\\\EntityRepository\\:\\:findOneBy\\(\\) should return T\\|null but returns object\\|null\\.$#" + message: "#^Method Doctrine\\\\ORM\\\\EntityRepository\\:\\:find\\(\\) should return T\\|null but returns object\\|null\\.$#" count: 1 path: lib/Doctrine/ORM/EntityRepository.php - - message: "#^Property Doctrine\\\\ORM\\\\EntityRepository\\\\:\\:\\$_em \\(Doctrine\\\\ORM\\\\EntityManager\\) does not accept Doctrine\\\\ORM\\\\EntityManagerInterface\\.$#" + message: "#^Method Doctrine\\\\ORM\\\\EntityRepository\\:\\:findOneBy\\(\\) should return T\\|null but returns object\\|null\\.$#" count: 1 path: lib/Doctrine/ORM/EntityRepository.php - - message: "#^Method Doctrine\\\\ORM\\\\Event\\\\LifecycleEventArgs\\:\\:getEntityManager\\(\\) should return Doctrine\\\\ORM\\\\EntityManager but returns Doctrine\\\\Persistence\\\\ObjectManager\\.$#" - count: 1 - path: lib/Doctrine/ORM/Event/LifecycleEventArgs.php - - - - message: "#^Method Doctrine\\\\ORM\\\\Event\\\\LoadClassMetadataEventArgs\\:\\:getEntityManager\\(\\) should return Doctrine\\\\ORM\\\\EntityManager but returns Doctrine\\\\Persistence\\\\ObjectManager\\.$#" + message: "#^Method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:find\\(\\) invoked with 4 parameters, 2 required\\.$#" count: 1 - path: lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php + path: lib/Doctrine/ORM/EntityRepository.php - - message: "#^Property Doctrine\\\\ORM\\\\Event\\\\PostFlushEventArgs\\:\\:\\$em \\(Doctrine\\\\ORM\\\\EntityManager\\) does not accept Doctrine\\\\ORM\\\\EntityManagerInterface\\.$#" + message: "#^Method Doctrine\\\\ORM\\\\Event\\\\LifecycleEventArgs\\:\\:getEntityManager\\(\\) should return Doctrine\\\\ORM\\\\EntityManagerInterface but returns Doctrine\\\\Persistence\\\\ObjectManager\\.$#" count: 1 - path: lib/Doctrine/ORM/Event/PostFlushEventArgs.php + path: lib/Doctrine/ORM/Event/LifecycleEventArgs.php - - message: "#^Property Doctrine\\\\ORM\\\\Event\\\\PreFlushEventArgs\\:\\:\\$em \\(Doctrine\\\\ORM\\\\EntityManager\\) does not accept Doctrine\\\\ORM\\\\EntityManagerInterface\\.$#" + message: "#^Method Doctrine\\\\ORM\\\\Event\\\\LoadClassMetadataEventArgs\\:\\:getEntityManager\\(\\) should return Doctrine\\\\ORM\\\\EntityManagerInterface but returns Doctrine\\\\Persistence\\\\ObjectManager\\.$#" count: 1 - path: lib/Doctrine/ORM/Event/PreFlushEventArgs.php + path: lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php - message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Platforms\\\\AbstractPlatform\\:\\:getTableHiLoCurrentValSql\\(\\)\\.$#" @@ -740,11 +735,6 @@ parameters: count: 1 path: lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php - - - message: "#^Parameter \\#1 \\$em of method Doctrine\\\\ORM\\\\Id\\\\AbstractIdGenerator\\:\\:generate\\(\\) expects Doctrine\\\\ORM\\\\EntityManager, Doctrine\\\\ORM\\\\EntityManagerInterface given\\.$#" - count: 1 - path: lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php - - message: "#^Parameter \\#3 \\$hints of method Doctrine\\\\ORM\\\\Internal\\\\Hydration\\\\AbstractHydrator\\:\\:hydrateAll\\(\\) expects array\\, array\\ given\\.$#" count: 1 @@ -775,11 +765,6 @@ parameters: count: 1 path: lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php - - - message: "#^Parameter \\#1 \\$em of method Doctrine\\\\ORM\\\\Id\\\\AbstractIdGenerator\\:\\:generate\\(\\) expects Doctrine\\\\ORM\\\\EntityManager, Doctrine\\\\ORM\\\\EntityManagerInterface given\\.$#" - count: 1 - path: lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php - - message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$isEmbeddedClass\\.$#" count: 1 @@ -970,11 +955,6 @@ parameters: count: 1 path: lib/Doctrine/ORM/Query/Expr/Select.php - - - message: "#^Property Doctrine\\\\ORM\\\\Query\\\\FilterCollection\\:\\:\\$em \\(Doctrine\\\\ORM\\\\EntityManager\\) does not accept Doctrine\\\\ORM\\\\EntityManagerInterface\\.$#" - count: 1 - path: lib/Doctrine/ORM/Query/FilterCollection.php - - message: "#^Property Doctrine\\\\ORM\\\\Query\\\\FilterCollection\\:\\:\\$filterHash is never written, only read\\.$#" count: 1 @@ -1875,11 +1855,6 @@ parameters: count: 1 path: lib/Doctrine/ORM/UnitOfWork.php - - - message: "#^Parameter \\#1 \\$em of method Doctrine\\\\ORM\\\\Id\\\\AbstractIdGenerator\\:\\:generate\\(\\) expects Doctrine\\\\ORM\\\\EntityManager, Doctrine\\\\ORM\\\\EntityManagerInterface given\\.$#" - count: 1 - path: lib/Doctrine/ORM/UnitOfWork.php - - message: "#^Parameter \\#3 \\$changeSet of class Doctrine\\\\ORM\\\\Event\\\\PreUpdateEventArgs constructor is passed by reference, so it expects variables only$#" count: 1 @@ -1904,3 +1879,4 @@ parameters: message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$subClasses\\.$#" count: 1 path: lib/Doctrine/ORM/Utility/HierarchyDiscriminatorResolver.php + diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 65912e695df..41c23aba3e5 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -503,16 +503,16 @@ ?T Collection<int, T> - - $em - + + find + $this->getObjectManager() - EntityManager + EntityManagerInterface @@ -520,7 +520,7 @@ $this->getObjectManager() - EntityManager + EntityManagerInterface @@ -528,16 +528,6 @@ (string) $className - - - $em - - - - - $em - - BaseORMException @@ -1572,9 +1562,6 @@ - - $this->em - $value === null @@ -1655,9 +1642,6 @@ - - $this->em - $postInsertIds @@ -2392,8 +2376,7 @@ $filterHash - - $em + $this->enabledFilters @@ -3498,13 +3481,12 @@ - + $class $class $collectionToDelete $collectionToUpdate $commitOrder[$i] - $this->em ! is_object($object) diff --git a/psalm.xml b/psalm.xml index 75039c541c7..95b580757a0 100644 --- a/psalm.xml +++ b/psalm.xml @@ -46,6 +46,7 @@ + diff --git a/tests/Doctrine/Tests/EventListener/CacheMetadataListener.php b/tests/Doctrine/Tests/EventListener/CacheMetadataListener.php index 5d441603069..612a90a9c3a 100644 --- a/tests/Doctrine/Tests/EventListener/CacheMetadataListener.php +++ b/tests/Doctrine/Tests/EventListener/CacheMetadataListener.php @@ -4,7 +4,7 @@ namespace Doctrine\Tests\EventListener; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Persistence\Event\LoadClassMetadataEventArgs; @@ -46,7 +46,7 @@ private function recordVisit(ClassMetadata $metadata): void $this->enabledItems[$metadata->getName()] = true; } - protected function enableCaching(ClassMetadata $metadata, EntityManager $em): void + protected function enableCaching(ClassMetadata $metadata, EntityManagerInterface $em): void { if ($this->isVisited($metadata)) { return; // Already handled in the past diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php index 88f3fa10205..d474caa91c5 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php @@ -19,7 +19,7 @@ use Doctrine\ORM\Cache\Region\DefaultMultiGetRegion; use Doctrine\ORM\Cache\Region\DefaultRegion; use Doctrine\ORM\Cache\RegionsConfiguration; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Persisters\Collection\OneToManyPersister; use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; @@ -43,7 +43,7 @@ class DefaultCacheFactoryTest extends OrmTestCase /** @var CacheFactory&MockObject */ private $factory; - /** @var EntityManager */ + /** @var EntityManagerInterface */ private $em; /** @var RegionsConfiguration */ diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php index bd5eaeac4dd..702874eab7e 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php @@ -10,7 +10,7 @@ use Doctrine\ORM\Cache\EntityCacheEntry; use Doctrine\ORM\Cache\EntityCacheKey; use Doctrine\ORM\Cache\EntityHydrator; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Models\Cache\Country; use Doctrine\Tests\Models\Cache\State; @@ -24,7 +24,7 @@ class DefaultEntityHydratorTest extends OrmTestCase /** @var EntityHydrator */ private $structure; - /** @var EntityManager */ + /** @var EntityManagerInterface */ private $em; protected function setUp(): void diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php index 17be99bd187..cae81dc113c 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php @@ -13,7 +13,6 @@ use Doctrine\ORM\Cache\QueryCache; use Doctrine\ORM\Cache\QueryCacheEntry; use Doctrine\ORM\Cache\QueryCacheKey; -use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\ResultSetMappingBuilder; use Doctrine\Tests\Mocks\CacheEntryMock; @@ -38,7 +37,7 @@ class DefaultQueryCacheTest extends OrmTestCase /** @var DefaultQueryCache */ private $queryCache; - /** @var EntityManager */ + /** @var EntityManagerInterface */ private $em; /** @var CacheRegionMock */ diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php index 75bded05593..9be04ff174b 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php @@ -9,7 +9,7 @@ use Doctrine\ORM\Cache\Persister\Collection\AbstractCollectionPersister; use Doctrine\ORM\Cache\Persister\Collection\CachedCollectionPersister; use Doctrine\ORM\Cache\Region; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Persisters\Collection\CollectionPersister; use Doctrine\Tests\Models\Cache\State; @@ -27,7 +27,7 @@ abstract class AbstractCollectionPersisterTest extends OrmTestCase /** @var CollectionPersister */ protected $collectionPersister; - /** @var EntityManager */ + /** @var EntityManagerInterface */ protected $em; /** @var array */ @@ -56,7 +56,7 @@ abstract class AbstractCollectionPersisterTest extends OrmTestCase 'loadCriteria', ]; - abstract protected function createPersister(EntityManager $em, CollectionPersister $persister, Region $region, array $mapping): AbstractCollectionPersister; + abstract protected function createPersister(EntityManagerInterface $em, CollectionPersister $persister, Region $region, array $mapping): AbstractCollectionPersister; protected function setUp(): void { diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/NonStrictReadWriteCachedCollectionPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/NonStrictReadWriteCachedCollectionPersisterTest.php index a36a4a8b9bc..6e014627533 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/NonStrictReadWriteCachedCollectionPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/NonStrictReadWriteCachedCollectionPersisterTest.php @@ -7,7 +7,7 @@ use Doctrine\ORM\Cache\Persister\Collection\AbstractCollectionPersister; use Doctrine\ORM\Cache\Persister\Collection\NonStrictReadWriteCachedCollectionPersister; use Doctrine\ORM\Cache\Region; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Persisters\Collection\CollectionPersister; /** @@ -18,7 +18,7 @@ class NonStrictReadWriteCachedCollectionPersisterTest extends AbstractCollection /** * {@inheritdoc} */ - protected function createPersister(EntityManager $em, CollectionPersister $persister, Region $region, array $mapping): AbstractCollectionPersister + protected function createPersister(EntityManagerInterface $em, CollectionPersister $persister, Region $region, array $mapping): AbstractCollectionPersister { return new NonStrictReadWriteCachedCollectionPersister($persister, $region, $em, $mapping); } diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadOnlyCachedCollectionPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadOnlyCachedCollectionPersisterTest.php index e074409bb2e..9dbbb2a5f76 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadOnlyCachedCollectionPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadOnlyCachedCollectionPersisterTest.php @@ -7,7 +7,7 @@ use Doctrine\ORM\Cache\Persister\Collection\AbstractCollectionPersister; use Doctrine\ORM\Cache\Persister\Collection\ReadOnlyCachedCollectionPersister; use Doctrine\ORM\Cache\Region; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Persisters\Collection\CollectionPersister; /** @@ -15,7 +15,7 @@ */ class ReadOnlyCachedCollectionPersisterTest extends AbstractCollectionPersisterTest { - protected function createPersister(EntityManager $em, CollectionPersister $persister, Region $region, array $mapping): AbstractCollectionPersister + protected function createPersister(EntityManagerInterface $em, CollectionPersister $persister, Region $region, array $mapping): AbstractCollectionPersister { return new ReadOnlyCachedCollectionPersister($persister, $region, $em, $mapping); } diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php index 60a95fa0297..b7a0c662696 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php @@ -10,7 +10,7 @@ use Doctrine\ORM\Cache\Persister\Collection\AbstractCollectionPersister; use Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister; use Doctrine\ORM\Cache\Region; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Persisters\Collection\CollectionPersister; use Doctrine\Tests\Models\Cache\State; use ReflectionProperty; @@ -33,7 +33,7 @@ class ReadWriteCachedCollectionPersisterTest extends AbstractCollectionPersister 'unlock', ]; - protected function createPersister(EntityManager $em, CollectionPersister $persister, Region $region, array $mapping): AbstractCollectionPersister + protected function createPersister(EntityManagerInterface $em, CollectionPersister $persister, Region $region, array $mapping): AbstractCollectionPersister { return new ReadWriteCachedCollectionPersister($persister, $region, $em, $mapping); } diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php index b387e46826e..7281e9f95f4 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php @@ -10,7 +10,7 @@ use Doctrine\ORM\Cache\Persister\Entity\AbstractEntityPersister; use Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister; use Doctrine\ORM\Cache\Region; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Persisters\Entity\EntityPersister; @@ -30,10 +30,10 @@ abstract class AbstractEntityPersisterTest extends OrmTestCase /** @var EntityPersister&MockObject */ protected $entityPersister; - /** @var EntityManager */ + /** @var EntityManagerInterface */ protected $em; - abstract protected function createPersister(EntityManager $em, EntityPersister $persister, Region $region, ClassMetadata $metadata): AbstractEntityPersister; + abstract protected function createPersister(EntityManagerInterface $em, EntityPersister $persister, Region $region, ClassMetadata $metadata): AbstractEntityPersister; protected function setUp(): void { diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php index 24ae0390abe..46f6a9b4fdc 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php @@ -9,7 +9,7 @@ use Doctrine\ORM\Cache\Persister\Entity\AbstractEntityPersister; use Doctrine\ORM\Cache\Persister\Entity\NonStrictReadWriteCachedEntityPersister; use Doctrine\ORM\Cache\Region; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Persisters\Entity\EntityPersister; use Doctrine\Tests\Models\Cache\Country; @@ -20,7 +20,7 @@ */ class NonStrictReadWriteCachedEntityPersisterTest extends AbstractEntityPersisterTest { - protected function createPersister(EntityManager $em, EntityPersister $persister, Region $region, ClassMetadata $metadata): AbstractEntityPersister + protected function createPersister(EntityManagerInterface $em, EntityPersister $persister, Region $region, ClassMetadata $metadata): AbstractEntityPersister { return new NonStrictReadWriteCachedEntityPersister($persister, $region, $em, $metadata); } diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadOnlyCachedEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadOnlyCachedEntityPersisterTest.php index aab93323545..e8214f18afd 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadOnlyCachedEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadOnlyCachedEntityPersisterTest.php @@ -8,7 +8,7 @@ use Doctrine\ORM\Cache\Persister\Entity\AbstractEntityPersister; use Doctrine\ORM\Cache\Persister\Entity\ReadOnlyCachedEntityPersister; use Doctrine\ORM\Cache\Region; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Persisters\Entity\EntityPersister; use Doctrine\Tests\Models\Cache\Country; @@ -18,7 +18,7 @@ */ class ReadOnlyCachedEntityPersisterTest extends AbstractEntityPersisterTest { - protected function createPersister(EntityManager $em, EntityPersister $persister, Region $region, ClassMetadata $metadata): AbstractEntityPersister + protected function createPersister(EntityManagerInterface $em, EntityPersister $persister, Region $region, ClassMetadata $metadata): AbstractEntityPersister { return new ReadOnlyCachedEntityPersister($persister, $region, $em, $metadata); } diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php index 34c0f273665..9a25b959002 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php @@ -10,7 +10,7 @@ use Doctrine\ORM\Cache\Persister\Entity\AbstractEntityPersister; use Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister; use Doctrine\ORM\Cache\Region; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Persisters\Entity\EntityPersister; use Doctrine\Tests\Models\Cache\Country; @@ -21,7 +21,7 @@ */ class ReadWriteCachedEntityPersisterTest extends AbstractEntityPersisterTest { - protected function createPersister(EntityManager $em, EntityPersister $persister, Region $region, ClassMetadata $metadata): AbstractEntityPersister + protected function createPersister(EntityManagerInterface $em, EntityPersister $persister, Region $region, ClassMetadata $metadata): AbstractEntityPersister { return new ReadWriteCachedEntityPersister($persister, $region, $em, $metadata); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToOneOrphanRemovalTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToOneOrphanRemovalTest.php index 6f4f0fdb0e7..55985aa74eb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToOneOrphanRemovalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToOneOrphanRemovalTest.php @@ -5,7 +5,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\DBAL\Connection; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriver; use Doctrine\Tests\Models\OrnementalOrphanRemoval\Person; @@ -87,7 +87,7 @@ public function testOrphanRemovalIsPurelyOrnemental(): void protected function getEntityManager( ?Connection $connection = null, ?MappingDriver $mappingDriver = null - ): EntityManager { + ): EntityManagerInterface { return parent::getEntityManager($connection, new XmlDriver( __DIR__ . DIRECTORY_SEPARATOR . 'xml' )); diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php index 6677def1a3c..31185b518b6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php @@ -10,6 +10,7 @@ use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\Models\Generic\DateTimeModel; @@ -233,7 +234,7 @@ public function testMergingUnInitializedProxyDoesNotInitializeIt(): void ); } - private function createEntityManager(SQLLogger $logger): EntityManager + private function createEntityManager(SQLLogger $logger): EntityManagerInterface { $config = new Configuration(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php index 0c74c1fe92c..b1904bf9349 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php @@ -4,8 +4,9 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Id\AbstractIdGenerator; +use Doctrine\ORM\Id\LegacyIdGeneratorProxy; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\Driver\StaticPHPDriver; use Doctrine\Tests\OrmFunctionalTestCase; @@ -108,7 +109,9 @@ public static function loadMetadata(ClassMetadataInfo $metadata): void class DDC2415Generator extends AbstractIdGenerator { - public function generate(EntityManager $em, $entity): string + use LegacyIdGeneratorProxy; + + public function generateId(EntityManagerInterface $em, $entity): string { return md5($entity->getName()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php index 8bad22705dd..e2df6402a81 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php @@ -6,8 +6,9 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Id\AbstractIdGenerator; +use Doctrine\ORM\Id\LegacyIdGeneratorProxy; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\CustomIdGenerator; use Doctrine\ORM\Mapping\Entity; @@ -51,10 +52,12 @@ public function testTextColumnSaveAndRetrieve2(): void final class GH5804Generator extends AbstractIdGenerator { + use LegacyIdGeneratorProxy; + /** * {@inheritdoc} */ - public function generate(EntityManager $em, $entity) + public function generateId(EntityManagerInterface $em, $entity) { return 'test5804'; } diff --git a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php index 7ac96c37efd..fef4eb0793d 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php @@ -4,7 +4,7 @@ namespace Doctrine\Tests\ORM\Hydration; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Query\ResultSetMappingBuilder; @@ -24,7 +24,7 @@ class ResultSetMappingTest extends OrmTestCase /** @var ResultSetMapping */ private $_rsm; - /** @var EntityManager */ + /** @var EntityManagerInterface */ private $entityManager; protected function setUp(): void diff --git a/tests/Doctrine/Tests/ORM/Id/AbstractIdGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/AbstractIdGeneratorTest.php new file mode 100644 index 00000000000..9b9ee0fe730 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Id/AbstractIdGeneratorTest.php @@ -0,0 +1,47 @@ +receivedEm = $em; + $this->receivedEntity = $entity; + + return '4711'; + } + }; + + $em = $this->createMock(EntityManager::class); + $entity = new stdClass(); + + $this->expectDeprecationWithIdentifier('TODO'); + + self::assertSame('4711', $generator->generateId($em, $entity)); + self::assertSame($em, $generator->receivedEm); + self::assertSame($entity, $generator->receivedEntity); + } +} diff --git a/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php index 54ec5668116..c446fbef2f6 100644 --- a/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Id; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Id\AssignedGenerator; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; @@ -35,7 +36,7 @@ public function testThrowsExceptionIfIdNotAssigned($entity): void { $this->expectException(ORMException::class); - $this->assignedGen->generate($this->entityManager, $entity); + $this->assignedGen->generateId($this->entityManager, $entity); } public function entitiesWithoutId(): array @@ -50,13 +51,13 @@ public function testCorrectIdGeneration(): void { $entity = new AssignedSingleIdEntity(); $entity->myId = 1; - $id = $this->assignedGen->generate($this->entityManager, $entity); + $id = $this->assignedGen->generateId($this->entityManager, $entity); self::assertEquals(['myId' => 1], $id); $entity = new AssignedCompositeIdEntity(); $entity->myId2 = 2; $entity->myId1 = 4; - $id = $this->assignedGen->generate($this->entityManager, $entity); + $id = $this->assignedGen->generateId($this->entityManager, $entity); self::assertEquals(['myId1' => 4, 'myId2' => 2], $id); } } diff --git a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php index 02af3a790db..0a71527f826 100644 --- a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php @@ -5,7 +5,7 @@ namespace Doctrine\Tests\ORM\Id; use BadMethodCallException; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Id\SequenceGenerator; use Doctrine\Tests\Mocks\ArrayResultFactory; use Doctrine\Tests\Mocks\ConnectionMock; @@ -13,7 +13,7 @@ class SequenceGeneratorTest extends OrmTestCase { - /** @var EntityManager */ + /** @var EntityManagerInterface */ private $entityManager; /** @var SequenceGenerator */ @@ -45,7 +45,7 @@ public function testGeneration(): void $this->connection->setQueryResult(ArrayResultFactory::createFromArray([[(int) ($i / 10) * 10]])); } - $id = $this->sequenceGenerator->generate($this->entityManager, null); + $id = $this->sequenceGenerator->generateId($this->entityManager, null); self::assertSame($i, $id); self::assertSame((int) ($i / 10) * 10 + 10, $this->sequenceGenerator->getCurrentMaxValue()); diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 8bd62625c3f..419686a1c50 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -5,7 +5,7 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\Common\Collections\Collection; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Events; use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping\ClassMetadata; @@ -96,10 +96,10 @@ public function createClassMetadata(string $entityClassName): ClassMetadata return $class; } - protected function createClassMetadataFactory(?EntityManager $em = null): ClassMetadataFactory + protected function createClassMetadataFactory(?EntityManagerInterface $em = null): ClassMetadataFactory { $driver = $this->loadDriver(); - $em = $em ?: $this->getTestEntityManager(); + $em = $em ?? $this->getTestEntityManager(); $factory = new ClassMetadataFactory(); $em->getConfiguration()->setMetadataDriverImpl($driver); $factory->setEntityManager($em); diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index f41e75ba40c..44f338ed075 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -7,12 +7,12 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; use Doctrine\ORM\Configuration; -use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs; use Doctrine\ORM\Events; use Doctrine\ORM\Exception\ORMException; use Doctrine\ORM\Id\AbstractIdGenerator; +use Doctrine\ORM\Id\LegacyIdGeneratorProxy; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\Column; @@ -589,7 +589,10 @@ class TestEntity1 class CustomIdGenerator extends AbstractIdGenerator { - public function generate(EntityManager $em, $entity): void + use LegacyIdGeneratorProxy; + + public function generateId(EntityManagerInterface $em, $entity) { + return 'foo'; } } diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php index 805d7483913..fe6bf4b33b6 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php @@ -5,7 +5,7 @@ namespace Doctrine\Tests\ORM\Persisters; use Doctrine\Common\Collections\Criteria; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; use Doctrine\Tests\Models\GeoNames\Admin1; use Doctrine\Tests\Models\GeoNames\Admin1AlternateName; @@ -17,7 +17,7 @@ class BasicEntityPersisterCompositeTypeParametersTest extends OrmTestCase /** @var BasicEntityPersister */ protected $persister; - /** @var EntityManager */ + /** @var EntityManagerInterface */ protected $entityManager; protected function setUp(): void diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php index 75dbb9b3486..da49050aa02 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php @@ -5,7 +5,7 @@ namespace Doctrine\Tests\ORM\Persisters; use Doctrine\Common\Collections\Expr\Comparison; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; use Doctrine\ORM\Persisters\Exception\CantUseInOperatorOnCompositeKeys; use Doctrine\Tests\Models\GeoNames\Admin1AlternateName; @@ -16,7 +16,7 @@ class BasicEntityPersisterCompositeTypeSqlTest extends OrmTestCase /** @var BasicEntityPersister */ protected $persister; - /** @var EntityManager */ + /** @var EntityManagerInterface */ protected $entityManager; protected function setUp(): void diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php index 647ed645172..c0045a593e6 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php @@ -7,7 +7,7 @@ use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Expr\Comparison; use Doctrine\DBAL\Types\Type as DBALType; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; use Doctrine\Tests\Models\CustomType\CustomTypeChild; use Doctrine\Tests\Models\CustomType\CustomTypeParent; @@ -22,7 +22,7 @@ class BasicEntityPersisterTypeValueSqlTest extends OrmTestCase /** @var BasicEntityPersister */ protected $persister; - /** @var EntityManager */ + /** @var EntityManagerInterface */ protected $entityManager; protected function setUp(): void diff --git a/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php b/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php index 31411d306bf..e9902849bc6 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php @@ -4,7 +4,7 @@ namespace Doctrine\Tests\ORM\Persisters; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Persisters\Entity\JoinedSubclassPersister; use Doctrine\Tests\Models\JoinedInheritanceType\RootClass; use Doctrine\Tests\OrmTestCase; @@ -19,7 +19,7 @@ class JoinedSubClassPersisterTest extends OrmTestCase /** @var JoinedSubclassPersister */ protected $persister; - /** @var EntityManager */ + /** @var EntityManagerInterface */ protected $em; protected function setUp(): void diff --git a/tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php b/tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php index f8ff65f433f..304c31d169d 100644 --- a/tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php @@ -4,7 +4,7 @@ namespace Doctrine\Tests\ORM\Query; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\Filter\SQLFilter; use Doctrine\Tests\OrmTestCase; @@ -14,7 +14,7 @@ */ class FilterCollectionTest extends OrmTestCase { - /** @var EntityManager */ + /** @var EntityManagerInterface */ private $em; protected function setUp(): void diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index fbdf1252a28..26d1db475d2 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -7,7 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Cache; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query; use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\Query\Parameter; @@ -29,7 +29,7 @@ */ class QueryBuilderTest extends OrmTestCase { - /** @var EntityManager */ + /** @var EntityManagerInterface */ private $entityManager; protected function setUp(): void diff --git a/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php b/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php index b5430ef7a67..6761f1a219e 100644 --- a/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php @@ -4,7 +4,7 @@ namespace Doctrine\Tests\ORM\Tools; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\Column; @@ -19,7 +19,7 @@ class AttachEntityListenersListenerTest extends OrmTestCase { - /** @var EntityManager */ + /** @var EntityManagerInterface */ private $em; /** @var AttachEntityListenersListener */ diff --git a/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php b/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php index 80d0957761d..64f0438ecf3 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php @@ -5,7 +5,7 @@ namespace Doctrine\Tests\ORM\Tools; use Doctrine\Common\Collections\Collection; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\Column; @@ -22,7 +22,7 @@ class ResolveTargetEntityListenerTest extends OrmTestCase { - /** @var EntityManager */ + /** @var EntityManagerInterface */ private $em; /** @var ResolveTargetEntityListener */ diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php index 97aa29f3fc5..501fae65ecc 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php @@ -6,7 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\DiscriminatorMap; use Doctrine\ORM\Mapping\Embeddable; @@ -29,7 +29,7 @@ class SchemaValidatorTest extends OrmTestCase { - /** @var EntityManager */ + /** @var EntityManagerInterface */ private $em = null; /** @var SchemaValidator */ diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 8e142e1c2f0..1c3298e606a 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -17,6 +17,7 @@ use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Exception\ORMException; use Doctrine\ORM\Tools\DebugUnitOfWorkListener; use Doctrine\ORM\Tools\SchemaTool; @@ -75,7 +76,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase */ protected static $sharedConn; - /** @var EntityManager */ + /** @var EntityManagerInterface */ protected $_em; /** @var SchemaTool */ @@ -706,7 +707,7 @@ protected function setUp(): void protected function getEntityManager( ?Connection $connection = null, ?MappingDriver $mappingDriver = null - ): EntityManager { + ): EntityManagerInterface { // NOTE: Functional tests use their own shared metadata cache, because // the actual database platform used during execution has effect on some // metadata mapping behaviors (like the choice of the ID generation).