Skip to content

Commit

Permalink
admin value resolver accept generat AdminInterface type
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Jun 15, 2022
1 parent 6d460d3 commit 83acf10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ArgumentResolver/AdminValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public function __construct(AdminFetcherInterface $adminFetcher)
public function supports(Request $request, ArgumentMetadata $argument): bool
{
$type = $argument->getType();
if (null === $type || !is_subclass_of($type, AdminInterface::class)) {

if (null === $type) {
return false;
}

if (AdminInterface::class !== $type && !is_subclass_of($type, AdminInterface::class)) {
return false;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/ArgumentResolver/AdminValueResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sonata\AdminBundle\Tests\ArgumentResolver;

use PHPUnit\Framework\TestCase;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\ArgumentResolver\AdminValueResolver;
use Sonata\AdminBundle\Request\AdminFetcher;
Expand Down Expand Up @@ -93,6 +94,12 @@ public function supportDataProvider(): iterable
$request,
new ArgumentMetadata('_sonata_admin', PostAdmin::class, false, false, null),
];

yield 'Admin can fetch by interface' => [
true,
$request,
new ArgumentMetadata('_sonata_admin', AdminInterface::class, false, false, null),
];
}

public function testResolveAdmin(): void
Expand Down

0 comments on commit 83acf10

Please sign in to comment.