diff --git a/UPGRADE.md b/UPGRADE.md index 7507b8d36da..c79594431e8 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -448,6 +448,17 @@ Calling `AbstractQuery::setFetchMode()` with anything else than `Doctrine\ORM\Mapping::FETCH_LAZY` being used. Relying on that behavior is deprecated and will result in an exception in 3.0. +## Deprecated `getEntityManager()` in `Doctrine\ORM\Event\OnClearEventArgs` and `Doctrine\ORM\Event\*FlushEventArgs` + +This method has been deprecated in: + +* `Doctrine\ORM\Event\OnClearEventArgs` +* `Doctrine\ORM\Event\OnFlushEventArgs` +* `Doctrine\ORM\Event\PostFlushEventArgs` +* `Doctrine\ORM\Event\PreFlushEventArgs` + +It will be removed in 3.0. Use `getObjectManager()` instead. + ## Prepare split of output walkers and tree walkers In 3.0, `SqlWalker` and its child classes won't implement the `TreeWalker` diff --git a/composer.json b/composer.json index 5eba6bd0822..183fae8d274 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "doctrine/annotations": "^1.13", "doctrine/coding-standard": "^9.0", "phpbench/phpbench": "^1.0", - "phpstan/phpstan": "1.7.15", + "phpstan/phpstan": "1.8.0", "phpunit/phpunit": "^9.5", "psr/log": "^1 || ^2 || ^3", "squizlabs/php_codesniffer": "3.7.1", diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index 787a22331e7..314574cb4e5 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -633,6 +633,9 @@ A simple example for this event looks like: if ($eventArgs->getEntity() instanceof User) { if ($eventArgs->hasChangedField('name') && $eventArgs->getNewValue('name') == 'Alice') { $eventArgs->setNewValue('name', 'Bob'); + // The following will only work if `status` is already present in the computed changeset. + // Otherwise it will throw an InvalidArgumentException: + $eventArgs->setNewValue('status', 'active'); } } } diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index b0ed06879c7..efb77284d38 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -169,7 +169,7 @@ public function setCacheable(bool $cacheable): static } /** - * @return bool TRUE if the query results are enable for second level cache, FALSE otherwise. + * @return bool TRUE if the query results are enabled for second level cache, FALSE otherwise. */ public function isCacheable(): bool { diff --git a/lib/Doctrine/ORM/Event/OnClearEventArgs.php b/lib/Doctrine/ORM/Event/OnClearEventArgs.php index c461023842c..83f5c2589f5 100644 --- a/lib/Doctrine/ORM/Event/OnClearEventArgs.php +++ b/lib/Doctrine/ORM/Event/OnClearEventArgs.php @@ -4,26 +4,33 @@ namespace Doctrine\ORM\Event; -use Doctrine\Common\EventArgs; +use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\Event\OnClearEventArgs as BaseOnClearEventArgs; /** * Provides event arguments for the onClear event. * * @link www.doctrine-project.org + * + * @extends BaseOnClearEventArgs */ -class OnClearEventArgs extends EventArgs +class OnClearEventArgs extends BaseOnClearEventArgs { - public function __construct( - private EntityManagerInterface $em - ) { - } - /** * Retrieves associated EntityManager. + * + * @deprecated 2.13. Use {@see getObjectManager} instead. */ public function getEntityManager(): EntityManagerInterface { - return $this->em; + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/issues/9875', + 'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.', + __METHOD__ + ); + + return $this->getObjectManager(); } } diff --git a/lib/Doctrine/ORM/Event/OnFlushEventArgs.php b/lib/Doctrine/ORM/Event/OnFlushEventArgs.php index a155f1a672f..340719f78f5 100644 --- a/lib/Doctrine/ORM/Event/OnFlushEventArgs.php +++ b/lib/Doctrine/ORM/Event/OnFlushEventArgs.php @@ -4,31 +4,35 @@ namespace Doctrine\ORM\Event; -use Doctrine\Common\EventArgs; +use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\Event\ManagerEventArgs; /** * Provides event arguments for the preFlush event. * * @link www.doctrine-project.org + * + * @extends ManagerEventArgs */ -class OnFlushEventArgs extends EventArgs +class OnFlushEventArgs extends ManagerEventArgs { - /** @var EntityManagerInterface */ - private $em; - - public function __construct(EntityManagerInterface $em) - { - $this->em = $em; - } - /** * Retrieve associated EntityManager. * + * @deprecated 2.13. Use {@see getObjectManager} instead. + * * @return EntityManagerInterface */ public function getEntityManager() { - return $this->em; + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/issues/9875', + 'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.', + __METHOD__ + ); + + return $this->getObjectManager(); } } diff --git a/lib/Doctrine/ORM/Event/PostFlushEventArgs.php b/lib/Doctrine/ORM/Event/PostFlushEventArgs.php index 1e7c06b6a7f..ae3f52a4066 100644 --- a/lib/Doctrine/ORM/Event/PostFlushEventArgs.php +++ b/lib/Doctrine/ORM/Event/PostFlushEventArgs.php @@ -4,31 +4,35 @@ namespace Doctrine\ORM\Event; -use Doctrine\Common\EventArgs; +use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\Event\ManagerEventArgs; /** * Provides event arguments for the postFlush event. * * @link www.doctrine-project.org + * + * @extends ManagerEventArgs */ -class PostFlushEventArgs extends EventArgs +class PostFlushEventArgs extends ManagerEventArgs { - /** @var EntityManagerInterface */ - private $em; - - public function __construct(EntityManagerInterface $em) - { - $this->em = $em; - } - /** * Retrieves associated EntityManager. * + * @deprecated 2.13. Use {@see getObjectManager} instead. + * * @return EntityManagerInterface */ public function getEntityManager() { - return $this->em; + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/issues/9875', + 'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.', + __METHOD__ + ); + + return $this->getObjectManager(); } } diff --git a/lib/Doctrine/ORM/Event/PreFlushEventArgs.php b/lib/Doctrine/ORM/Event/PreFlushEventArgs.php index c7d2fef4885..b8bdb25538e 100644 --- a/lib/Doctrine/ORM/Event/PreFlushEventArgs.php +++ b/lib/Doctrine/ORM/Event/PreFlushEventArgs.php @@ -4,29 +4,33 @@ namespace Doctrine\ORM\Event; -use Doctrine\Common\EventArgs; +use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\Event\ManagerEventArgs; /** * Provides event arguments for the preFlush event. * * @link www.doctrine-project.com + * + * @extends ManagerEventArgs */ -class PreFlushEventArgs extends EventArgs +class PreFlushEventArgs extends ManagerEventArgs { - /** @var EntityManagerInterface */ - private $em; - - public function __construct(EntityManagerInterface $em) - { - $this->em = $em; - } - /** + * @deprecated 2.13. Use {@see getObjectManager} instead. + * * @return EntityManagerInterface */ public function getEntityManager() { - return $this->em; + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/issues/9875', + 'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.', + __METHOD__ + ); + + return $this->getObjectManager(); } } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index c970610569c..5f0a66dfdd2 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -43,6 +43,9 @@ class ObjectHydrator extends AbstractHydrator /** @var mixed[] */ private array $initializedCollections = []; + /** @var array */ + private $uninitializedCollections = []; + /** @var mixed[] */ private array $existingCollections = []; @@ -105,10 +108,11 @@ protected function cleanup(): void parent::cleanup(); - $this->identifierMap = - $this->initializedCollections = - $this->existingCollections = - $this->resultPointers = []; + $this->identifierMap = + $this->initializedCollections = + $this->uninitializedCollections = + $this->existingCollections = + $this->resultPointers = []; if ($eagerLoad) { $this->_uow->triggerEagerLoads(); @@ -119,10 +123,11 @@ protected function cleanup(): void protected function cleanupAfterRowIteration(): void { - $this->identifierMap = - $this->initializedCollections = - $this->existingCollections = - $this->resultPointers = []; + $this->identifierMap = + $this->initializedCollections = + $this->uninitializedCollections = + $this->existingCollections = + $this->resultPointers = []; } /** @@ -141,6 +146,12 @@ protected function hydrateAllData(): array $coll->takeSnapshot(); } + foreach ($this->uninitializedCollections as $coll) { + if (! $coll->isInitialized()) { + $coll->setInitialized(true); + } + } + return $result; } @@ -397,8 +408,8 @@ protected function hydrateRowData(array $row, array &$result): void } } elseif (! $reflFieldValue) { $this->initRelatedCollection($parentObject, $parentClass, $relationField, $parentAlias); - } elseif ($reflFieldValue instanceof PersistentCollection && $reflFieldValue->isInitialized() === false) { - $reflFieldValue->setInitialized(true); + } elseif ($reflFieldValue instanceof PersistentCollection && $reflFieldValue->isInitialized() === false && ! isset($this->uninitializedCollections[$oid . $relationField])) { + $this->uninitializedCollections[$oid . $relationField] = $reflFieldValue; } } else { // PATH B: Single-valued association diff --git a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php index ab8b301c20f..6dd36c48848 100644 --- a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php +++ b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php @@ -51,7 +51,7 @@ public function __construct($file = 'php://output', $context = '') */ public function onFlush(OnFlushEventArgs $args) { - $this->dumpIdentityMap($args->getEntityManager()); + $this->dumpIdentityMap($args->getObjectManager()); } /** diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 8d26133deaa..f357e856192 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -786,8 +786,8 @@ private function gatherColumnOptions(array $mapping): array return []; } - $options = array_intersect_key($mappingOptions, array_flip(self::KNOWN_COLUMN_OPTIONS)); - $options['customSchemaOptions'] = array_diff_key($mappingOptions, $options); + $options = array_intersect_key($mappingOptions, array_flip(self::KNOWN_COLUMN_OPTIONS)); + $options['platformOptions'] = array_diff_key($mappingOptions, $options); return $options; } diff --git a/phpstan-dbal4.neon b/phpstan-dbal4.neon index b8c63ba0d5b..fa8291b8612 100644 --- a/phpstan-dbal4.neon +++ b/phpstan-dbal4.neon @@ -18,3 +18,7 @@ parameters: - message: '~^Parameter #1 \$command of method Symfony\\Component\\Console\\Application::add\(\) expects Symfony\\Component\\Console\\Command\\Command, Doctrine\\DBAL\\Tools\\Console\\Command\\ReservedWordsCommand given\.$~' path: lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php + + - + message: '~Strict comparison using \=\=\= between callable\(\)\: mixed and null will always evaluate to false\.~' + path: lib/Doctrine/ORM/Tools/SchemaTool.php diff --git a/psalm.xml b/psalm.xml index 0e34c912cf0..3f3b111cdb3 100644 --- a/psalm.xml +++ b/psalm.xml @@ -17,6 +17,11 @@ + + + + + @@ -111,6 +116,12 @@ + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php b/tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php index 0d90c578a96..d9ccc262e12 100644 --- a/tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php @@ -76,7 +76,7 @@ public function onFlush(OnFlushEventArgs $args): void { //echo "---preFlush".PHP_EOL; - $em = $args->getEntityManager(); + $em = $args->getObjectManager(); $uow = $em->getUnitOfWork(); foreach ($uow->getScheduledEntityInsertions() as $entity) { diff --git a/tests/Doctrine/Tests/ORM/Functional/InsertableUpdatableTest.php b/tests/Doctrine/Tests/ORM/Functional/InsertableUpdatableTest.php index c59425e6d81..8e3da45b4ca 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InsertableUpdatableTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/InsertableUpdatableTest.php @@ -4,7 +4,6 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\ORM\Tools\ToolsException; use Doctrine\Tests\Models\Upsertable\Insertable; use Doctrine\Tests\Models\Upsertable\Updatable; use Doctrine\Tests\OrmFunctionalTestCase; @@ -15,15 +14,7 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(Updatable::class), - $this->_em->getClassMetadata(Insertable::class), - ] - ); - } catch (ToolsException) { - } + $this->createSchemaForModels(Updatable::class, Insertable::class); } public function testNotInsertableIsFetchedFromDatabase(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php b/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php index 8d3b52a5610..d6605761609 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php @@ -30,10 +30,7 @@ protected function setUp(): void $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8383'); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(NotifyUser::class), - $this->_em->getClassMetadata(NotifyGroup::class), - ]); + $this->createSchemaForModels(NotifyUser::class, NotifyGroup::class); } public function testChangeTracking(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php index 88773b804cd..763e64dd01d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php @@ -4,7 +4,6 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\ORM\Tools\ToolsException; use Doctrine\Tests\Models\OneToOneInverseSideLoad\InverseSide; use Doctrine\Tests\Models\OneToOneInverseSideLoad\OwningSide; use Doctrine\Tests\OrmFunctionalTestCase; @@ -17,14 +16,7 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(OwningSide::class), - $this->_em->getClassMetadata(InverseSide::class), - ]); - } catch (ToolsException) { - // ignored - } + $this->createSchemaForModels(OwningSide::class, InverseSide::class); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php index f4ff04d3dc0..77c3c1e8495 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php @@ -94,9 +94,7 @@ public function testLazyLoadsAssociation(): void public function testMultiSelfReference(): void { - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(MultiSelfReference::class), - ]); + $this->createSchemaForModels(MultiSelfReference::class); $entity1 = new MultiSelfReference(); $this->_em->persist($entity1); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.php index e3b4ed621bf..b433be59d65 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.php @@ -17,11 +17,11 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(Pet::class), - $this->_em->getClassMetadata(Cat::class), - $this->_em->getClassMetadata(LitterBox::class), - ]); + $this->createSchemaForModels( + Pet::class, + Cat::class, + LitterBox::class + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php index 71755a21648..486805741cf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php @@ -27,11 +27,11 @@ class OrderedJoinedTableInheritanceCollectionTest extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(OJTICPet::class), - $this->_em->getClassMetadata(OJTICCat::class), - $this->_em->getClassMetadata(OJTICDog::class), - ]); + $this->createSchemaForModels( + OJTICPet::class, + OJTICCat::class, + OJTICDog::class + ); $dog = new OJTICDog(); $dog->name = 'Poofy'; diff --git a/tests/Doctrine/Tests/ORM/Functional/PostFlushEventTest.php b/tests/Doctrine/Tests/ORM/Functional/PostFlushEventTest.php index aede96e34be..995baeb9e76 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PostFlushEventTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PostFlushEventTest.php @@ -54,7 +54,7 @@ public function testListenerShouldReceiveEntityManagerThroughArgs(): void { $this->_em->persist($this->createNewValidUser()); $this->_em->flush(); - $receivedEm = $this->listener->receivedArgs->getEntityManager(); + $receivedEm = $this->listener->receivedArgs->getObjectManager(); self::assertSame($this->_em, $receivedEm); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php index 0a49a3a791b..48a4935b1d1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php @@ -8,7 +8,6 @@ use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\GeneratedValue; use Doctrine\ORM\Mapping\Id; -use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\OrmFunctionalTestCase; use function array_filter; @@ -16,27 +15,16 @@ class DBAL483Test extends OrmFunctionalTestCase { - private SchemaTool $schemaTool; - - protected function setUp(): void - { - parent::setUp(); - - $this->_em->getConnection(); - - $this->schemaTool = new SchemaTool($this->_em); - } - /** * @group DBAL-483 */ public function testDefaultValueIsComparedCorrectly(): void { - $class = $this->_em->getClassMetadata(DBAL483Default::class); + $class = DBAL483Default::class; - $this->schemaTool->createSchema([$class]); + $this->createSchemaForModels($class); - $updateSql = $this->schemaTool->getUpdateSchemaSql([$class]); + $updateSql = $this->getUpdateSchemaSqlForModels($class); $updateSql = array_filter($updateSql, static fn ($sql) => str_contains($sql, 'DBAL483')); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php index 58c98da1a0f..18e86bd896e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php @@ -5,23 +5,8 @@ namespace Doctrine\Tests\ORM\Functional\SchemaTool; use Doctrine\DBAL\Platforms\SqlitePlatform; -use Doctrine\ORM\Tools\SchemaTool; -use Doctrine\Tests\Models\CMS\CmsAddress; -use Doctrine\Tests\Models\CMS\CmsArticle; -use Doctrine\Tests\Models\CMS\CmsEmail; -use Doctrine\Tests\Models\CMS\CmsGroup; -use Doctrine\Tests\Models\CMS\CmsPhonenumber; -use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\Company\CompanyAuction; -use Doctrine\Tests\Models\Company\CompanyCar; -use Doctrine\Tests\Models\Company\CompanyEmployee; -use Doctrine\Tests\Models\Company\CompanyEvent; -use Doctrine\Tests\Models\Company\CompanyManager; -use Doctrine\Tests\Models\Company\CompanyOrganization; -use Doctrine\Tests\Models\Company\CompanyPerson; -use Doctrine\Tests\Models\Company\CompanyRaffle; +use Doctrine\Tests\Models; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; use function array_filter; use function implode; @@ -34,11 +19,6 @@ */ class DDC214Test extends OrmFunctionalTestCase { - /** @psalm-var list */ - private array $classes = []; - - private ?SchemaTool $schemaTool = null; - protected function setUp(): void { parent::setUp(); @@ -48,8 +28,6 @@ protected function setUp(): void if ($conn->getDatabasePlatform() instanceof SqlitePlatform) { self::markTestSkipped('SQLite does not support ALTER TABLE statements.'); } - - $this->schemaTool = new SchemaTool($this->_em); } /** @@ -57,16 +35,14 @@ protected function setUp(): void */ public function testCmsAddressModel(): void { - $this->classes = [ - CmsUser::class, - CmsPhonenumber::class, - CmsAddress::class, - CmsGroup::class, - CmsArticle::class, - CmsEmail::class, - ]; - - $this->assertCreatedSchemaNeedsNoUpdates($this->classes); + $this->assertCreatedSchemaNeedsNoUpdates( + Models\CMS\CmsUser::class, + Models\CMS\CmsPhonenumber::class, + Models\CMS\CmsAddress::class, + Models\CMS\CmsGroup::class, + Models\CMS\CmsArticle::class, + Models\CMS\CmsEmail::class + ); } /** @@ -74,37 +50,29 @@ public function testCmsAddressModel(): void */ public function testCompanyModel(): void { - $this->classes = [ - CompanyPerson::class, - CompanyEmployee::class, - CompanyManager::class, - CompanyOrganization::class, - CompanyEvent::class, - CompanyAuction::class, - CompanyRaffle::class, - CompanyCar::class, - ]; - - $this->assertCreatedSchemaNeedsNoUpdates($this->classes); + $this->assertCreatedSchemaNeedsNoUpdates( + Models\Company\CompanyPerson::class, + Models\Company\CompanyEmployee::class, + Models\Company\CompanyManager::class, + Models\Company\CompanyOrganization::class, + Models\Company\CompanyEvent::class, + Models\Company\CompanyAuction::class, + Models\Company\CompanyRaffle::class, + Models\Company\CompanyCar::class + ); } - public function assertCreatedSchemaNeedsNoUpdates($classes): void + /** + * @param class-string ...$classes + */ + public function assertCreatedSchemaNeedsNoUpdates(string ...$classes): void { - $classMetadata = []; - foreach ($classes as $class) { - $classMetadata[] = $this->_em->getClassMetadata($class); - } - - try { - $this->schemaTool->createSchema($classMetadata); - } catch (Exception) { - // was already created - } + $this->createSchemaForModels(...$classes); $sm = $this->createSchemaManager(); $fromSchema = $sm->createSchema(); - $toSchema = $this->schemaTool->getSchemaFromMetadata($classMetadata); + $toSchema = $this->getSchemaForModels(...$classes); $comparator = $sm->createComparator(); $schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php index 53c7c09dc54..e2a92e69828 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php @@ -12,7 +12,6 @@ use Doctrine\ORM\Mapping\JoinColumn; use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\ORM\Mapping\Table; -use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\OrmFunctionalTestCase; @@ -44,15 +43,10 @@ public function testPostgresMetadataSequenceIncrementedBy10(): void */ public function testUpdateSchemaWithPostgreSQLSchema(): void { - $classes = [ - $this->_em->getClassMetadata(DDC1657Screen::class), - $this->_em->getClassMetadata(DDC1657Avatar::class), - ]; - - $tool = new SchemaTool($this->_em); - $tool->createSchema($classes); - - $sql = $tool->getUpdateSchemaSql($classes); + $sql = $this->getUpdateSchemaSqlForModels( + DDC1657Screen::class, + DDC1657Avatar::class + ); $sql = array_filter($sql, static fn ($sql) => str_starts_with($sql, 'DROP SEQUENCE stonewood.')); self::assertCount(0, $sql, implode("\n", $sql)); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php index b2a45c5ff06..1c40fd65c6f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php @@ -24,12 +24,10 @@ class DDC1080Test extends OrmFunctionalTestCase { public function testHydration(): void { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1080Foo::class), - $this->_em->getClassMetadata(DDC1080Bar::class), - $this->_em->getClassMetadata(DDC1080FooBar::class), - ] + $this->createSchemaForModels( + DDC1080Foo::class, + DDC1080Bar::class, + DDC1080FooBar::class ); $foo1 = new DDC1080Foo(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php index 0c856b3cf0a..e4f8dcae8d4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php @@ -33,13 +33,11 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1163Product::class), - $this->_em->getClassMetadata(DDC1163SpecialProduct::class), - $this->_em->getClassMetadata(DDC1163ProxyHolder::class), - $this->_em->getClassMetadata(DDC1163Tag::class), - ] + $this->createSchemaForModels( + DDC1163Product::class, + DDC1163SpecialProduct::class, + DDC1163ProxyHolder::class, + DDC1163Tag::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php index 00cd93cf8f4..52ab662d9b8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php @@ -19,12 +19,10 @@ class DDC1181Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1181Hotel::class), - $this->_em->getClassMetadata(DDC1181Booking::class), - $this->_em->getClassMetadata(DDC1181Room::class), - ] + $this->createSchemaForModels( + DDC1181Hotel::class, + DDC1181Booking::class, + DDC1181Room::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php index 6b6c0e58bc6..35ad187be27 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php @@ -17,12 +17,10 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1193Company::class), - $this->_em->getClassMetadata(DDC1193Person::class), - $this->_em->getClassMetadata(DDC1193Account::class), - ] + $this->createSchemaForModels( + DDC1193Company::class, + DDC1193Person::class, + DDC1193Account::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php index 4ff0840af45..86a4d7f1d5d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php @@ -23,11 +23,9 @@ class DDC1225Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1225TestEntity1::class), - $this->_em->getClassMetadata(DDC1225TestEntity2::class), - ] + $this->createSchemaForModels( + DDC1225TestEntity1::class, + DDC1225TestEntity2::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php index 368dba40a3d..06998b6baa0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php @@ -20,9 +20,7 @@ class DDC1250Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [$this->_em->getClassMetadata(DDC1250ClientHistory::class)] - ); + $this->createSchemaForModels(DDC1250ClientHistory::class); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php index 731eecd6212..da19f707bd6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php @@ -22,11 +22,9 @@ class DDC1300Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1300Foo::class), - $this->_em->getClassMetadata(DDC1300FooLocale::class), - ] + $this->createSchemaForModels( + DDC1300Foo::class, + DDC1300FooLocale::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php index e1ff3073f35..dee785fd442 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php @@ -12,7 +12,6 @@ use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\ORM\Mapping\OneToMany; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; /** * @group DDC-1400 @@ -23,16 +22,11 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1400Article::class), - $this->_em->getClassMetadata(DDC1400User::class), - $this->_em->getClassMetadata(DDC1400UserState::class), - ] - ); - } catch (Exception) { - } + $this->createSchemaForModels( + DDC1400Article::class, + DDC1400User::class, + DDC1400UserState::class + ); } public function testFailingCase(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php index 1939c84dde4..79c30c2f98b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php @@ -11,7 +11,6 @@ use Doctrine\ORM\Mapping\JoinColumn; use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; /** * @group DDC-1436 @@ -22,14 +21,7 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1436Page::class), - ] - ); - } catch (Exception) { - } + $this->createSchemaForModels(DDC1436Page::class); } public function testIdentityMap(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php index a9832db5f38..c4ac7cf3b2f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php @@ -20,11 +20,9 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC144FlowElement::class), - $this->_em->getClassMetadata(DDC144Operand::class), - ] + $this->createSchemaForModels( + DDC144FlowElement::class, + DDC144Operand::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php index 9bd1eb08e58..5aa90545af1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php @@ -16,7 +16,6 @@ use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; /** * @group DDC-1452 @@ -28,15 +27,10 @@ protected function setUp(): void $this->useModelSet('cms'); parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1452EntityA::class), - $this->_em->getClassMetadata(DDC1452EntityB::class), - ] - ); - } catch (Exception) { - } + $this->createSchemaForModels( + DDC1452EntityA::class, + DDC1452EntityB::class + ); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php index d0cc7a74d7a..8e2741c84b7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php @@ -12,7 +12,6 @@ use Doctrine\ORM\Mapping\InheritanceType; use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; use function mt_getrandmax; use function random_int; @@ -26,15 +25,7 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1454File::class), - $this->_em->getClassMetadata(DDC1454Picture::class), - ] - ); - } catch (Exception) { - } + $this->createSchemaForModels(DDC1454File::class, DDC1454Picture::class); } public function testFailingCase(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php index 9c1cda103f4..86b330d93d3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php @@ -16,11 +16,9 @@ class DDC1458Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(TestEntity::class), - $this->_em->getClassMetadata(TestAdditionalEntity::class), - ] + $this->createSchemaForModels( + TestEntity::class, + TestAdditionalEntity::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php index 62746a2e23c..4de542f1ea4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php @@ -13,7 +13,6 @@ use Doctrine\ORM\Mapping\ManyToMany; use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; /** * @group DDC-1514 @@ -24,16 +23,11 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1514EntityA::class), - $this->_em->getClassMetadata(DDC1514EntityB::class), - $this->_em->getClassMetadata(DDC1514EntityC::class), - ] - ); - } catch (Exception) { - } + $this->createSchemaForModels( + DDC1514EntityA::class, + DDC1514EntityB::class, + DDC1514EntityC::class + ); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php index 00249e6e755..d8268f9ef8c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php @@ -19,11 +19,9 @@ class DDC1515Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1515Foo::class), - $this->_em->getClassMetadata(DDC1515Bar::class), - ] + $this->createSchemaForModels( + DDC1515Foo::class, + DDC1515Bar::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php index 9c0cdfea0ce..380bdbd075c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php @@ -21,11 +21,7 @@ class DDC1526Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1526Menu::class), - ] - ); + $this->createSchemaForModels(DDC1526Menu::class); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php index ebb0405deb0..0486813fefb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php @@ -19,12 +19,10 @@ class DDC1548Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1548E1::class), - $this->_em->getClassMetadata(DDC1548E2::class), - $this->_em->getClassMetadata(DDC1548Rel::class), - ] + $this->createSchemaForModels( + DDC1548E1::class, + DDC1548E2::class, + DDC1548Rel::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php index f4ab7b33945..e7387a4a2cf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php @@ -29,12 +29,10 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1595BaseInheritance::class), - $this->_em->getClassMetadata(DDC1595InheritedEntity1::class), - $this->_em->getClassMetadata(DDC1595InheritedEntity2::class), - ] + $this->createSchemaForModels( + DDC1595BaseInheritance::class, + DDC1595InheritedEntity1::class, + DDC1595InheritedEntity2::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php index d7c80635d47..1221b04ac8a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php @@ -23,10 +23,7 @@ class DDC1690Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(DDC1690Parent::class), - $this->_em->getClassMetadata(DDC1690Child::class), - ]); + $this->createSchemaForModels(DDC1690Parent::class, DDC1690Child::class); } public function testChangeTracking(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php index a0beecb8ab9..7ffb3768a8c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php @@ -14,7 +14,6 @@ use Doctrine\ORM\Mapping\InheritanceType; use Doctrine\ORM\Mapping\PostLoad; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; /** * @group DDC-1707 @@ -25,15 +24,10 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1509File::class), - $this->_em->getClassMetadata(DDC1509Picture::class), - ] - ); - } catch (Exception) { - } + $this->createSchemaForModels( + DDC1707Base::class, + DDC1707Child::class + ); } public function testPostLoadOnChild(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php index 2e0de1db09a..02abb943371 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php @@ -22,11 +22,9 @@ class DDC1787Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1787Foo::class), - $this->_em->getClassMetadata(DDC1787Bar::class), - ] + $this->createSchemaForModels( + DDC1787Foo::class, + DDC1787Bar::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php index 32402b1407d..ffd8ecae13b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php @@ -26,12 +26,7 @@ class DDC1925Test extends OrmFunctionalTestCase { public function testIssue(): void { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1925User::class), - $this->_em->getClassMetadata(DDC1925Product::class), - ] - ); + $this->createSchemaForModels(DDC1925User::class, DDC1925Product::class); $user = new DDC1925User(); $user->setTitle('Test User'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php index 24142579e4e..07a2f6d4a20 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php @@ -4,7 +4,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\GeneratedValue; @@ -14,8 +13,6 @@ use Doctrine\ORM\Mapping\Table; use Doctrine\Tests\OrmFunctionalTestCase; -use function assert; - /** * @group DDC-192 */ @@ -24,17 +21,19 @@ class DDC192Test extends OrmFunctionalTestCase public function testSchemaCreation(): void { $classes = [ - $this->_em->getClassMetadata(DDC192User::class), - $this->_em->getClassMetadata(DDC192Phonenumber::class), + DDC192User::class, + DDC192Phonenumber::class, ]; - $this->_schemaTool->createSchema($classes); + $this->createSchemaForModels(...$classes); $tables = $this->createSchemaManager()->listTableNames(); foreach ($classes as $class) { - assert($class instanceof ClassMetadata); - self::assertContains($class->getTableName(), $tables); + self::assertContains( + $this->_em->getClassMetadata($class)->getTableName(), + $tables + ); } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1998Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1998Test.php index f38e1d61352..640294ac6f9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1998Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1998Test.php @@ -22,11 +22,7 @@ public function testSqlConversionAsIdentifier(): void { Type::addType('ddc1998', DDC1998Type::class); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC1998Entity::class), - ] - ); + $this->createSchemaForModels(DDC1998Entity::class); $entity = new DDC1998Entity(); $entity->id = new DDC1998Id('foo'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php index 0938f4e2835..3efcfaa48e1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php @@ -23,12 +23,10 @@ class DDC199Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC199ParentClass::class), - $this->_em->getClassMetadata(DDC199ChildClass::class), - $this->_em->getClassMetadata(DDC199RelatedClass::class), - ] + $this->createSchemaForModels( + DDC199ParentClass::class, + DDC199ChildClass::class, + DDC199RelatedClass::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php index 300cd5bf4bb..922e18c41dc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php @@ -37,11 +37,9 @@ protected function setUp(): void DDC2012TsVectorType::$calls = []; - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2012Item::class), - $this->_em->getClassMetadata(DDC2012ItemPerson::class), - ] + $this->createSchemaForModels( + DDC2012Item::class, + DDC2012ItemPerson::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2084Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2084Test.php index 4842df2ada4..8e6aa405c59 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2084Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2084Test.php @@ -8,7 +8,6 @@ use Doctrine\Tests\ORM\Functional\Ticket\DDC2084\MyEntity2; use Doctrine\ORM\ORMInvalidArgumentException; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; /** * @group DDC-2084 @@ -19,15 +18,10 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2084\MyEntity1'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2084\MyEntity2'), - ] - ); - } catch (Exception) { - } + $this->createSchemaForModels( + __NAMESPACE__ . '\DDC2084\MyEntity1', + __NAMESPACE__ . '\DDC2084\MyEntity2' + ); } public function loadFixture(): MyEntity1 diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php index f3d8610def4..8d9bd74d2e3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php @@ -24,11 +24,7 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2106Entity::class), - ] - ); + $this->createSchemaForModels(DDC2106Entity::class); } public function testDetachedEntityAsId(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php index 670dc65833a..21215b092bc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php @@ -21,12 +21,7 @@ class DDC211Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC211User::class), - $this->_em->getClassMetadata(DDC211Group::class), - ] - ); + $this->createSchemaForModels(DDC211User::class, DDC211Group::class); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php index a99c5f031d1..a2cc16a75e4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php @@ -18,7 +18,6 @@ use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\ORM\Mapping\OneToMany; use Doctrine\ORM\Mapping\Table; -use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\ORM\Functional\Ticket\Doctrine\Common\Collections\Collection; use Doctrine\Tests\OrmFunctionalTestCase; @@ -32,18 +31,14 @@ class DDC2138Test extends OrmFunctionalTestCase */ public function testForeignKeyOnSTIWithMultipleMapping(): void { - $em = $this->_em; - $schemaTool = new SchemaTool($em); - - $classes = [ - $em->getClassMetadata(DDC2138User::class), - $em->getClassMetadata(DDC2138Structure::class), - $em->getClassMetadata(DDC2138UserFollowedObject::class), - $em->getClassMetadata(DDC2138UserFollowedStructure::class), - $em->getClassMetadata(DDC2138UserFollowedUser::class), - ]; - - $schema = $schemaTool->getSchemaFromMetadata($classes); + $em = $this->_em; + $schema = $this->getSchemaForModels( + DDC2138User::class, + DDC2138Structure::class, + DDC2138UserFollowedObject::class, + DDC2138UserFollowedStructure::class, + DDC2138UserFollowedUser::class + ); self::assertTrue($schema->hasTable('users_followed_objects'), 'Table users_followed_objects should exist.'); $table = $schema->getTable('users_followed_objects'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php index 3a64b1617d8..5bb724627f7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php @@ -21,11 +21,7 @@ class DDC2175Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2175Entity::class), - ] - ); + $this->createSchemaForModels(DDC2175Entity::class); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2214Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2214Test.php index 18326253225..40866868107 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2214Test.php @@ -27,12 +27,7 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2214Foo::class), - $this->_em->getClassMetadata(DDC2214Bar::class), - ] - ); + $this->createSchemaForModels(DDC2214Foo::class, DDC2214Bar::class); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php index 0a1d94845e2..066303063d2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php @@ -11,7 +11,6 @@ use Doctrine\ORM\Mapping\GeneratedValue; use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\OneToOne; -use Doctrine\ORM\Tools\ToolsException; use Doctrine\Persistence\NotifyPropertyChanged; use Doctrine\Persistence\PropertyChangedListener; use Doctrine\Tests\OrmFunctionalTestCase; @@ -27,15 +26,10 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2230User::class), - $this->_em->getClassMetadata(DDC2230Address::class), - ] - ); - } catch (ToolsException) { - } + $this->createSchemaForModels( + DDC2230User::class, + DDC2230Address::class + ); } public function testNotifyTrackingCalledOnProxyInitialization(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2252Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2252Test.php index dbd470b1a77..fddc77f6e89 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2252Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2252Test.php @@ -40,13 +40,11 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2252User::class), - $this->_em->getClassMetadata(DDC2252Privilege::class), - $this->_em->getClassMetadata(DDC2252Membership::class), - $this->_em->getClassMetadata(DDC2252MerchantAccount::class), - ] + $this->createSchemaForModels( + DDC2252User::class, + DDC2252Privilege::class, + DDC2252Membership::class, + DDC2252MerchantAccount::class ); $this->loadFixtures(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php index 959ffa3d111..5adfdf736f3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php @@ -26,13 +26,11 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2306Zone::class), - $this->_em->getClassMetadata(DDC2306User::class), - $this->_em->getClassMetadata(DDC2306Address::class), - $this->_em->getClassMetadata(DDC2306UserAddress::class), - ] + $this->createSchemaForModels( + DDC2306Zone::class, + DDC2306User::class, + DDC2306Address::class, + DDC2306UserAddress::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php index 855c0fc1b5a..0dc4a79a95a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php @@ -26,12 +26,10 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2346Foo::class), - $this->_em->getClassMetadata(DDC2346Bar::class), - $this->_em->getClassMetadata(DDC2346Baz::class), - ] + $this->createSchemaForModels( + DDC2346Foo::class, + DDC2346Bar::class, + DDC2346Baz::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2350Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2350Test.php index 017464b065f..5eb1aaaccef 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2350Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2350Test.php @@ -23,12 +23,7 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2350User::class), - $this->_em->getClassMetadata(DDC2350Bug::class), - ] - ); + $this->createSchemaForModels(DDC2350User::class, DDC2350Bug::class); } public function testEagerCollectionsAreOnlyRetrievedOnce(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php index 0010b15aeae..de5ebaf0ea4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php @@ -19,12 +19,10 @@ class DDC237Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC237EntityX::class), - $this->_em->getClassMetadata(DDC237EntityY::class), - $this->_em->getClassMetadata(DDC237EntityZ::class), - ] + $this->createSchemaForModels( + DDC237EntityX::class, + DDC237EntityY::class, + DDC237EntityZ::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php index bef58d8926c..3a1a4ccb8aa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php @@ -23,11 +23,9 @@ protected function setUp(): void $this->_em->getConfiguration()->setMetadataDriverImpl(new StaticPHPDriver([])); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2415ParentEntity::class), - $this->_em->getClassMetadata(DDC2415ChildEntity::class), - ] + $this->createSchemaForModels( + DDC2415ParentEntity::class, + DDC2415ChildEntity::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php index d5ff4e2ac89..cebcfa0ee6e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php @@ -32,11 +32,9 @@ protected function setUp(): void Type::addType('ddc2494_tinyint', DDC2494TinyIntType::class); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2494Currency::class), - $this->_em->getClassMetadata(DDC2494Campaign::class), - ] + $this->createSchemaForModels( + DDC2494Currency::class, + DDC2494Campaign::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2575Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2575Test.php index 0215047eb75..9487c3562cd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2575Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2575Test.php @@ -30,12 +30,10 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2575Root::class), - $this->_em->getClassMetadata(DDC2575A::class), - $this->_em->getClassMetadata(DDC2575B::class), - ] + $this->createSchemaForModels( + DDC2575Root::class, + DDC2575A::class, + DDC2575B::class ); $entityRoot1 = new DDC2575Root(1); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php index a3c8098203c..a5b13fe53f0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php @@ -26,12 +26,10 @@ protected function setUp(): void Type::addType(DDC2579Type::NAME, DDC2579Type::class); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2579Entity::class), - $this->_em->getClassMetadata(DDC2579EntityAssoc::class), - $this->_em->getClassMetadata(DDC2579AssocAssoc::class), - ] + $this->createSchemaForModels( + DDC2579Entity::class, + DDC2579EntityAssoc::class, + DDC2579AssocAssoc::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php index f3760a86a53..50780e34032 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php @@ -19,13 +19,11 @@ class DDC258Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC258Super::class), - $this->_em->getClassMetadata(DDC258Class1::class), - $this->_em->getClassMetadata(DDC258Class2::class), - $this->_em->getClassMetadata(DDC258Class3::class), - ] + $this->createSchemaForModels( + DDC258Super::class, + DDC258Class1::class, + DDC258Class2::class, + DDC258Class3::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php index ff789d9c88c..e9a1c0b3560 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php @@ -13,7 +13,6 @@ use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\Table; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; /** * @group DDC-2692 @@ -24,15 +23,7 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2692Foo::class), - ] - ); - } catch (Exception) { - return; - } + $this->createSchemaForModels(DDC2692Foo::class); $this->_em->clear(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php index 85ae05c0ebd..141c654c1bb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php @@ -14,7 +14,6 @@ use Doctrine\ORM\Mapping\OneToOne; use Doctrine\ORM\Mapping\Table; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; /** * @group DDC-2759 @@ -25,18 +24,12 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2759Qualification::class), - $this->_em->getClassMetadata(DDC2759Category::class), - $this->_em->getClassMetadata(DDC2759QualificationMetadata::class), - $this->_em->getClassMetadata(DDC2759MetadataCategory::class), - ] - ); - } catch (Exception) { - return; - } + $this->createSchemaForModels( + DDC2759Qualification::class, + DDC2759Category::class, + DDC2759QualificationMetadata::class, + DDC2759MetadataCategory::class + ); $qualification = new DDC2759Qualification(); $qualificationMetadata = new DDC2759QualificationMetadata($qualification); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2780Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2780Test.php index 0c8a2166489..64b8536d349 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2780Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2780Test.php @@ -22,12 +22,7 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2780User::class), - $this->_em->getClassMetadata(DDC2780Project::class), - ] - ); + $this->createSchemaForModels(DDC2780User::class, DDC2780Project::class); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2790Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2790Test.php index 39d104d2c51..88fbf701925 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2790Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2790Test.php @@ -66,7 +66,7 @@ class OnFlushListener */ public function onFlush(OnFlushEventArgs $args): void { - $em = $args->getEntityManager(); + $em = $args->getObjectManager(); $uow = $em->getUnitOfWork(); $deletions = $uow->getScheduledEntityDeletions(); $updates = $uow->getScheduledEntityUpdates(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php index 2765fdecdad..218c3afd58b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php @@ -20,13 +20,11 @@ class DDC279Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC279EntityXAbstract::class), - $this->_em->getClassMetadata(DDC279EntityX::class), - $this->_em->getClassMetadata(DDC279EntityY::class), - $this->_em->getClassMetadata(DDC279EntityZ::class), - ] + $this->createSchemaForModels( + DDC279EntityXAbstract::class, + DDC279EntityX::class, + DDC279EntityY::class, + DDC279EntityZ::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php index 236667dc6fa..dbac108568e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php @@ -10,7 +10,6 @@ use Doctrine\ORM\Mapping\GeneratedValue; use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\Table; -use Doctrine\ORM\Tools\ToolsException; use Doctrine\Tests\Models\DDC2825\ExplicitSchemaAndTable; use Doctrine\Tests\Models\DDC2825\SchemaAndTableInTableName; use Doctrine\Tests\OrmFunctionalTestCase; @@ -68,11 +67,7 @@ public function testClassSchemaMappingsValidity(string $className, string $expec */ public function testPersistenceOfEntityWithSchemaMapping(string $className): void { - try { - $this->_schemaTool->createSchema([$this->_em->getClassMetadata($className)]); - } catch (ToolsException) { - // table already exists - } + $this->createSchemaForModels($className); $this->_em->persist(new $className()); $this->_em->flush(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php index d4e845abc19..73fc94ec6cf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php @@ -11,7 +11,6 @@ use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\OneToOne; use Doctrine\ORM\Mapping\Table; -use Doctrine\ORM\Tools\ToolsException; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -25,15 +24,7 @@ protected function setUp(): void $this->enableSecondLevelCache(); parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2862User::class), - $this->_em->getClassMetadata(DDC2862Driver::class), - ] - ); - } catch (ToolsException) { - } + $this->createSchemaForModels(DDC2862User::class, DDC2862Driver::class); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2931Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2931Test.php index e7b848e193c..820b4c1a80c 100755 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2931Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2931Test.php @@ -11,7 +11,6 @@ use Doctrine\ORM\Mapping\OneToOne; use Doctrine\ORM\Query; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; /** * @group DDC-2931 @@ -22,15 +21,7 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2931User::class), - ] - ); - } catch (Exception) { - // no action needed - schema seems to be already in place - } + $this->createSchemaForModels(DDC2931User::class); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php index e5c0113fe0e..8862c4505be 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php @@ -14,7 +14,6 @@ use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\Table; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; use Stringable; use function is_string; @@ -35,15 +34,7 @@ protected function setUp(): void ); } - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2984User::class), - ] - ); - } catch (Exception) { - // no action needed - schema seems to be already in place - } + $this->createSchemaForModels(DDC2984User::class); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php index ba3f6abcd5f..b6f86e24ce4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php @@ -20,11 +20,9 @@ class DDC2996Test extends OrmFunctionalTestCase { public function testIssue(): void { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC2996User::class), - $this->_em->getClassMetadata(DDC2996UserPreference::class), - ] + $this->createSchemaForModels( + DDC2996User::class, + DDC2996UserPreference::class ); $pref = new DDC2996UserPreference(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php index 5cef0d320cf..2007561e881 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php @@ -27,11 +27,9 @@ class DDC3033Test extends OrmFunctionalTestCase { public function testIssue(): void { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC3033User::class), - $this->_em->getClassMetadata(DDC3033Product::class), - ] + $this->createSchemaForModels( + DDC3033User::class, + DDC3033Product::class ); $user = new DDC3033User(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3042Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3042Test.php index 99597727105..7c77a32475f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3042Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3042Test.php @@ -19,12 +19,7 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC3042Foo::class), - $this->_em->getClassMetadata(DDC3042Bar::class), - ] - ); + $this->createSchemaForModels(DDC3042Foo::class, DDC3042Bar::class); } public function testSQLGenerationDoesNotProvokeAliasCollisions(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3160Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3160Test.php index 6037f7e0fa3..bb61473dce4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3160Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3160Test.php @@ -54,7 +54,7 @@ class DDC3160OnFlushListener public function onFlush(OnFlushEventArgs $args): void { - $em = $args->getEntityManager(); + $em = $args->getObjectManager(); $uow = $em->getUnitOfWork(); foreach ($uow->getScheduledEntityInsertions() as $entity) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php index a2586a2e6a2..6dcdbaaeb4e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php @@ -23,13 +23,11 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC3170AbstractEntityJoined::class), - $this->_em->getClassMetadata(DDC3170ProductJoined::class), - $this->_em->getClassMetadata(DDC3170AbstractEntitySingleTable::class), - $this->_em->getClassMetadata(DDC3170ProductSingleTable::class), - ] + $this->createSchemaForModels( + DDC3170AbstractEntityJoined::class, + DDC3170ProductJoined::class, + DDC3170AbstractEntitySingleTable::class, + DDC3170ProductSingleTable::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php index 3ccf471dfdb..aaa0e7d83d1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php @@ -38,11 +38,9 @@ protected function setUp(): void Type::addType('ddc3192_currency_code', DDC3192CurrencyCode::class); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC3192Currency::class), - $this->_em->getClassMetadata(DDC3192Transaction::class), - ] + $this->createSchemaForModels( + DDC3192Currency::class, + DDC3192Transaction::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php index c3e96ce6f44..c0c9bfe927a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php @@ -37,11 +37,7 @@ public function testResolveTargetEntitiesChangesDiscriminatorMapValues(): void $this->_em->getEventManager()->addEventSubscriber($resolveTargetEntity); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC3300Person::class), - ] - ); + $this->createSchemaForModels(DDC3300Person::class); $boss = new DDC3300HumanBoss('boss'); $employee = new DDC3300HumanEmployee('employee'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3303Test.php index 3e07b9804c6..776dfb68f95 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3303Test.php @@ -20,7 +20,7 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema([$this->_em->getClassMetadata(DDC3303Employee::class)]); + $this->createSchemaForModels(DDC3303Employee::class); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php index 4de7c54b2dd..f23f1ae166c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php @@ -27,12 +27,10 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC345User::class), - $this->_em->getClassMetadata(DDC345Group::class), - $this->_em->getClassMetadata(DDC345Membership::class), - ] + $this->createSchemaForModels( + DDC345User::class, + DDC345Group::class, + DDC345Membership::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php index c0e911559da..53b4d557203 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php @@ -13,22 +13,13 @@ use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; class DDC353Test extends OrmFunctionalTestCase { protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC353File::class), - $this->_em->getClassMetadata(DDC353Picture::class), - ] - ); - } catch (Exception) { - } + $this->createSchemaForModels(DDC353File::class, DDC353Picture::class); } public function testWorkingCase(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3582Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3582Test.php index 2dd2e16b723..0886a6b5d26 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3582Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3582Test.php @@ -17,7 +17,7 @@ class DDC3582Test extends OrmFunctionalTestCase { public function testNestedEmbeddablesAreHydratedWithProperClass(): void { - $this->_schemaTool->createSchema([$this->_em->getClassMetadata(DDC3582Entity::class)]); + $this->createSchemaForModels(DDC3582Entity::class); $this->_em->persist(new DDC3582Entity('foo')); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php index d7f200166c0..b20466f41b2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php @@ -17,12 +17,10 @@ class DDC3597Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC3597Root::class), - $this->_em->getClassMetadata(DDC3597Media::class), - $this->_em->getClassMetadata(DDC3597Image::class), - ] + $this->createSchemaForModels( + DDC3597Root::class, + DDC3597Media::class, + DDC3597Image::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php index c837372f575..7e83ee87bc0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php @@ -17,7 +17,6 @@ use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\InheritanceType; use Doctrine\ORM\Tools\SchemaTool; -use Doctrine\ORM\Tools\ToolsException; use Doctrine\Tests\OrmFunctionalTestCase; use Doctrine\Tests\TestUtil; @@ -47,15 +46,11 @@ protected function setUp(): void self::markTestSkipped('Need a post-insert ID generator in order to make this test work correctly'); } - try { - $this->_schemaTool->createSchema([ - $metadata, - $this->_em->getClassMetadata(DDC3634JTIBaseEntity::class), - $this->_em->getClassMetadata(DDC3634JTIChildEntity::class), - ]); - } catch (ToolsException) { - // schema already in place - } + $this->createSchemaForModels( + DDC3634Entity::class, + DDC3634JTIBaseEntity::class, + DDC3634JTIChildEntity::class + ); } public function testSavesVeryLargeIntegerAutoGeneratedValue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php index 75c9c25ffd7..8f3ca785963 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php @@ -26,12 +26,7 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC371Parent::class), - $this->_em->getClassMetadata(DDC371Child::class), - ] - ); + $this->createSchemaForModels(DDC371Parent::class, DDC371Child::class); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php index 1a0d0675622..0ccfc3e652a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php @@ -25,12 +25,10 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC422Guest::class), - $this->_em->getClassMetadata(DDC422Customer::class), - $this->_em->getClassMetadata(DDC422Contact::class), - ] + $this->createSchemaForModels( + DDC422Guest::class, + DDC422Customer::class, + DDC422Contact::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php index d3e72ccff3f..bdd852d213a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php @@ -17,11 +17,7 @@ class DDC425Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC425Entity::class), - ] - ); + $this->createSchemaForModels(DDC425Entity::class); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php index 20086f5637d..0404c668b0e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php @@ -23,10 +23,7 @@ class DDC440Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(DDC440Phone::class), - $this->_em->getClassMetadata(DDC440Client::class), - ]); + $this->createSchemaForModels(DDC440Phone::class, DDC440Client::class); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php index bf936560915..ff263faccd7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php @@ -20,11 +20,7 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC444User::class), - ] - ); + $this->createSchemaForModels(DDC444User::class); } public function testExplicitPolicy(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php index 9ccd4c5ec20..bf96fb96d2f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php @@ -24,12 +24,10 @@ class DDC448Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC448MainTable::class), - $this->_em->getClassMetadata(DDC448ConnectedClass::class), - $this->_em->getClassMetadata(DDC448SubTable::class), - ] + $this->createSchemaForModels( + DDC448MainTable::class, + DDC448ConnectedClass::class, + DDC448SubTable::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php index 77d5a236f95..98181d12391 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php @@ -22,12 +22,10 @@ class DDC493Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC493Customer::class), - $this->_em->getClassMetadata(DDC493Distributor::class), - $this->_em->getClassMetadata(DDC493Contact::class), - ] + $this->createSchemaForModels( + DDC493Customer::class, + DDC493Distributor::class, + DDC493Contact::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php index 637a7ea865a..da8d3c73507 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php @@ -20,12 +20,10 @@ class DDC512Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC512Customer::class), - $this->_em->getClassMetadata(DDC512OfferItem::class), - $this->_em->getClassMetadata(DDC512Item::class), - ] + $this->createSchemaForModels( + DDC512Customer::class, + DDC512OfferItem::class, + DDC512Item::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php index f88d75c2fb4..7d530384f57 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php @@ -22,12 +22,10 @@ class DDC513Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC513OfferItem::class), - $this->_em->getClassMetadata(DDC513Item::class), - $this->_em->getClassMetadata(DDC513Price::class), - ] + $this->createSchemaForModels( + DDC513OfferItem::class, + DDC513Item::class, + DDC513Price::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php index d6d0ada4276..d9299555d8e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php @@ -24,11 +24,9 @@ class DDC531Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC531Item::class), - $this->_em->getClassMetadata(DDC531SubItem::class), - ] + $this->createSchemaForModels( + DDC531Item::class, + DDC531SubItem::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php index 663c0282646..eacfd9cde71 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php @@ -16,11 +16,7 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC588Site::class), - ] - ); + $this->createSchemaForModels(DDC588Site::class); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC599Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC599Test.php index fef1aa0d4c8..ecb0495d038 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC599Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC599Test.php @@ -17,7 +17,6 @@ use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\ORM\Mapping\OneToMany; use Doctrine\Tests\OrmFunctionalTestCase; -use Exception; class DDC599Test extends OrmFunctionalTestCase { @@ -25,16 +24,11 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC599Item::class), - $this->_em->getClassMetadata(DDC599Subitem::class), - $this->_em->getClassMetadata(DDC599Child::class), - ] - ); - } catch (Exception) { - } + $this->createSchemaForModels( + DDC599Item::class, + DDC599Subitem::class, + DDC599Child::class + ); } public function testCascadeRemoveOnInheritanceHierarchy(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index cd6cce4825d..cdca83c5c90 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -14,7 +14,6 @@ use Doctrine\ORM\Mapping\InheritanceType; use Doctrine\ORM\Mapping\Table; use Doctrine\ORM\OptimisticLockException; -use Doctrine\ORM\Tools\ToolsException; use Doctrine\Persistence\Mapping\MappingException; use Doctrine\Tests\OrmFunctionalTestCase; @@ -31,14 +30,11 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(DDC6303BaseClass::class), - $this->_em->getClassMetadata(DDC6303ChildA::class), - $this->_em->getClassMetadata(DDC6303ChildB::class), - ]); - } catch (ToolsException) { - } + $this->createSchemaForModels( + DDC6303BaseClass::class, + DDC6303ChildA::class, + DDC6303ChildB::class + ); } public function testMixedTypeHydratedCorrectlyInJoinedInheritance(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC719Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC719Test.php index f0c1d0e9814..a24724c270c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC719Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC719Test.php @@ -24,11 +24,7 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC719Group::class), - ] - ); + $this->createSchemaForModels(DDC719Group::class); } public function testIsEmptySqlGeneration(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php index 102cace4b4b..dd85e0345ed 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php @@ -19,11 +19,9 @@ class DDC809Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC809Variant::class), - $this->_em->getClassMetadata(DDC809SpecificationValue::class), - ] + $this->createSchemaForModels( + DDC809Variant::class, + DDC809SpecificationValue::class ); $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php index 4f458229e14..2f3ab0563be 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php @@ -20,14 +20,12 @@ class DDC837Test extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC837Super::class), - $this->_em->getClassMetadata(DDC837Class1::class), - $this->_em->getClassMetadata(DDC837Class2::class), - $this->_em->getClassMetadata(DDC837Class3::class), - $this->_em->getClassMetadata(DDC837Aggregate::class), - ] + $this->createSchemaForModels( + DDC837Super::class, + DDC837Class1::class, + DDC837Class2::class, + DDC837Class3::class, + DDC837Aggregate::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH2947Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH2947Test.php index 907f7e14fb8..2e2d125a968 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH2947Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH2947Test.php @@ -25,7 +25,7 @@ protected function setUp(): void parent::setUp(); - $this->_schemaTool->createSchema([$this->_em->getClassMetadata(GH2947Car::class)]); + $this->createSchemaForModels(GH2947Car::class); } public function testIssue(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5562Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5562Test.php index b15c7091535..053167a8505 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5562Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5562Test.php @@ -25,12 +25,10 @@ protected function setUp(): void parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(GH5562User::class), - $this->_em->getClassMetadata(GH5562Manager::class), - $this->_em->getClassMetadata(GH5562Merchant::class), - ] + $this->createSchemaForModels( + GH5562User::class, + GH5562Manager::class, + GH5562Merchant::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php index 843be4b7348..2751e2917a4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php @@ -29,12 +29,10 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(GH5762Driver::class), - $this->_em->getClassMetadata(GH5762DriverRide::class), - $this->_em->getClassMetadata(GH5762Car::class), - ] + $this->createSchemaForModels( + GH5762Driver::class, + GH5762DriverRide::class, + GH5762Car::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php index 076aea829ab..047c2429e14 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php @@ -29,9 +29,7 @@ protected function setUp(): void Type::addType(GH5804Type::NAME, GH5804Type::class); - $this->_schemaTool->createSchema( - [$this->_em->getClassMetadata(GH5804Article::class)] - ); + $this->createSchemaForModels(GH5804Article::class); } public function testTextColumnSaveAndRetrieve2(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php index b9424e25709..21206eabac0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php @@ -29,12 +29,7 @@ protected function setUp(): void Type::addType(GH5887CustomIdObjectType::NAME, GH5887CustomIdObjectType::class); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(GH5887Cart::class), - $this->_em->getClassMetadata(GH5887Customer::class), - ] - ); + $this->createSchemaForModels(GH5887Cart::class, GH5887Customer::class); } public function testLazyLoadsForeignEntitiesInOneToOneRelationWhileHavingCustomIdObject(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php index 7ba3ca017d6..0eff597d17a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php @@ -29,12 +29,10 @@ protected function setUp(): void Type::addType(GH6141PeopleType::NAME, GH6141PeopleType::class); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(GH6141Person::class), - $this->_em->getClassMetadata(GH6141Boss::class), - $this->_em->getClassMetadata(GH6141Employee::class), - ] + $this->createSchemaForModels( + GH6141Person::class, + GH6141Boss::class, + GH6141Employee::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index 037448810e3..ce862a7235f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Doctrine\Tests\Functional\Ticket; +namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\ORM\Mapping\Cache; use Doctrine\ORM\Mapping\Column; @@ -25,10 +25,10 @@ protected function setUp(): void parent::setUp(); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(GH6217AssociatedEntity::class), - $this->_em->getClassMetadata(GH6217FetchedEntity::class), - ]); + $this->createSchemaForModels( + GH6217AssociatedEntity::class, + GH6217FetchedEntity::class + ); } public function testLoadingOfSecondLevelCacheOnEagerAssociations(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php index 57dd8334635..57b625ca904 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php @@ -28,13 +28,11 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(GH6362Start::class), - $this->_em->getClassMetadata(GH6362Base::class), - $this->_em->getClassMetadata(GH6362Child::class), - $this->_em->getClassMetadata(GH6362Join::class), - ] + $this->createSchemaForModels( + GH6362Start::class, + GH6362Base::class, + GH6362Child::class, + GH6362Join::class ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6394Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6394Test.php index 9f340691e24..c13a5fa92c4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6394Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6394Test.php @@ -18,12 +18,7 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(A::class), - $this->_em->getClassMetadata(B::class), - ] - ); + $this->createSchemaForModels(A::class, B::class); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php index 062d932c344..838015bb3b9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php @@ -22,11 +22,11 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(GH6464Post::class), - $this->_em->getClassMetadata(GH6464User::class), - $this->_em->getClassMetadata(GH6464Author::class), - ]); + $this->createSchemaForModels( + GH6464Post::class, + GH6464User::class, + GH6464Author::class + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7735Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7735Test.php index b99acbd9181..fdb76377b3c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7735Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7735Test.php @@ -22,12 +22,10 @@ protected function setUp(): void $this->enableSecondLevelCache(); parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(GH7735Car::class), - $this->_em->getClassMetadata(GH7735Power::class), - $this->_em->getClassMetadata(GH7735Engine::class), - ] + $this->createSchemaForModels( + GH7735Car::class, + GH7735Power::class, + GH7735Engine::class ); $this->_em->persist(new GH7735Car(1, new GH7735Engine(1, 'turbo', new GH7735Power(1)))); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7875Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7875Test.php index fbbc805e7ab..f405f78f15e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7875Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7875Test.php @@ -10,7 +10,6 @@ use Doctrine\ORM\Mapping\GeneratedValue; use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\Table; -use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\OrmFunctionalTestCase; use function array_filter; @@ -49,22 +48,21 @@ private function filterCreateTable(array $sqls, string $tableName): array public function testUpdateSchemaSql(): void { - $classes = [$this->_em->getClassMetadata(GH7875MyEntity::class)]; + $classes = [GH7875MyEntity::class]; - $tool = new SchemaTool($this->_em); - $sqls = $this->filterCreateTable($tool->getUpdateSchemaSql($classes), 'gh7875_my_entity'); + $sqls = $this->filterCreateTable($this->getUpdateSchemaSqlForModels(...$classes), 'gh7875_my_entity'); self::assertCount(1, $sqls); $this->_em->getConnection()->executeStatement(current($sqls)); - $sqls = array_filter($tool->getUpdateSchemaSql($classes), static fn (string $sql): bool => str_contains($sql, ' gh7875_my_entity ')); + $sqls = array_filter($this->getUpdateSchemaSqlForModels(...$classes), static fn (string $sql): bool => str_contains($sql, ' gh7875_my_entity ')); self::assertSame([], $sqls); - $classes[] = $this->_em->getClassMetadata(GH7875MyOtherEntity::class); + $classes[] = GH7875MyOtherEntity::class; - $sqls = $tool->getUpdateSchemaSql($classes); + $sqls = $this->getUpdateSchemaSqlForModels(...$classes); self::assertCount(0, $this->filterCreateTable($sqls, 'gh7875_my_entity')); self::assertCount(1, $this->filterCreateTable($sqls, 'gh7875_my_other_entity')); @@ -74,17 +72,16 @@ public function testUpdateSchemaSqlWithSchemaAssetFilter(): void { $filterCallback = static fn ($assetName): bool => $assetName !== 'gh7875_my_entity'; - $classes = [$this->_em->getClassMetadata(GH7875MyEntity::class)]; + $class = GH7875MyEntity::class; - $tool = new SchemaTool($this->_em); - $tool->createSchema($classes); + $this->createSchemaForModels($class); $config = $this->_em->getConnection()->getConfiguration(); $config->setSchemaAssetsFilter($filterCallback); $previousFilter = $config->getSchemaAssetsFilter(); - $sqls = $tool->getUpdateSchemaSql($classes); + $sqls = $this->getUpdateSchemaSqlForModels($class); $sqls = array_filter($sqls, static fn (string $sql): bool => str_contains($sql, ' gh7875_my_entity ')); self::assertCount(0, $sqls); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH9807Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH9807Test.php new file mode 100644 index 00000000000..6298fce4fb5 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH9807Test.php @@ -0,0 +1,131 @@ +createSchemaForModels(GH9807Main::class, GH9807Join::class); + } + + public function testHydrateJoinedCollectionWithFirstNullishRow(): void + { + $rsm = new ResultSetMapping(); + $rsm->addEntityResult(GH9807Main::class, 'm'); + $rsm->addJoinedEntityResult(GH9807Join::class, 'j', 'm', 'joins'); + + $rsm->addFieldResult('m', 'id_0', 'id'); + $rsm->addFieldResult('j', 'id_1', 'id'); + $rsm->addFieldResult('j', 'value_2', 'value'); + + $hydrator = new ObjectHydrator($this->_em); + + $uow = $this->_em->getUnitOfWork(); + + $uow->createEntity( + GH9807Main::class, + ['id' => 1] + ); + + $resultSet = [ + [ + 'id_0' => 1, + 'id_1' => null, + 'value_2' => null, + ], + [ + 'id_0' => 1, + 'id_1' => 1, + 'value_2' => '2', + ], + [ + 'id_0' => 1, + 'id_1' => 2, + 'value_2' => '2', + ], + ]; + + $stmt = new Result(new ArrayResult($resultSet), $this->createMock(Connection::class)); + + /** @var GH9807Main[] $result */ + $result = $hydrator->hydrateAll($stmt, $rsm); + + self::assertInstanceOf(GH9807Main::class, $result[0]); + self::assertCount(2, $result[0]->getJoins()); + } +} + +/** + * @Entity + */ +class GH9807Main +{ + /** + * @var int + * @Column(type="integer") + * @Id + * @GeneratedValue + */ + private $id; + + /** + * @ORM\ManyToMany(targetEntity="GH9807Join", inversedBy="starts") + * + * @var Collection + */ + private $joins; + + /** + * @return Collection + */ + public function getJoins(): Collection + { + return $this->joins; + } +} + +/** + * @Entity + */ +class GH9807Join +{ + /** + * @var int + * @Column(type="integer") + * @Id + * @GeneratedValue + */ + private $id; + + /** + * @ORM\ManyToMany(targetEntity="GH9807Main", mappedBy="bases") + * + * @var Collection + */ + private $mains; + + /** + * @ORM\Column(type="string", nullable=false) + * + * @var string + */ + private $value; +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php index 8fb3b0c245c..b1702fbaf19 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php @@ -17,9 +17,7 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(Ticket2481Product::class), - ]); + $this->createSchemaForModels(Ticket2481Product::class); } public function testEmptyInsert(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php index c3259c58875..15c78330487 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php @@ -20,10 +20,10 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(PersonTicket4646Abstract::class), - $this->_em->getClassMetadata(EmployeeTicket4646Abstract::class), - ]); + $this->createSchemaForModels( + PersonTicket4646Abstract::class, + EmployeeTicket4646Abstract::class + ); } public function testInstanceOf(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php index 8ae9987426e..2591f0299b5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php @@ -20,11 +20,11 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(PersonTicket4646MultiLevel::class), - $this->_em->getClassMetadata(EmployeeTicket4646MultiLevel::class), - $this->_em->getClassMetadata(EngineerTicket4646MultiLevel::class), - ]); + $this->createSchemaForModels( + PersonTicket4646MultiLevel::class, + EmployeeTicket4646MultiLevel::class, + EngineerTicket4646MultiLevel::class + ); } public function testInstanceOf(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php index 3f384fff0d4..4c2393071b2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php @@ -19,10 +19,10 @@ class Ticket4646InstanceOfParametricTest extends OrmFunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(PersonTicket4646Parametric::class), - $this->_em->getClassMetadata(EmployeeTicket4646Parametric::class), - ]); + $this->createSchemaForModels( + PersonTicket4646Parametric::class, + EmployeeTicket4646Parametric::class + ); } public function testInstanceOf(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php index 83aeef6f0fa..d83a3031d35 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php @@ -20,10 +20,10 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(PersonTicket4646::class), - $this->_em->getClassMetadata(EmployeeTicket4646::class), - ]); + $this->createSchemaForModels( + PersonTicket4646::class, + EmployeeTicket4646::class + ); } public function testInstanceOf(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfWithMultipleParametersTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfWithMultipleParametersTest.php index 6a0a8dae215..8e2312a8d81 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfWithMultipleParametersTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfWithMultipleParametersTest.php @@ -20,12 +20,12 @@ protected function setUp(): void { parent::setUp(); - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(PersonTicket4646Multiple::class), - $this->_em->getClassMetadata(EmployeeTicket4646Multiple::class), - $this->_em->getClassMetadata(ManagerTicket4646Multiple::class), - $this->_em->getClassMetadata(InternTicket4646Multiple::class), - ]); + $this->createSchemaForModels( + PersonTicket4646Multiple::class, + EmployeeTicket4646Multiple::class, + ManagerTicket4646Multiple::class, + InternTicket4646Multiple::class + ); } public function testInstanceOf(): void diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php index 37f5e140f54..bbaeb970079 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -6,6 +6,8 @@ use DateTime; use DateTimeZone; +use Doctrine\DBAL\Types\ArrayType; +use Doctrine\DBAL\Types\ObjectType; use Doctrine\DBAL\Types\Types; use Doctrine\Tests\Models\Generic\BooleanModel; use Doctrine\Tests\Models\Generic\DateTimeModel; @@ -14,6 +16,8 @@ use Doctrine\Tests\OrmFunctionalTestCase; use stdClass; +use function class_exists; + class TypeTest extends OrmFunctionalTestCase { protected function setUp(): void @@ -70,10 +74,16 @@ public function testBoolean(): void public function testArray(): void { + if (! class_exists(ArrayType::class)) { + self::markTestSkipped('Test valid for doctrine/dbal:3.x only.'); + } + $serialize = new SerializationModel(); $serialize->array['foo'] = 'bar'; $serialize->array['bar'] = 'baz'; + $this->createSchemaForModels(SerializationModel::class); + static::$sharedConn->executeStatement('DELETE FROM serialize_model'); $this->_em->persist($serialize); $this->_em->flush(); $this->_em->clear(); @@ -86,9 +96,15 @@ public function testArray(): void public function testObject(): void { + if (! class_exists(ObjectType::class)) { + self::markTestSkipped('Test valid for doctrine/dbal:3.x only.'); + } + $serialize = new SerializationModel(); $serialize->object = new stdClass(); + $this->createSchemaForModels(SerializationModel::class); + static::$sharedConn->executeStatement('DELETE FROM serialize_model'); $this->_em->persist($serialize); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php index a9388ca0215..de30f3384d0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php @@ -341,11 +341,7 @@ public function testThrowsExceptionOnInfiniteEmbeddableNesting( ) ); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\' . $embeddableClassName), - ] - ); + $this->createSchemaForModels(__NAMESPACE__ . '\\' . $embeddableClassName); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php index 344d9913920..d008e17ef79 100644 --- a/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php @@ -4,7 +4,6 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\ORM\Exception\ORMException; use Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity; use Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -20,15 +19,10 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(FirstRelatedEntity::class), - $this->_em->getClassMetadata(SecondRelatedEntity::class), - ] - ); - } catch (ORMException) { - } + $this->createSchemaForModels( + FirstRelatedEntity::class, + SecondRelatedEntity::class + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index d8ff285b565..c167a5b0cd0 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -11,6 +11,7 @@ use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\ORM\Mapping\MappingException; use Doctrine\Persistence\Mapping\Driver\MappingDriver; +use Doctrine\Persistence\Mapping\MappingException as PersistenceMappingException; use Doctrine\Persistence\Mapping\RuntimeReflectionService; use Doctrine\Tests\Models\DDC117\DDC117Translation; use Doctrine\Tests\Models\DDC3293\DDC3293User; @@ -18,7 +19,7 @@ use Doctrine\Tests\Models\DDC889\DDC889Class; use Doctrine\Tests\Models\DDC889\DDC889Entity; use Doctrine\Tests\Models\DDC889\DDC889SuperClass; -use Doctrine\Tests\Models\Generic\SerializationModel; +use Doctrine\Tests\Models\Generic\BooleanModel; use Doctrine\Tests\Models\GH7141\GH7141Article; use Doctrine\Tests\Models\GH7316\GH7316Article; use Doctrine\Tests\Models\ValueObjects\Name; @@ -151,11 +152,11 @@ public function testEmbeddedMapping(): void /** * @group DDC-1468 */ - public function testInvalidMappingFileException(): void + public function testItMentionsFilenameAndEntityNameOnInvalidMapping(): void { - $this->expectException(\Doctrine\Persistence\Mapping\MappingException::class); - $this->expectExceptionMessage('Invalid mapping file \'Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml\' for class \'Doctrine\Tests\Models\Generic\SerializationModel\'.'); - $this->createClassMetadata(SerializationModel::class); + $this->expectException(PersistenceMappingException::class); + $this->expectExceptionMessage('Invalid mapping file \'Doctrine.Tests.Models.Generic.BooleanModel.dcm.xml\' for class \'Doctrine\Tests\Models\Generic\BooleanModel\'.'); + $this->createClassMetadata(BooleanModel::class); } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.BooleanModel.dcm.xml similarity index 80% rename from tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml rename to tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.BooleanModel.dcm.xml index 6e42bce75af..1594b1e01d6 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.BooleanModel.dcm.xml @@ -9,9 +9,7 @@ - - - + diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Generic.BooleanModel.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Generic.BooleanModel.dcm.yml new file mode 100644 index 00000000000..5b1ec64b874 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Generic.BooleanModel.dcm.yml @@ -0,0 +1,11 @@ +\stdClass: + type: entity + id: + id: + type: integer + unsigned: true + generator: + strategy: AUTO + fields: + booleanField: + type: boolean diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index fde54c86899..76c9a2cde5e 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -77,7 +77,7 @@ public function testAnnotationOptionsAttribute(): void ); $table = $schema->getTable('TestEntityWithAnnotationOptionsAttribute'); - foreach ([$table->getOptions(), $table->getColumn('test')->getCustomSchemaOptions()] as $options) { + foreach ([$table->getOptions(), $table->getColumn('test')->getPlatformOptions()] as $options) { self::assertArrayHasKey('foo', $options); self::assertSame('bar', $options['foo']); self::assertArrayHasKey('baz', $options); @@ -136,14 +136,14 @@ public function testPassColumnOptionsToJoinColumn(): void ); self::assertEquals( - $tableCategory->getColumn('id')->getCustomSchemaOptions(), - $tableBoard->getColumn('category_id')->getCustomSchemaOptions(), + $tableCategory->getColumn('id')->getPlatformOptions(), + $tableBoard->getColumn('category_id')->getPlatformOptions(), 'Foreign key/join column should have the same custom options as the referenced column' ); self::assertEquals( ['collation' => 'latin1_bin', 'foo' => 'bar'], - $tableBoard->getColumn('category_id')->getCustomSchemaOptions() + $tableBoard->getColumn('category_id')->getPlatformOptions() ); } @@ -177,17 +177,15 @@ public function testPostGenerateEvents(): void self::assertTrue($listener->schemaCalled); } - public function testNullDefaultNotAddedToCustomSchemaOptions(): void + public function testNullDefaultNotAddedToPlatformOptions(): void { $em = $this->getTestEntityManager(); $schemaTool = new SchemaTool($em); - $customSchemaOptions = $schemaTool->getSchemaFromMetadata([$em->getClassMetadata(NullDefaultColumn::class)]) + self::assertSame([], $schemaTool->getSchemaFromMetadata([$em->getClassMetadata(NullDefaultColumn::class)]) ->getTable('NullDefaultColumn') ->getColumn('nullDefault') - ->getCustomSchemaOptions(); - - self::assertSame([], $customSchemaOptions); + ->getPlatformOptions()); } /** @@ -198,13 +196,13 @@ public function testEnumTypeAddedToCustomSchemaOptions(): void $em = $this->getTestEntityManager(); $schemaTool = new SchemaTool($em); - $customSchemaOptions = $schemaTool->getSchemaFromMetadata([$em->getClassMetadata(Card::class)]) + $platformOptions = $schemaTool->getSchemaFromMetadata([$em->getClassMetadata(Card::class)]) ->getTable('Card') ->getColumn('suit') - ->getCustomSchemaOptions(); + ->getPlatformOptions(); - self::assertArrayHasKey('enumType', $customSchemaOptions); - self::assertSame(Suit::class, $customSchemaOptions['enumType']); + self::assertArrayHasKey('enumType', $platformOptions); + self::assertSame(Suit::class, $platformOptions['enumType']); } /** diff --git a/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerEnumIdTest.php b/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerEnumIdTest.php index 0ee426124f4..a0b9fad4e72 100644 --- a/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerEnumIdTest.php +++ b/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerEnumIdTest.php @@ -4,7 +4,6 @@ namespace Doctrine\Tests\ORM\Utility; -use Doctrine\ORM\Exception\ORMException; use Doctrine\Tests\Models\Enums\Suit; use Doctrine\Tests\Models\Enums\TypedCardEnumCompositeId; use Doctrine\Tests\Models\Enums\TypedCardEnumId; @@ -23,15 +22,10 @@ protected function setUp(): void { parent::setUp(); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(TypedCardEnumId::class), - $this->_em->getClassMetadata(TypedCardEnumCompositeId::class), - ] - ); - } catch (ORMException) { - } + $this->createSchemaForModels( + TypedCardEnumId::class, + TypedCardEnumCompositeId::class + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerTest.php b/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerTest.php index f1452be2ec5..42170e4090c 100644 --- a/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerTest.php +++ b/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerTest.php @@ -4,7 +4,6 @@ namespace Doctrine\Tests\ORM\Utility; -use Doctrine\ORM\Exception\ORMException; use Doctrine\ORM\Utility\IdentifierFlattener; use Doctrine\Tests\Models\Cache\City; use Doctrine\Tests\Models\Cache\Flight; @@ -33,17 +32,12 @@ protected function setUp(): void $this->_em->getMetadataFactory() ); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(FirstRelatedEntity::class), - $this->_em->getClassMetadata(SecondRelatedEntity::class), - $this->_em->getClassMetadata(Flight::class), - $this->_em->getClassMetadata(City::class), - ] - ); - } catch (ORMException) { - } + $this->createSchemaForModels( + FirstRelatedEntity::class, + SecondRelatedEntity::class, + Flight::class, + City::class + ); } /** diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index d36f1b9d06b..e6b4765c9e6 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Cache\CacheConfiguration; @@ -104,7 +105,6 @@ use Doctrine\Tests\Models\Generic\BooleanModel; use Doctrine\Tests\Models\Generic\DateTimeModel; use Doctrine\Tests\Models\Generic\DecimalModel; -use Doctrine\Tests\Models\Generic\SerializationModel; use Doctrine\Tests\Models\GeoNames\Admin1; use Doctrine\Tests\Models\GeoNames\Admin1AlternateName; use Doctrine\Tests\Models\Issue5989\Issue5989Employee; @@ -292,7 +292,6 @@ abstract class OrmFunctionalTestCase extends OrmTestCase BooleanModel::class, DateTimeModel::class, DecimalModel::class, - SerializationModel::class, ], 'routing' => [ RoutingLeg::class, @@ -483,14 +482,44 @@ abstract class OrmFunctionalTestCase extends OrmTestCase final protected function createSchemaForModels(string ...$models): void { try { - $this->_schemaTool->createSchema(array_map( - fn (string $className): ClassMetadata => $this->_em->getClassMetadata($className), - $models - )); + $this->_schemaTool->createSchema($this->getMetadataForModels($models)); } catch (ToolsException) { } } + /** + * @param class-string ...$models + * + * @return string[] + */ + final protected function getUpdateSchemaSqlForModels(string ...$models): array + { + return $this->_schemaTool->getUpdateSchemaSql($this->getMetadataForModels($models)); + } + + /** + * @param class-string ...$models + */ + final protected function getSchemaForModels(string ...$models): Schema + { + return $this->_schemaTool->getSchemaFromMetadata($this->getMetadataForModels($models)); + } + + /** + * @param class-string[] $models + * + * @return ClassMetadata[] + */ + private function getMetadataForModels(array $models): array + { + return array_map( + function (string $className): ClassMetadata { + return $this->_em->getClassMetadata($className); + }, + $models + ); + } + protected function useModelSet(string $setName): void { $this->_usedModelSets[$setName] = true; @@ -560,7 +589,6 @@ protected function tearDown(): void $conn->executeStatement('DELETE FROM boolean_model'); $conn->executeStatement('DELETE FROM date_time_model'); $conn->executeStatement('DELETE FROM decimal_model'); - $conn->executeStatement('DELETE FROM serialize_model'); } if (isset($this->_usedModelSets['routing'])) {