diff --git a/.doctrine-project.json b/.doctrine-project.json index 1d51fa3..f24e1a0 100644 --- a/.doctrine-project.json +++ b/.doctrine-project.json @@ -10,17 +10,23 @@ "slug": "latest", "upcoming": true }, + { + "name": "2.2", + "branchName": "2.2.x", + "slug": "2.2", + "upcoming": true + }, { "name": "2.1", "branchName": "2.1.x", "slug": "2.1", - "upcoming": true + "current": true }, { "name": "2.0", "branchName": "2.0.x", "slug": "2.0", - "current": true + "maintained": false }, { "name": "1.8", diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index e57b10f..265d106 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -11,4 +11,4 @@ on: jobs: coding-standards: name: "Coding Standards" - uses: "doctrine/.github/.github/workflows/coding-standards.yml@7.3.0" + uses: "doctrine/.github/.github/workflows/coding-standards.yml@10.1.0" diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 71f7eb6..9734c20 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -17,4 +17,4 @@ on: jobs: documentation: name: "Documentation" - uses: "doctrine/.github/.github/workflows/documentation.yml@7.3.0" + uses: "doctrine/.github/.github/workflows/documentation.yml@10.1.0" diff --git a/.github/workflows/release-on-milestone-closed.yml b/.github/workflows/release-on-milestone-closed.yml index 951002c..f660801 100644 --- a/.github/workflows/release-on-milestone-closed.yml +++ b/.github/workflows/release-on-milestone-closed.yml @@ -8,7 +8,7 @@ on: jobs: release: name: "Git tag, release & create merge-up PR" - uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@7.3.0" + uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@10.1.0" secrets: GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }} GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }} diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index aa1f8d6..bf93f48 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -11,4 +11,4 @@ on: jobs: static-analysis: name: "Static Analysis" - uses: "doctrine/.github/.github/workflows/phpstan.yml@7.3.0" + uses: "doctrine/.github/.github/workflows/phpstan.yml@10.1.0" diff --git a/composer.json b/composer.json index 959e88b..2d15bdb 100644 --- a/composer.json +++ b/composer.json @@ -25,13 +25,13 @@ }, "require-dev": { "ext-sqlite3": "*", - "doctrine/coding-standard": "^13", + "doctrine/coding-standard": "^14", "doctrine/dbal": "^3.5 || ^4", "doctrine/mongodb-odm": "^1.3.0 || ^2.0.0", "doctrine/orm": "^2.14 || ^3", "fig/log-test": "^1", - "phpstan/phpstan": "2.1.22", - "phpunit/phpunit": "10.5.45", + "phpstan/phpstan": "2.1.31", + "phpunit/phpunit": "10.5.45 || 12.4.0", "symfony/cache": "^6.4 || ^7", "symfony/var-exporter": "^6.4 || ^7" }, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0079aeb..468de3e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -270,6 +270,12 @@ parameters: count: 1 path: src/Sorter/Vertex.php + - + message: '#^Call to function method_exists\(\) with ''Doctrine\\\\ORM\\\\ORMSetup'' and ''createAttributeMeta…'' will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType + count: 1 + path: tests/Common/DataFixtures/BaseTestCase.php + - message: '#^Method Doctrine\\Tests\\Common\\DataFixtures\\FixtureWithUnexistentDependency\:\:getDependencies\(\) should return array\\> but returns array\\.$#' identifier: return.type @@ -277,19 +283,7 @@ parameters: path: tests/Common/DataFixtures/DependentFixtureTest.php - - message: '#^Call to method expects\(\) on an unknown class Doctrine\\ODM\\PHPCR\\DocumentManager\.$#' - identifier: class.notFound - count: 5 - path: tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php - - - - message: '#^Method Doctrine\\Tests\\Common\\DataFixtures\\Executor\\PHPCRExecutorTest\:\:getDocumentManager\(\) has invalid return type Doctrine\\ODM\\PHPCR\\DocumentManager\.$#' - identifier: class.notFound - count: 1 - path: tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php - - - - message: '#^Parameter \#1 \$dm of class Doctrine\\Common\\DataFixtures\\Executor\\PHPCRExecutor constructor expects Doctrine\\ODM\\PHPCR\\DocumentManagerInterface, Doctrine\\ODM\\PHPCR\\DocumentManager&PHPUnit\\Framework\\MockObject\\MockObject given\.$#' + message: '#^Parameter \#1 \$dm of class Doctrine\\Common\\DataFixtures\\Executor\\PHPCRExecutor constructor expects Doctrine\\ODM\\PHPCR\\DocumentManagerInterface, Doctrine\\Tests\\Mock\\PHPCRDocumentManager&PHPUnit\\Framework\\MockObject\\MockObject given\.$#' identifier: argument.type count: 5 path: tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -300,6 +294,12 @@ parameters: count: 3 path: tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php + - + message: '#^Call to function method_exists\(\) with ''Doctrine\\\\ORM\\\\ORMSetup'' and ''createAttributeMeta…'' will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType + count: 2 + path: tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php + - message: '#^Call to an undefined method Doctrine\\ODM\\MongoDB\\DocumentManager\:\:getConnection\(\)\.$#' identifier: method.notFound @@ -312,6 +312,12 @@ parameters: count: 1 path: tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php + - + message: '#^Call to function method_exists\(\) with ''Doctrine\\\\ORM\\\\ORMSetup'' and ''createAttributeMeta…'' will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType + count: 2 + path: tests/Common/DataFixtures/ReferenceRepositoryTest.php + - message: '#^Parameter \#1 \$name of class Doctrine\\ORM\\Mapping\\ClassMetadata constructor expects class\-string\<1\>, string given\.$#' identifier: argument.type diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9e2aa0e..6cd8ddc 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,11 +1,12 @@ parameters: - phpVersion: 80200 + phpVersion: 80400 level: 7 paths: - src - tests excludePaths: - tests/Mock/ForwardCompatibleEntityManager.php + - tests/Mock/PHPCRDocumentManager.php includes: - phpstan-baseline.neon diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9374ffb..6c549ed 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,8 +3,8 @@ xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" colors="true" beStrictAboutOutputDuringTests="true" - beStrictAboutTodoAnnotatedTests="true" - bootstrap="vendor/autoload.php" + displayDetailsOnTestsThatTriggerDeprecations="true" + failOnDeprecation="true" > @@ -12,9 +12,13 @@ - + + + + + - ./src + ./src/ - + diff --git a/src/Purger/ORMPurger.php b/src/Purger/ORMPurger.php index 8733a70..3d3565e 100644 --- a/src/Purger/ORMPurger.php +++ b/src/Purger/ORMPurger.php @@ -6,6 +6,7 @@ namespace Doctrine\Common\DataFixtures\Purger; use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Schema\AbstractNamedObject; use Doctrine\DBAL\Schema\Identifier; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; @@ -13,6 +14,7 @@ use Doctrine\ORM\Mapping\ManyToManyOwningSideMapping; use function array_map; use function array_reverse; +use function class_exists; use function count; use function in_array; @@ -253,6 +255,12 @@ final class ORMPurger implements ORMPurgerInterface { $tableIdentifier = new Identifier($tableName); - return 'DELETE FROM ' . $tableIdentifier->getQuotedName($platform); + if (class_exists(AbstractNamedObject::class)) { + $identifier = $tableIdentifier->getObjectName()->toSQL($platform); + } else { + $identifier = $tableIdentifier->getQuotedName($platform); + } + + return 'DELETE FROM ' . $identifier; } } diff --git a/src/ReferenceRepository.php b/src/ReferenceRepository.php index a0ed7ef..5747f48 100644 --- a/src/ReferenceRepository.php +++ b/src/ReferenceRepository.php @@ -116,7 +116,7 @@ class ReferenceRepository * not be set yet * * Notice: in case if identifier is generated after - * the record is inserted, be sure tu use this method + * the record is inserted, be sure to use this method * after $object is flushed * * @param object $object - managed object diff --git a/tests/Common/DataFixtures/BaseTestCase.php b/tests/Common/DataFixtures/BaseTestCase.php index 86c7b88..1dd2bf3 100644 --- a/tests/Common/DataFixtures/BaseTestCase.php +++ b/tests/Common/DataFixtures/BaseTestCase.php @@ -11,9 +11,8 @@ use PHPUnit\Framework\TestCase; use function method_exists; -/** - * Base test class - */ +use const PHP_VERSION_ID; + abstract class BaseTestCase extends TestCase { /** @@ -24,8 +23,13 @@ abstract class BaseTestCase extends TestCase protected function getMockSqliteEntityManager(string $fixtureSet = 'TestEntity'): EntityManager { $dbParams = ['driver' => 'sqlite3', 'memory' => true]; - $config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/' . $fixtureSet], true); - $config->setLazyGhostObjectEnabled(true); + if (PHP_VERSION_ID >= 80400 && method_exists(ORMSetup::class, 'createAttributeMetadataConfig')) { + $config = ORMSetup::createAttributeMetadataConfig([__DIR__ . '/' . $fixtureSet], true); + $config->enableNativeLazyObjects(true); + } else { + $config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/' . $fixtureSet], true); + $config->setLazyGhostObjectEnabled(true); + } $connection = DriverManager::getConnection($dbParams, $config); $platform = $connection->getDatabasePlatform(); diff --git a/tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php b/tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php index 78b8db5..de94b9b 100644 --- a/tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php +++ b/tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php @@ -10,6 +10,7 @@ use Doctrine\Common\DataFixtures\SharedFixtureInterface; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\Common\DataFixtures\TestEntity\Role; use Doctrine\Tests\Common\DataFixtures\TestEntity\User; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\MockObject\MockObject; /** @@ -20,6 +21,7 @@ class ORMExecutorSharedFixtureTest extends BaseTestCase public const TEST_ENTITY_ROLE = Role::class; public const TEST_ENTITY_USER = User::class; + #[IgnoreDeprecations] public function testFixtureExecution(): void { $em = $this->getMockSqliteEntityManager(); @@ -39,6 +41,7 @@ class ORMExecutorSharedFixtureTest extends BaseTestCase $executor->execute([$fixture], true); } + #[IgnoreDeprecations] public function testSharedFixtures(): void { $em = $this->getMockSqliteEntityManager(); diff --git a/tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index 563a8b5..62f1b3d 100644 --- a/tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -9,17 +9,15 @@ use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\DataFixtures\Purger\PHPCRPurgerInterface; use Doctrine\ODM\PHPCR\DocumentManager; use Doctrine\Tests\Common\DataFixtures\BaseTestCase; +use Doctrine\Tests\Mock\PHPCRDocumentManager; use Exception; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use Throwable; use function class_exists; -/** - * Tests for {@see \Doctrine\Common\DataFixtures\Executor\PHPCRExecutor} - * - * @covers \Doctrine\Common\DataFixtures\Executor\PHPCRExecutor - */ +#[CoversClass(PHPCRExecutor::class)] class PHPCRExecutorTest extends BaseTestCase { public function testExecuteSingleFixtureWithNoPurge(): void @@ -33,9 +31,9 @@ class PHPCRExecutorTest extends BaseTestCase ->expects($this->once()) ->method('transactional') ->with($this->isType('callable')) - ->will($this->returnCallback(static function ($callback) use ($dm) { + ->willReturnCallback(static function ($callback) use ($dm) { return $callback($dm); - })); + }); $executor->execute([$fixture], true); } @@ -53,9 +51,9 @@ class PHPCRExecutorTest extends BaseTestCase ->expects($this->once()) ->method('transactional') ->with($this->isType('callable')) - ->will($this->returnCallback(static function ($callback) use ($dm) { + ->willReturnCallback(static function ($callback) use ($dm) { return $callback($dm); - })); + }); $executor->execute([$fixture1, $fixture2], true); } @@ -72,9 +70,9 @@ class PHPCRExecutorTest extends BaseTestCase ->expects($this->once()) ->method('transactional') ->with($this->isType('callable')) - ->will($this->returnCallback(static function ($callback) use ($dm) { + ->willReturnCallback(static function ($callback) use ($dm) { return $callback($dm); - })); + }); $purger->expects($this->once())->method('purge'); $executor->execute([$fixture], false); @@ -92,9 +90,9 @@ class PHPCRExecutorTest extends BaseTestCase ->expects($this->once()) ->method('transactional') ->with($this->isType('callable')) - ->will($this->returnCallback(static function ($callback) use ($dm) { + ->willReturnCallback(static function ($callback) use ($dm) { return $callback($dm); - })); + }); $purger->expects($this->never())->method('purge'); $executor->execute([$fixture], true); @@ -124,19 +122,14 @@ class PHPCRExecutorTest extends BaseTestCase return $this->createMock(PHPCRPurgerInterface::class); } - private function getDocumentManager(): DocumentManager&MockObject + private function getDocumentManager(): PHPCRDocumentManager&MockObject { if (! class_exists(DocumentManager::class)) { $this->markTestSkipped('Missing doctrine/phpcr-odm'); } return $this - ->getMockBuilder(DocumentManager::class) - ->addMethods([ - 'transactional', - 'flush', - 'clear', - ]) + ->getMockBuilder(PHPCRDocumentManager::class) ->disableOriginalConstructor() ->getMock(); } diff --git a/tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php b/tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php index dd5a8f9..9c77e2e 100644 --- a/tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php +++ b/tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php @@ -7,16 +7,20 @@ namespace Doctrine\Tests\Common\DataFixtures; use Doctrine\Common\DataFixtures\Event\Listener\ORMReferenceListener; use Doctrine\Common\DataFixtures\ProxyReferenceRepository; use Doctrine\DBAL\Types\Type; +use Doctrine\ORM\ORMSetup; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Persistence\Proxy; use Doctrine\Tests\Common\DataFixtures\TestEntity\Link; use Doctrine\Tests\Common\DataFixtures\TestEntity\Role; use Doctrine\Tests\Common\DataFixtures\TestTypes\UuidType; use Doctrine\Tests\Common\DataFixtures\TestValueObjects\Uuid; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; +use ReflectionClass; + +use function method_exists; + +use const PHP_VERSION_ID; -/** - * Test ProxyReferenceRepository. - */ class ProxyReferenceRepositoryTest extends BaseTestCase { public const TEST_ENTITY_ROLE = Role::class; @@ -33,12 +37,15 @@ class ProxyReferenceRepositoryTest extends BaseTestCase Type::addType('uuid', UuidType::class); } + #[IgnoreDeprecations] public function testReferenceEntry(): void { $em = $this->getMockSqliteEntityManager(); $role = new TestEntity\Role(); $role->setName('admin'); $meta = $em->getClassMetadata(self::TEST_ENTITY_ROLE); + + // getPropertyAccessor() is not available with ORM < 3.4 $meta->getReflectionProperty('id')->setValue($role, 1); $referenceRepo = new ProxyReferenceRepository($em); @@ -72,7 +79,7 @@ class ProxyReferenceRepositoryTest extends BaseTestCase $referenceRepository->expects($this->once()) ->method('getReferenceNames') - ->will($this->returnValue(['admin-role'])); + ->willReturn(['admin-role']); $referenceRepository->expects($this->once()) ->method('setReferenceIdentity') @@ -100,7 +107,7 @@ class ProxyReferenceRepositoryTest extends BaseTestCase // first test against managed state $ref = $referenceRepository->getReference('admin-role', Role::class); - $this->assertNotInstanceOf(Proxy::class, $ref); + $this->assertNotProxy($ref); // test reference reconstruction from serialized data (was managed) $serializedData = $referenceRepository->serialize(); @@ -111,14 +118,14 @@ class ProxyReferenceRepositoryTest extends BaseTestCase $ref = $proxyReferenceRepository->getReference('admin-role', Role::class); // before clearing, the reference is not yet a proxy - $this->assertNotInstanceOf(Proxy::class, $ref); + $this->assertNotProxy($ref); $this->assertInstanceOf(self::TEST_ENTITY_ROLE, $ref); // now test reference reconstruction from identity $em->clear(); $ref = $referenceRepository->getReference('admin-role', Role::class); - $this->assertInstanceOf(Proxy::class, $ref); + $this->assertProxy($ref); // test reference reconstruction from serialized data (was identity) $serializedData = $referenceRepository->serialize(); @@ -128,9 +135,10 @@ class ProxyReferenceRepositoryTest extends BaseTestCase $ref = $proxyReferenceRepository->getReference('admin-role', Role::class); - $this->assertInstanceOf(Proxy::class, $ref); + $this->assertProxy($ref); } + #[IgnoreDeprecations] public function testReconstructionOfCustomTypedId(): void { $em = $this->getMockSqliteEntityManager(); @@ -177,7 +185,31 @@ class ProxyReferenceRepositoryTest extends BaseTestCase $em->flush(); $em->clear(); - $this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('admin', Role::class)); - $this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('duplicate', Role::class)); + $this->assertProxy($referenceRepository->getReference('admin', Role::class)); + $this->assertProxy($referenceRepository->getReference('duplicate', Role::class)); + } + + private function assertProxy(object $object): void + { + if (PHP_VERSION_ID < 80400 || ! method_exists(ORMSetup::class, 'createAttributeMetadataConfig')) { + $this->assertInstanceOf(Proxy::class, $object); + + return; + } + + $reflector = new ReflectionClass($object); + $this->assertTrue($reflector->isUninitializedLazyObject($object)); + } + + private function assertNotProxy(object $object): void + { + if (PHP_VERSION_ID < 80400 || ! method_exists(ORMSetup::class, 'createAttributeMetadataConfig')) { + $this->assertNotInstanceOf(Proxy::class, $object); + + return; + } + + $reflector = new ReflectionClass($object); + $this->assertFalse($reflector->isUninitializedLazyObject($object)); } } diff --git a/tests/Common/DataFixtures/Purger/ORMPurgerTest.php b/tests/Common/DataFixtures/Purger/ORMPurgerTest.php index 442948f..8334710 100644 --- a/tests/Common/DataFixtures/Purger/ORMPurgerTest.php +++ b/tests/Common/DataFixtures/Purger/ORMPurgerTest.php @@ -5,8 +5,11 @@ declare(strict_types=1); namespace Doctrine\Tests\Common\DataFixtures; use Doctrine\Common\DataFixtures\Purger\ORMPurger; +use Doctrine\DBAL\Schema\AbstractNamedObject; use ReflectionClass; +use function class_exists; + /** * Doctrine\Tests\Common\DataFixtures\ORMPurgerTest */ @@ -86,6 +89,11 @@ class ORMPurgerTest extends BaseTestCase $method = $class->getMethod('getDeleteFromTableSQL'); $method->setAccessible(true); $sql = $method->invokeArgs($purger, [$tableName, $platform]); - $this->assertEquals('DELETE FROM test_schema."group"', $sql); + + if (class_exists(AbstractNamedObject::class)) { + $this->assertEquals('DELETE FROM "test_schema"."group"', $sql); + } else { + $this->assertEquals('DELETE FROM test_schema."group"', $sql); + } } } diff --git a/tests/Common/DataFixtures/ReferenceRepositoryTest.php b/tests/Common/DataFixtures/ReferenceRepositoryTest.php index 0e5e56a..7b126f9 100644 --- a/tests/Common/DataFixtures/ReferenceRepositoryTest.php +++ b/tests/Common/DataFixtures/ReferenceRepositoryTest.php @@ -8,6 +8,7 @@ use BadMethodCallException; use Doctrine\Common\DataFixtures\Event\Listener\ORMReferenceListener; use Doctrine\Common\DataFixtures\ReferenceRepository; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\ORMSetup; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\UnitOfWork; use Doctrine\Persistence\Proxy; @@ -15,11 +16,17 @@ use Doctrine\Tests\Common\DataFixtures\TestEntity\Role; use Doctrine\Tests\Common\DataFixtures\TestEntity\User; use Doctrine\Tests\Mock\ForwardCompatibleEntityManager; use OutOfBoundsException; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; +use ReflectionClass; +use function method_exists; use function sprintf; +use const PHP_VERSION_ID; + class ReferenceRepositoryTest extends BaseTestCase { + #[IgnoreDeprecations] public function testReferenceEntry(): void { $em = $this->getMockSqliteEntityManager(); @@ -91,13 +98,13 @@ class ReferenceRepositoryTest extends BaseTestCase // first test against managed state $ref = $referenceRepository->getReference('admin-role', Role::class); - $this->assertNotInstanceOf(Proxy::class, $ref); + $this->assertNotProxy($ref); // now test reference reconstruction from identity $em->clear(); $ref = $referenceRepository->getReference('admin-role', Role::class); - $this->assertInstanceOf(Proxy::class, $ref); + $this->assertProxy($ref); } public function testReferenceMultipleEntries(): void @@ -117,8 +124,8 @@ class ReferenceRepositoryTest extends BaseTestCase $em->flush(); $em->clear(); - $this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('admin', Role::class)); - $this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('duplicate', Role::class)); + $this->assertProxy($referenceRepository->getReference('admin', Role::class)); + $this->assertProxy($referenceRepository->getReference('duplicate', Role::class)); } public function testUndefinedReference(): void @@ -131,7 +138,7 @@ class ReferenceRepositoryTest extends BaseTestCase $referenceRepository->getReference('foo', Role::class); } - /** @group legacy */ + #[IgnoreDeprecations] public function testLegacyUndefinedReference(): void { $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); @@ -263,4 +270,28 @@ class ReferenceRepositoryTest extends BaseTestCase $this->assertCount(1, $names); $this->assertSame('1', $names[0]); } + + private function assertProxy(object $object): void + { + if (PHP_VERSION_ID < 80400 || ! method_exists(ORMSetup::class, 'createAttributeMetadataConfig')) { + $this->assertInstanceOf(Proxy::class, $object); + + return; + } + + $reflector = new ReflectionClass($object); + $this->assertTrue($reflector->isUninitializedLazyObject($object)); + } + + private function assertNotProxy(object $object): void + { + if (PHP_VERSION_ID < 80400 || ! method_exists(ORMSetup::class, 'createAttributeMetadataConfig')) { + $this->assertNotInstanceOf(Proxy::class, $object); + + return; + } + + $reflector = new ReflectionClass($object); + $this->assertFalse($reflector->isUninitializedLazyObject($object)); + } } diff --git a/tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index 1a1f8c2..9e73acc 100644 --- a/tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -8,6 +8,7 @@ use Doctrine\Common\DataFixtures\Exception\CircularReferenceException; use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Tests\Common\DataFixtures\BaseTestCase; +use PHPUnit\Framework\Attributes\CoversClass; use RuntimeException; /** @@ -16,9 +17,8 @@ use RuntimeException; * Note: When writing tests here consider that a lot of graph * constellations can have many valid orderings, so you may want to * build a graph that has only 1 valid order to simplify your tests - * - * @covers \Doctrine\Common\DataFixtures\Sorter\TopologicalSorter */ +#[CoversClass(TopologicalSorter::class)] class TopologicalSorterTest extends BaseTestCase { public function testSuccessSortLinearDependency(): void diff --git a/tests/Common/DataFixtures/Sorter/VertexTest.php b/tests/Common/DataFixtures/Sorter/VertexTest.php index 1f85652..82f8c21 100644 --- a/tests/Common/DataFixtures/Sorter/VertexTest.php +++ b/tests/Common/DataFixtures/Sorter/VertexTest.php @@ -7,8 +7,9 @@ namespace Doctrine\Test\DataFixtures\Sorter; use Doctrine\Common\DataFixtures\Sorter\Vertex; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Tests\Common\DataFixtures\BaseTestCase; +use PHPUnit\Framework\Attributes\CoversClass; -/** @covers \Doctrine\Common\DataFixtures\Sorter\Vertex */ +#[CoversClass(Vertex::class)] class VertexTest extends BaseTestCase { public function testNode(): void diff --git a/tests/Mock/PHPCRDocumentManager.php b/tests/Mock/PHPCRDocumentManager.php new file mode 100644 index 0000000..fdbb692 --- /dev/null +++ b/tests/Mock/PHPCRDocumentManager.php @@ -0,0 +1,13 @@ +