Skip to content

Commit

Permalink
Merge f4580c0 into 195ff52
Browse files Browse the repository at this point in the history
  • Loading branch information
jotwea committed Apr 15, 2024
2 parents 195ff52 + f4580c0 commit df072a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/GraphQl/State/Provider/ResolverProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private function getResourceClass(?object $item, ?string $resourceClass, string
return $itemClass;
}

if ($resourceClass !== $itemClass) {
if ($resourceClass !== $itemClass && !$item instanceof $resourceClass) {
throw new \UnexpectedValueException(sprintf($errorMessage, (new \ReflectionClass($resourceClass))->getShortName(), (new \ReflectionClass($itemClass))->getShortName()));
}

Expand Down
17 changes: 17 additions & 0 deletions src/GraphQl/Tests/State/Provider/ResolverProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

use ApiPlatform\GraphQl\Resolver\QueryItemResolverInterface;
use ApiPlatform\GraphQl\State\Provider\ResolverProvider;
use ApiPlatform\GraphQl\Tests\Fixtures\ApiResource\ChildFoo;
use ApiPlatform\GraphQl\Tests\Fixtures\ApiResource\ParentFoo;
use ApiPlatform\Metadata\GraphQl\Query;
use ApiPlatform\Metadata\GraphQl\QueryCollection;
use ApiPlatform\State\ProviderInterface;
use PHPUnit\Framework\TestCase;
Expand All @@ -35,4 +38,18 @@ public function testProvide(): void
$provider = new ResolverProvider($decorated, $resolverLocator);
$this->assertEquals($res, $provider->provide($operation, [], $context));
}

public function testProvideInheritedClass(): void
{
$res = new ChildFoo();
$operation = new Query(class: ParentFoo::class, resolver: 'foo');
$context = [];
$decorated = $this->createMock(ProviderInterface::class);
$resolverMock = $this->createMock(QueryItemResolverInterface::class);
$resolverMock->expects($this->once())->method('__invoke')->willReturn($res);
$resolverLocator = $this->createMock(ContainerInterface::class);
$resolverLocator->expects($this->once())->method('get')->with('foo')->willReturn($resolverMock);
$provider = new ResolverProvider($decorated, $resolverLocator);
$this->assertEquals($res, $provider->provide($operation, [], $context));
}
}

0 comments on commit df072a4

Please sign in to comment.