Skip to content

Commit

Permalink
Fix test using SearchHandler object
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Dec 15, 2020
1 parent b8603a6 commit ce892c9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tests/Block/AdminSearchBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Block\AdminSearchBlockService;
use Sonata\AdminBundle\Datagrid\DatagridInterface;
use Sonata\AdminBundle\Datagrid\PagerInterface;
use Sonata\AdminBundle\Filter\FilterInterface;
use Sonata\AdminBundle\Search\SearchHandler;
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
use Sonata\BlockBundle\Test\BlockServiceTestCase;
Expand Down Expand Up @@ -74,8 +76,26 @@ public function testDefaultSettings(): void

public function testGlobalSearchReturnsResponse(): void
{
$datagrid = $this->createStub(DatagridInterface::class);

$admin = $this->createMock(AbstractAdmin::class);
$pagerInterface = $this->createMock(PagerInterface::class);
$admin
->method('getDatagrid')
->willReturn($datagrid);

$filter = $this->createStub(FilterInterface::class);
$filter
->method('getOption')
->with('global_search')
->willReturn(true);

$datagrid
->method('getFilters')
->willReturn([$filter]);

$datagrid
->method('getPager')
->willReturn($this->createStub(PagerInterface::class));

$blockService = new AdminSearchBlockService(
$this->twig,
Expand All @@ -86,7 +106,6 @@ public function testGlobalSearchReturnsResponse(): void
);
$blockContext = $this->getBlockContext($blockService);

$this->searchHandler->expects(self::once())->method('search')->willReturn($pagerInterface);
$this->pool->expects(self::once())->method('getAdminByAdminCode')->willReturn($admin);
$admin->expects(self::once())->method('checkAccess')->with('list');

Expand Down

0 comments on commit ce892c9

Please sign in to comment.