From c62bb63f0d955b0d06fd768e120c37d17c37a47d Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 29 Oct 2023 20:08:54 +0100 Subject: [PATCH] Support DBAL 4 and ORM 3 --- composer.json | 16 ++++--- phpstan.neon.dist | 4 ++ psalm.xml | 9 ++++ src/AbstractFixture.php | 2 +- .../Listener/MongoDBReferenceListener.php | 2 +- src/Event/Listener/ORMReferenceListener.php | 6 +-- src/Purger/ORMPurger.php | 5 ++- tests/Common/DataFixtures/BaseTestCase.php | 37 +++++++++------- .../Executor/ORMExecutorSharedFixtureTest.php | 8 +--- .../DataFixtures/Executor/ORMExecutorTest.php | 17 +++---- .../ProxyReferenceRepositoryTest.php | 2 +- .../Purger/ORMPurgerExcludeTest.php | 11 +---- .../DataFixtures/Purger/ORMPurgerTest.php | 14 +++--- .../DataFixtures/ReferenceRepositoryTest.php | 8 ++-- .../Sorter/TopologicalSorterTest.php | 44 +++++++++---------- .../Common/DataFixtures/TestEntity/Group.php | 5 +++ .../TestEntity/GroupWithSchema.php | 6 +++ tests/Common/DataFixtures/TestEntity/Link.php | 4 ++ .../Common/DataFixtures/TestEntity/Quoted.php | 14 ++++-- tests/Common/DataFixtures/TestEntity/Role.php | 5 +++ tests/Common/DataFixtures/TestEntity/User.php | 13 ++++++ .../TestEntity/UserWithSchema.php | 14 ++++++ .../TestPurgeEntity/ExcludedEntity.php | 3 ++ .../TestPurgeEntity/IncludedEntity.php | 3 ++ .../DataFixtures/TestTypes/UuidType.php | 2 +- tests/Mock/ForwardCompatibleEntityManager.php | 21 +++++++++ 26 files changed, 181 insertions(+), 94 deletions(-) create mode 100644 tests/Mock/ForwardCompatibleEntityManager.php diff --git a/composer.json b/composer.json index e4260f99..41f271fe 100644 --- a/composer.json +++ b/composer.json @@ -19,19 +19,21 @@ "doctrine/persistence": "^2.0|^3.0" }, "conflict": { - "doctrine/dbal": "<3", - "doctrine/orm": "<2.14", + "doctrine/dbal": "<3.5 || >=5", + "doctrine/orm": "<2.14 || >=4", "doctrine/phpcr-odm": "<1.3.0" }, "require-dev": { "ext-sqlite3": "*", - "doctrine/coding-standard": "^11.1", - "doctrine/dbal": "^3.0", + "doctrine/annotations": "^1.12 || ^2", + "doctrine/coding-standard": "^12", + "doctrine/dbal": "^3.5 || ^4", "doctrine/mongodb-odm": "^1.3.0 || ^2.0.0", - "doctrine/orm": "^2.14", + "doctrine/orm": "^2.14 || ^3", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.6.6 || ^10.0", - "symfony/cache": "^5.4 || ^6.2", + "phpunit/phpunit": "^9.6.13 || ^10.4.2", + "symfony/cache": "^5.4 || ^6.3 || ^7", + "symfony/var-exporter": "^5.4 || ^6.3 || ^7", "vimeo/psalm": "^5.9" }, "suggest": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index e2b42229..088bd6d0 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -5,5 +5,9 @@ parameters: - src - tests + ignoreErrors: + # ORM 3 forward compatibility + - '~^Parameter \$assoc of method Doctrine\\Common\\DataFixtures\\Purger\\ORMPurger\:\:getJoinTableName\(\) has invalid type Doctrine\\ORM\\Mapping\\ManyToManyOwningSideMapping\.$~' + includes: - phpstan-baseline.neon diff --git a/psalm.xml b/psalm.xml index 19e2ba03..1a74623d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -16,4 +16,13 @@ + + + + + + + + + diff --git a/src/AbstractFixture.php b/src/AbstractFixture.php index 1214e8de..8de1e971 100644 --- a/src/AbstractFixture.php +++ b/src/AbstractFixture.php @@ -24,7 +24,7 @@ abstract class AbstractFixture implements SharedFixtureInterface protected $referenceRepository; /** - * {@inheritdoc} + * {@inheritDoc} */ public function setReferenceRepository(ReferenceRepository $referenceRepository) { diff --git a/src/Event/Listener/MongoDBReferenceListener.php b/src/Event/Listener/MongoDBReferenceListener.php index 7001cf08..31f28214 100644 --- a/src/Event/Listener/MongoDBReferenceListener.php +++ b/src/Event/Listener/MongoDBReferenceListener.php @@ -24,7 +24,7 @@ public function __construct(ReferenceRepository $referenceRepository) } /** - * {@inheritdoc} + * {@inheritDoc} */ public function getSubscribedEvents(): array { diff --git a/src/Event/Listener/ORMReferenceListener.php b/src/Event/Listener/ORMReferenceListener.php index 2ed72185..75d6cca0 100644 --- a/src/Event/Listener/ORMReferenceListener.php +++ b/src/Event/Listener/ORMReferenceListener.php @@ -6,7 +6,7 @@ use Doctrine\Common\DataFixtures\ReferenceRepository; use Doctrine\Common\EventSubscriber; -use Doctrine\ORM\Event\LifecycleEventArgs; +use Doctrine\ORM\Event\PostPersistEventArgs; use function get_class; @@ -24,7 +24,7 @@ public function __construct(ReferenceRepository $referenceRepository) } /** - * {@inheritdoc} + * {@inheritDoc} */ public function getSubscribedEvents(): array { @@ -35,7 +35,7 @@ public function getSubscribedEvents(): array /** * Populates identities for stored references */ - public function postPersist(LifecycleEventArgs $args): void + public function postPersist(PostPersistEventArgs $args): void { $object = $args->getObject(); diff --git a/src/Purger/ORMPurger.php b/src/Purger/ORMPurger.php index 1adb4bc1..b153a0e6 100644 --- a/src/Purger/ORMPurger.php +++ b/src/Purger/ORMPurger.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\Schema\Identifier; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Mapping\ManyToManyOwningSideMapping; use function array_map; use function array_reverse; @@ -256,9 +257,9 @@ private function getTableName(ClassMetadata $class, AbstractPlatform $platform): return $this->em->getConfiguration()->getQuoteStrategy()->getTableName($class, $platform); } - /** @param mixed[] $assoc */ + /** @param ManyToManyOwningSideMapping|mixed[] $assoc */ private function getJoinTableName( - array $assoc, + $assoc, ClassMetadata $class, AbstractPlatform $platform ): string { diff --git a/tests/Common/DataFixtures/BaseTestCase.php b/tests/Common/DataFixtures/BaseTestCase.php index 6ec4409b..d9a8869a 100644 --- a/tests/Common/DataFixtures/BaseTestCase.php +++ b/tests/Common/DataFixtures/BaseTestCase.php @@ -9,33 +9,38 @@ use Doctrine\ORM\ORMSetup; use PHPUnit\Framework\TestCase; +use function method_exists; + +use const PHP_VERSION_ID; + /** * Base test class */ abstract class BaseTestCase extends TestCase { - /** - * EntityManager mock object together with - * annotation mapping driver - */ - protected function getMockAnnotationReaderEntityManager(): EntityManager - { - $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; - $config = ORMSetup::createAnnotationMetadataConfiguration([__DIR__ . '/TestEntity'], true); - - return new EntityManager(DriverManager::getConnection($dbParams, $config), $config); - } - /** * EntityManager mock object together with * annotation mapping driver and pdo_sqlite * database in memory */ - protected function getMockSqliteEntityManager(): EntityManager + protected function getMockSqliteEntityManager(string $fixtureSet = 'TestEntity'): EntityManager { - $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; - $config = ORMSetup::createAnnotationMetadataConfiguration([__DIR__ . '/TestEntity'], true); + $dbParams = ['driver' => 'sqlite3', 'memory' => true]; + if (PHP_VERSION_ID >= 80100) { + $config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/' . $fixtureSet], true); + $config->setLazyGhostObjectEnabled(true); + } else { + $config = ORMSetup::createAnnotationMetadataConfiguration([__DIR__ . '/' . $fixtureSet], true); + } + + $connection = DriverManager::getConnection($dbParams, $config); + $platform = $connection->getDatabasePlatform(); + if (method_exists($platform, 'disableSchemaEmulation')) { + $platform->disableSchemaEmulation(); + } + + $connection->executeStatement('ATTACH DATABASE \':memory:\' AS readers'); - return new EntityManager(DriverManager::getConnection($dbParams, $config), $config); + return new EntityManager($connection, $config); } } diff --git a/tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php b/tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php index aefbceac..f4275f3e 100644 --- a/tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php +++ b/tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php @@ -12,8 +12,6 @@ use Doctrine\Tests\Common\DataFixtures\TestEntity\User; use PHPUnit\Framework\MockObject\MockObject; -use function extension_loaded; - /** * Test referenced fixture execution */ @@ -24,7 +22,7 @@ class ORMExecutorSharedFixtureTest extends BaseTestCase public function testFixtureExecution(): void { - $em = $this->getMockAnnotationReaderEntityManager(); + $em = $this->getMockSqliteEntityManager(); $purger = new ORMPurger(); $executor = new ORMExecutor($em, $purger); @@ -43,10 +41,6 @@ public function testFixtureExecution(): void public function testSharedFixtures(): void { - if (! extension_loaded('pdo_sqlite')) { - $this->markTestSkipped('Missing pdo_sqlite extension.'); - } - $em = $this->getMockSqliteEntityManager(); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); diff --git a/tests/Common/DataFixtures/Executor/ORMExecutorTest.php b/tests/Common/DataFixtures/Executor/ORMExecutorTest.php index 4b1ed870..e1ee3961 100644 --- a/tests/Common/DataFixtures/Executor/ORMExecutorTest.php +++ b/tests/Common/DataFixtures/Executor/ORMExecutorTest.php @@ -12,6 +12,7 @@ use Doctrine\Common\EventManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Tests\Common\DataFixtures\BaseTestCase; +use Doctrine\Tests\Mock\ForwardCompatibleEntityManager; use PHPUnit\Framework\MockObject\MockObject; /** @@ -38,8 +39,8 @@ public function testExecuteSingleTransactionsCountTransactionalCalls(): void { $em = $this->getMockEntityManager(); $em->method('getEventManager')->willReturn($this->createMock(EventManager::class)); - // We call transactional once for purge and for the fixtures (load) - $em->expects($this->once())->method('transactional')->with(self::isInstanceOf(Closure::class)); + // We call wrapInTransaction once for purge and for the fixtures (load) + $em->expects($this->once())->method('wrapInTransaction')->with(self::isInstanceOf(Closure::class)); $executor = new ORMExecutor($em); $fixture = $this->getMockFixture(); @@ -52,7 +53,7 @@ public function testExecuteWithPurge(): void $purger = $this->getMockPurger(); $purger->expects($this->once()) ->method('purge') - ->will($this->returnValue(null)); + ->willReturn(null); $executor = new ORMExecutor($em, $purger); $fixture = $this->getMockFixture(); $fixture->expects($this->once()) @@ -76,7 +77,7 @@ public function testCustomLegacyEntityManager(): void { $em = $this->getMockEntityManager(); $em->method('getEventManager')->willReturn($this->createMock(EventManager::class)); - $em->expects($this->once())->method('transactional')->with(self::isInstanceOf(Closure::class)); + $em->expects($this->once())->method('wrapInTransaction')->with(self::isInstanceOf(Closure::class)); $executor = new ORMExecutor($em); @$executor->execute([]); @@ -103,7 +104,7 @@ public function testExecuteMultipleTransactionsWithPurge(): void $purger = $this->getMockPurger(); $purger->expects($this->once()) ->method('purge') - ->will($this->returnValue(null)); + ->willReturn(null); $executor = new MultipleTransactionORMExecutor($em, $purger); $fixture = $this->getMockFixture(); $fixture->expects($this->once()) @@ -116,8 +117,8 @@ public function testExecuteMultipleTransactionsCountTransactionalCalls(): void { $em = $this->getMockEntityManager(); $em->method('getEventManager')->willReturn($this->createMock(EventManager::class)); - // We call transactional once for purge and twice for the fixtures (load) - $em->expects($this->exactly(3))->method('transactional')->with(self::isInstanceOf(Closure::class)); + // We call wrapInTransaction once for purge and twice for the fixtures (load) + $em->expects($this->exactly(3))->method('wrapInTransaction')->with(self::isInstanceOf(Closure::class)); $executor = new MultipleTransactionORMExecutor($em); $fixture = $this->getMockFixture(); @@ -127,7 +128,7 @@ public function testExecuteMultipleTransactionsCountTransactionalCalls(): void /** @return EntityManagerInterface&MockObject */ private function getMockEntityManager(): EntityManagerInterface { - return $this->createMock(EntityManagerInterface::class); + return $this->createMock(ForwardCompatibleEntityManager::class); } /** @return FixtureInterface&MockObject */ diff --git a/tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php b/tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php index 04514bdf..75bf6f07 100644 --- a/tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php +++ b/tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php @@ -35,7 +35,7 @@ public static function setUpBeforeClass(): void public function testReferenceEntry(): void { - $em = $this->getMockAnnotationReaderEntityManager(); + $em = $this->getMockSqliteEntityManager(); $role = new TestEntity\Role(); $role->setName('admin'); $meta = $em->getClassMetadata(self::TEST_ENTITY_ROLE); diff --git a/tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php b/tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php index 55b7834b..18226b47 100644 --- a/tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php +++ b/tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php @@ -5,15 +5,12 @@ namespace Doctrine\Tests\Common\DataFixtures; use Doctrine\Common\DataFixtures\Purger\ORMPurger; -use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\ORMSetup; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\Common\DataFixtures\TestPurgeEntity\ExcludedEntity; use Doctrine\Tests\Common\DataFixtures\TestPurgeEntity\IncludedEntity; use function count; -use function extension_loaded; use function preg_match; class ORMPurgerExcludeTest extends BaseTestCase @@ -26,13 +23,7 @@ class ORMPurgerExcludeTest extends BaseTestCase */ protected function loadTestData(): EntityManager { - if (! extension_loaded('pdo_sqlite')) { - $this->markTestSkipped('Missing pdo_sqlite extension.'); - } - - $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; - $config = ORMSetup::createAnnotationMetadataConfiguration([__DIR__ . '/../TestPurgeEntity'], true); - $em = new EntityManager(DriverManager::getConnection($dbParams, $config), $config); + $em = $this->getMockSqliteEntityManager('TestPurgeEntity'); $schemaTool = new SchemaTool($em); $schemaTool->dropDatabase(); diff --git a/tests/Common/DataFixtures/Purger/ORMPurgerTest.php b/tests/Common/DataFixtures/Purger/ORMPurgerTest.php index a9509f0e..442948ff 100644 --- a/tests/Common/DataFixtures/Purger/ORMPurgerTest.php +++ b/tests/Common/DataFixtures/Purger/ORMPurgerTest.php @@ -20,7 +20,7 @@ class ORMPurgerTest extends BaseTestCase public function testGetAssociationTables(): void { - $em = $this->getMockAnnotationReaderEntityManager(); + $em = $this->getMockSqliteEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_USER); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); @@ -28,12 +28,12 @@ public function testGetAssociationTables(): void $method = $class->getMethod('getAssociationTables'); $method->setAccessible(true); $associationTables = $method->invokeArgs($purger, [[$metadata], $platform]); - $this->assertEquals($associationTables[0], 'readers__author_reader'); + $this->assertEquals('readers.author_reader', $associationTables[0]); } public function testGetAssociationTablesQuoted(): void { - $em = $this->getMockAnnotationReaderEntityManager(); + $em = $this->getMockSqliteEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_QUOTED); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); @@ -46,7 +46,7 @@ public function testGetAssociationTablesQuoted(): void public function testTableNameWithSchema(): void { - $em = $this->getMockAnnotationReaderEntityManager(); + $em = $this->getMockSqliteEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_USER_WITH_SCHEMA); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); @@ -59,7 +59,7 @@ public function testTableNameWithSchema(): void public function testGetDeleteFromTableSQL(): void { - $em = $this->getMockAnnotationReaderEntityManager(); + $em = $this->getMockSqliteEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_GROUP); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); @@ -75,7 +75,7 @@ public function testGetDeleteFromTableSQL(): void public function testGetDeleteFromTableSQLWithSchema(): void { - $em = $this->getMockAnnotationReaderEntityManager(); + $em = $this->getMockSqliteEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_GROUP_WITH_SCHEMA); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); @@ -86,6 +86,6 @@ public function testGetDeleteFromTableSQLWithSchema(): void $method = $class->getMethod('getDeleteFromTableSQL'); $method->setAccessible(true); $sql = $method->invokeArgs($purger, [$tableName, $platform]); - $this->assertEquals('DELETE FROM test_schema__group', $sql); + $this->assertEquals('DELETE FROM test_schema."group"', $sql); } } diff --git a/tests/Common/DataFixtures/ReferenceRepositoryTest.php b/tests/Common/DataFixtures/ReferenceRepositoryTest.php index f3850317..95b66de5 100644 --- a/tests/Common/DataFixtures/ReferenceRepositoryTest.php +++ b/tests/Common/DataFixtures/ReferenceRepositoryTest.php @@ -7,19 +7,19 @@ use BadMethodCallException; use Doctrine\Common\DataFixtures\Event\Listener\ORMReferenceListener; use Doctrine\Common\DataFixtures\ReferenceRepository; -use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\UnitOfWork; -use Doctrine\Persistence\Mapping\ClassMetadata; use Doctrine\Persistence\Proxy; use Doctrine\Tests\Common\DataFixtures\TestEntity\Role; +use Doctrine\Tests\Mock\ForwardCompatibleEntityManager; use OutOfBoundsException; class ReferenceRepositoryTest extends BaseTestCase { public function testReferenceEntry(): void { - $em = $this->getMockAnnotationReaderEntityManager(); + $em = $this->getMockSqliteEntityManager(); $role = new TestEntity\Role(); $role->setName('admin'); @@ -199,7 +199,7 @@ public function testGetIdentifierWhenHasNotBeenManagedYetByUnitOfWork(): void ->with($role) ->willReturn($identitiesExpected); - $em = $this->createMock(EntityManagerInterface::class); + $em = $this->createMock(ForwardCompatibleEntityManager::class); $em->method('getUnitOfWork') ->willReturn($uow); $em->method('getClassMetadata') diff --git a/tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index e5db2e7b..1a1f8c23 100644 --- a/tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -25,11 +25,11 @@ public function testSuccessSortLinearDependency(): void { $sorter = new TopologicalSorter(); - $node1 = new ClassMetadata(1); - $node2 = new ClassMetadata(2); - $node3 = new ClassMetadata(3); - $node4 = new ClassMetadata(4); - $node5 = new ClassMetadata(5); + $node1 = new ClassMetadata('1'); + $node2 = new ClassMetadata('2'); + $node3 = new ClassMetadata('3'); + $node4 = new ClassMetadata('4'); + $node5 = new ClassMetadata('5'); $sorter->addNode('1', $node1); $sorter->addNode('2', $node2); @@ -52,11 +52,11 @@ public function testSuccessSortMultiDependency(): void { $sorter = new TopologicalSorter(); - $node1 = new ClassMetadata(1); - $node2 = new ClassMetadata(2); - $node3 = new ClassMetadata(3); - $node4 = new ClassMetadata(4); - $node5 = new ClassMetadata(5); + $node1 = new ClassMetadata('1'); + $node2 = new ClassMetadata('2'); + $node3 = new ClassMetadata('3'); + $node4 = new ClassMetadata('4'); + $node5 = new ClassMetadata('5'); $sorter->addNode('1', $node1); $sorter->addNode('2', $node2); @@ -80,9 +80,9 @@ public function testSortCyclicDependency(): void { $sorter = new TopologicalSorter(); - $node1 = new ClassMetadata(1); - $node2 = new ClassMetadata(2); - $node3 = new ClassMetadata(3); + $node1 = new ClassMetadata('1'); + $node2 = new ClassMetadata('2'); + $node3 = new ClassMetadata('3'); $sorter->addNode('1', $node1); $sorter->addNode('2', $node2); @@ -104,9 +104,9 @@ public function testFailureSortCyclicDependency(): void { $sorter = new TopologicalSorter(false); - $node1 = new ClassMetadata(1); - $node2 = new ClassMetadata(2); - $node3 = new ClassMetadata(3); + $node1 = new ClassMetadata('1'); + $node2 = new ClassMetadata('2'); + $node3 = new ClassMetadata('3'); $sorter->addNode('1', $node1); $sorter->addNode('2', $node2); @@ -125,11 +125,11 @@ public function testNoFailureOnSelfReferencingDependency(): void { $sorter = new TopologicalSorter(); - $node1 = new ClassMetadata(1); - $node2 = new ClassMetadata(2); - $node3 = new ClassMetadata(3); - $node4 = new ClassMetadata(4); - $node5 = new ClassMetadata(5); + $node1 = new ClassMetadata('1'); + $node2 = new ClassMetadata('2'); + $node3 = new ClassMetadata('3'); + $node4 = new ClassMetadata('4'); + $node5 = new ClassMetadata('5'); $sorter->addNode('1', $node1); $sorter->addNode('2', $node2); @@ -153,7 +153,7 @@ public function testFailureSortMissingDependency(): void { $sorter = new TopologicalSorter(); - $node1 = new ClassMetadata(1); + $node1 = new ClassMetadata('1'); $sorter->addNode('1', $node1); diff --git a/tests/Common/DataFixtures/TestEntity/Group.php b/tests/Common/DataFixtures/TestEntity/Group.php index b6c13cea..d960aeee 100644 --- a/tests/Common/DataFixtures/TestEntity/Group.php +++ b/tests/Common/DataFixtures/TestEntity/Group.php @@ -7,18 +7,23 @@ use Doctrine\ORM\Mapping as ORM; /** @ORM\Entity() */ +#[ORM\Entity] class Group { /** * @ORM\Column(type="integer") * @ORM\Id */ + #[ORM\Column] + #[ORM\Id] private ?int $id = null; /** * @ORM\Column(length=32) * @ORM\Id */ + #[ORM\Column(length: 32)] + #[ORM\Id] private ?string $code = null; public function setId(int $id): void diff --git a/tests/Common/DataFixtures/TestEntity/GroupWithSchema.php b/tests/Common/DataFixtures/TestEntity/GroupWithSchema.php index 77efcdb9..6a7b4e49 100644 --- a/tests/Common/DataFixtures/TestEntity/GroupWithSchema.php +++ b/tests/Common/DataFixtures/TestEntity/GroupWithSchema.php @@ -10,18 +10,24 @@ * @ORM\Entity() * @ORM\Table(name="group",schema="test_schema") */ +#[ORM\Entity] +#[ORM\Table(name: 'group', schema: 'test_schema')] class GroupWithSchema { /** * @ORM\Column(type="integer") * @ORM\Id */ + #[ORM\Column] + #[ORM\Id] private ?int $id = null; /** * @ORM\Column(length=32) * @ORM\Id */ + #[ORM\Column(length: 32)] + #[ORM\Id] private ?string $code = null; public function setId(int $id): void diff --git a/tests/Common/DataFixtures/TestEntity/Link.php b/tests/Common/DataFixtures/TestEntity/Link.php index ccde1d66..89549e7a 100644 --- a/tests/Common/DataFixtures/TestEntity/Link.php +++ b/tests/Common/DataFixtures/TestEntity/Link.php @@ -8,15 +8,19 @@ use Doctrine\Tests\Common\DataFixtures\TestValueObjects\Uuid; /** @ORM\Entity */ +#[ORM\Entity] class Link { /** * @ORM\Id * @ORM\Column(type="uuid") */ + #[ORM\Id] + #[ORM\Column(type: 'uuid')] private Uuid $id; /** @ORM\Column(length=150) */ + #[ORM\Column(length: 150)] private ?string $url = null; public function __construct(Uuid $id) diff --git a/tests/Common/DataFixtures/TestEntity/Quoted.php b/tests/Common/DataFixtures/TestEntity/Quoted.php index 4c4a6f58..57d1df23 100644 --- a/tests/Common/DataFixtures/TestEntity/Quoted.php +++ b/tests/Common/DataFixtures/TestEntity/Quoted.php @@ -11,6 +11,8 @@ * @ORM\Entity * @ORM\Table("`SELECT`") */ +#[ORM\Entity] +#[ORM\Table(name: '`SELECT`')] class Quoted { /** @@ -18,9 +20,13 @@ class Quoted * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ + #[ORM\Column] + #[ORM\Id] + #[ORM\GeneratedValue(strategy: 'IDENTITY')] private ?int $id = null; /** @ORM\Column(length=50, name="select") */ + #[ORM\Column(length: 50, name: '`SELECT`')] private ?string $select = null; /** @@ -29,9 +35,11 @@ class Quoted * joinColumns={@ORM\JoinColumn(name="`SELECT`", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="`UPDATE`", referencedColumnName="id")} * ) - * - * @var Collection|null */ + #[ORM\ManyToMany(targetEntity: self::class)] + #[ORM\JoinTable(name: '`INSERT`')] + #[ORM\JoinColumn(name: '`SELECT`', referencedColumnName: 'id')] + #[ORM\InverseJoinColumn(name: '`UPDATE`', referencedColumnName: 'id')] private ?Collection $selects = null; public function getId(): ?int @@ -54,13 +62,11 @@ public function setSelect(?string $select): void $this->select = $select; } - /** @return Collection|null */ public function getSelects(): ?Collection { return $this->selects; } - /** @param Collection|null $selects */ public function setSelects(?Collection $selects): void { $this->selects = $selects; diff --git a/tests/Common/DataFixtures/TestEntity/Role.php b/tests/Common/DataFixtures/TestEntity/Role.php index 1abed139..80b55db6 100644 --- a/tests/Common/DataFixtures/TestEntity/Role.php +++ b/tests/Common/DataFixtures/TestEntity/Role.php @@ -7,6 +7,7 @@ use Doctrine\ORM\Mapping as ORM; /** @ORM\Entity */ +#[ORM\Entity] class Role { /** @@ -14,9 +15,13 @@ class Role * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ + #[ORM\Column] + #[ORM\Id] + #[ORM\GeneratedValue(strategy: 'IDENTITY')] private ?int $id = null; /** @ORM\Column(length=50) */ + #[ORM\Column(length: 50)] private ?string $name = null; public function getId(): ?int diff --git a/tests/Common/DataFixtures/TestEntity/User.php b/tests/Common/DataFixtures/TestEntity/User.php index ced5cb9b..5e0a04fe 100644 --- a/tests/Common/DataFixtures/TestEntity/User.php +++ b/tests/Common/DataFixtures/TestEntity/User.php @@ -11,27 +11,35 @@ use function md5; /** @ORM\Entity */ +#[ORM\Entity] class User { /** * @ORM\Column(type="integer") * @ORM\Id */ + #[ORM\Column] + #[ORM\Id] private ?int $id = null; /** * @ORM\Column(length=32) * @ORM\Id */ + #[ORM\Column(length: 32)] + #[ORM\Id] private ?string $code = null; /** @ORM\Column(length=32) */ + #[ORM\Column(length: 32)] private ?string $password = null; /** @ORM\Column(length=255) */ + #[ORM\Column(length: 255)] private ?string $email = null; /** @ORM\ManyToOne(targetEntity=Role::class, cascade={"persist"}) */ + #[ORM\ManyToOne(cascade: ['persist'])] private ?Role $role = null; /** @@ -43,6 +51,10 @@ class User * * @var Collection */ + #[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'authors')] + #[ORM\JoinTable(name: 'author_reader', schema: 'readers')] + #[ORM\JoinColumn(name: 'author_id', referencedColumnName: 'id')] + #[ORM\InverseJoinColumn(name: 'reader_id', referencedColumnName: 'id')] private Collection $readers; /** @@ -50,6 +62,7 @@ class User * * @var Collection */ + #[ORM\ManyToMany(targetEntity: self::class, mappedBy: 'readers')] private Collection $authors; public function __construct() diff --git a/tests/Common/DataFixtures/TestEntity/UserWithSchema.php b/tests/Common/DataFixtures/TestEntity/UserWithSchema.php index f9e8a820..c6552f75 100644 --- a/tests/Common/DataFixtures/TestEntity/UserWithSchema.php +++ b/tests/Common/DataFixtures/TestEntity/UserWithSchema.php @@ -14,27 +14,36 @@ * @ORM\Entity * @ORM\Table(name="user",schema="test_schema") */ +#[ORM\Entity] +#[ORM\Table(name: 'user', schema: 'test_schema')] class UserWithSchema { /** * @ORM\Column(type="integer") * @ORM\Id */ + #[ORM\Column] + #[ORM\Id] private ?int $id = null; /** * @ORM\Column(length=32) * @ORM\Id */ + #[ORM\Column(length: 32)] + #[ORM\Id] private ?string $code = null; /** @ORM\Column(length=32) */ + #[ORM\Column(length: 32)] private ?string $password = null; /** @ORM\Column(length=255) */ + #[ORM\Column(length: 255)] private ?string $email = null; /** @ORM\ManyToOne(targetEntity=Role::class, cascade={"persist"}) */ + #[ORM\ManyToOne(cascade: ['persist'])] private ?Role $role = null; /** @@ -46,6 +55,10 @@ class UserWithSchema * * @var Collection */ + #[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'authors')] + #[ORM\JoinTable(name: 'author_reader', schema: 'readers')] + #[ORM\JoinColumn(name: 'author_id', referencedColumnName: 'id')] + #[ORM\InverseJoinColumn(name: 'reader_id', referencedColumnName: 'id')] private Collection $readers; /** @@ -53,6 +66,7 @@ class UserWithSchema * * @var Collection */ + #[ORM\ManyToMany(targetEntity: self::class, mappedBy: 'readers')] private Collection $authors; public function __construct() diff --git a/tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php b/tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php index 5ee28a82..9871ae0a 100644 --- a/tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php +++ b/tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php @@ -7,12 +7,15 @@ use Doctrine\ORM\Mapping as ORM; /** @ORM\Entity */ +#[ORM\Entity] class ExcludedEntity { /** * @ORM\Column(type="integer") * @ORM\Id */ + #[ORM\Column] + #[ORM\Id] private ?int $id = null; public function setId(int $id): void diff --git a/tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php b/tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php index 96eb1af9..9352272a 100644 --- a/tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php +++ b/tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php @@ -7,12 +7,15 @@ use Doctrine\ORM\Mapping as ORM; /** @ORM\Entity */ +#[ORM\Entity] class IncludedEntity { /** * @ORM\Column(type="integer") * @ORM\Id */ + #[ORM\Column] + #[ORM\Id] private ?int $id = null; public function setId(int $id): void diff --git a/tests/Common/DataFixtures/TestTypes/UuidType.php b/tests/Common/DataFixtures/TestTypes/UuidType.php index 26f1bddb..cdf725ea 100644 --- a/tests/Common/DataFixtures/TestTypes/UuidType.php +++ b/tests/Common/DataFixtures/TestTypes/UuidType.php @@ -18,7 +18,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla $fieldDeclaration['length'] = 36; $fieldDeclaration['fixed'] = true; - return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); + return $platform->getStringTypeDeclarationSQL($fieldDeclaration); } /** @param string|null $value */ diff --git a/tests/Mock/ForwardCompatibleEntityManager.php b/tests/Mock/ForwardCompatibleEntityManager.php new file mode 100644 index 00000000..911763de --- /dev/null +++ b/tests/Mock/ForwardCompatibleEntityManager.php @@ -0,0 +1,21 @@ +