Completed
Push — 3.x ( b75183...b1c847 )
by Oskar
04:45
created

tests/Block/AdminSearchBlockServiceTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Block;
15
16
use Sonata\AdminBundle\Admin\AbstractAdmin;
17
use Sonata\AdminBundle\Admin\Pool;
18
use Sonata\AdminBundle\Block\AdminSearchBlockService;
19
use Sonata\AdminBundle\Search\SearchHandler;
20
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
21
use Sonata\BlockBundle\Test\FakeTemplating;
22
23
/**
24
 * @author Sullivan Senechal <[email protected]>
25
 */
26
class AdminSearchBlockServiceTest extends AbstractBlockServiceTestCase
27
{
28
    /**
29
     * @var Pool
30
     */
31
    private $pool;
32
33
    /**
34
     * @var SearchHandler
35
     */
36
    private $searchHandler;
37
38
    protected function setUp(): void
39
    {
40
        parent::setUp();
41
42
        $this->pool = $this->getMockBuilder(Pool::class)->disableOriginalConstructor()->getMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(\S...onstructor()->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Sonata\AdminBundle\Admin\Pool> of property $pool.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
        $this->searchHandler = $this->getMockBuilder(SearchHandler::class)->disableOriginalConstructor()->getMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(\S...onstructor()->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Sonata\AdminBundle\Search\SearchHandler> of property $searchHandler.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
44
    }
45
46
    public function testDefaultSettings(): void
47
    {
48
        $blockService = new AdminSearchBlockService('foo', $this->templating, $this->pool, $this->searchHandler);
49
        $blockContext = $this->getBlockContext($blockService);
50
51
        $this->assertSettings([
52
            'admin_code' => false,
53
            'query' => '',
54
            'page' => 0,
55
            'per_page' => 10,
56
            'icon' => '<i class="fa fa-list"></i>',
57
        ], $blockContext);
58
    }
59
60
    public function testGlobalSearchReturnsEmptyWhenFiltersAreDisabled(): void
61
    {
62
        $admin = $this->getMockBuilder(AbstractAdmin::class)->disableOriginalConstructor()->getMock();
63
        $templating = $this->getMockBuilder(FakeTemplating::class)->disableOriginalConstructor()->getMock();
64
65
        $blockService = new AdminSearchBlockService('foo', $templating, $this->pool, $this->searchHandler);
66
        $blockContext = $this->getBlockContext($blockService);
67
68
        $this->searchHandler->expects(self::once())->method('search')->willReturn(false);
69
        $this->pool->expects(self::once())->method('getAdminByAdminCode')->willReturn($admin);
70
        $admin->expects(self::once())->method('checkAccess')->with('list')->willReturn(true);
71
72
        // Make sure the template is never generated (empty response is required,
73
        // but the FakeTemplate always returns an empty response)
74
        $templating->expects(self::never())->method('renderResponse');
75
76
        $response = $blockService->execute($blockContext);
77
78
        static::assertSame('', $response->getContent());
79
        static::assertSame(204, $response->getStatusCode());
80
    }
81
}
82