diff --git a/composer.json b/composer.json index a8e139f..126ffba 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "require": { "php": "^8.4", - "doctrine/orm": "^3.6", - "doctrine/doctrine-laminas-hydrator": "^3.7", + "doctrine/orm": "^2.20.9 || ^3.0", + "doctrine/doctrine-laminas-hydrator": "^3.2", "webonyx/graphql-php": "^v15.29", "psr/container": "^2.0", "league/event": "^3.0", @@ -20,12 +20,20 @@ }, "require-dev": { "doctrine/coding-standard": "^14.0", - "doctrine/dbal": "^4.0", + "doctrine/dbal": "^3.1 || ^4.0", "phpunit/phpunit": "^13.0", - "vimeo/psalm": "^6.14", + "vimeo/psalm": "^6.16.1", "symfony/cache": "^7.0 || ^8.0", - "php-parallel-lint/php-parallel-lint": "^1.3.2", - "phpstan/phpstan": "^2.1" + "php-parallel-lint/php-parallel-lint": "^1.4", + "phpstan/phpstan": "^2.1.51", + "amphp/dns": "^v2.4", + "amphp/socket": "^v2.4", + "amphp/cache": "^v2.0.1", + "amphp/parser": "^v1.1.1", + "amphp/process": "^v2.0.3", + "symfony/console": "^8.0", + "spatie/array-to-xml": "^3.4.4", + "daverandom/libdns": "^2.1" }, "suggest": { "ramsey/uuid-doctrine": "Support for an UUID Doctrine type" diff --git a/test/TestCase.php b/test/TestCase.php index 4f1eeaa..a339ade 100644 --- a/test/TestCase.php +++ b/test/TestCase.php @@ -15,6 +15,7 @@ use function count; use function date; use function file_get_contents; +use function method_exists; require_once __DIR__ . '/../vendor/autoload.php'; @@ -29,7 +30,9 @@ public function setUp(): void paths: [__DIR__ . '/Entity'], isDevMode: true, ); - $config->enableNativeLazyObjects(true); + if (method_exists($config, 'enableNativeLazyObjects')) { + $config->enableNativeLazyObjects(true); + } // database connection $connection = DriverManager::getConnection([ diff --git a/test/Unit/Hydrator/DoctrineObjectWithComputedTest.php b/test/Unit/Hydrator/DoctrineObjectWithComputedTest.php index 19257b4..68b679f 100644 --- a/test/Unit/Hydrator/DoctrineObjectWithComputedTest.php +++ b/test/Unit/Hydrator/DoctrineObjectWithComputedTest.php @@ -5,9 +5,8 @@ namespace ApiSkeletonsTest\Doctrine\ORM\GraphQL\Unit\Hydrator; use ApiSkeletons\Doctrine\ORM\GraphQL\Hydrator\DoctrineObjectWithComputed; -use Doctrine\ORM\EntityManager; -use PHPUnit\Framework\TestCase; -use stdClass; +use ApiSkeletonsTest\Doctrine\ORM\GraphQL\Entity\Artist; +use ApiSkeletonsTest\Doctrine\ORM\GraphQL\TestCase; use function strlen; use function strtoupper; @@ -16,13 +15,11 @@ class DoctrineObjectWithComputedTest extends TestCase { private DoctrineObjectWithComputed $hydrator; - protected function setUp(): void + public function setUp(): void { - // Create a stub entity manager for testing (not used by the hydrator methods we're testing) - $entityManager = $this->createStub(EntityManager::class); + parent::setUp(); - // DoctrineObjectWithComputed extends DoctrineObject which takes EntityManager and byValue flag - $this->hydrator = new DoctrineObjectWithComputed($entityManager, false); + $this->hydrator = new DoctrineObjectWithComputed($this->getEntityManager(), false); } public function testHasComputedFieldReturnsFalseWhenNotRegistered(): void @@ -58,19 +55,19 @@ public function testGetComputedFieldNamesReturnsAllRegisteredFields(): void public function testExtractIncludesComputedFields(): void { - $entity = new stdClass(); - $entity->name = 'Test Name'; + $artist = $this->getEntityManager() + ->getRepository(Artist::class) + ->findOneBy(['name' => 'Grateful Dead']); - // Add computed field that transforms the name - $this->hydrator->addComputedField('uppercaseName', static fn ($obj) => strtoupper($obj->name)); - $this->hydrator->addComputedField('nameLength', static fn ($obj) => strlen($obj->name)); + $this->hydrator->addComputedField('uppercaseName', static fn ($obj) => strtoupper($obj->getName())); + $this->hydrator->addComputedField('nameLength', static fn ($obj) => strlen($obj->getName())); - $result = $this->hydrator->extract($entity); + $result = $this->hydrator->extract($artist); $this->assertArrayHasKey('uppercaseName', $result); $this->assertArrayHasKey('nameLength', $result); - $this->assertEquals('TEST NAME', $result['uppercaseName']); - $this->assertEquals(9, $result['nameLength']); + $this->assertEquals('GRATEFUL DEAD', $result['uppercaseName']); + $this->assertEquals(13, $result['nameLength']); } public function testAddComputedFieldAllowsMultipleFields(): void