Completed
Pull Request — 3.x (#6220)
by Vincent
03:15
created

DeprecatedAdminSearchBlockServiceTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\BlockServiceTestCase;
21
use Symfony\Component\HttpFoundation\Response;
22
use Twig\Environment;
23
24
/**
25
 * NEXT_MAJOR: Remove this class.
26
 *
27
 * @group legacy
28
 *
29
 * @author Sullivan Senechal <[email protected]>
30
 */
31
class DeprecatedAdminSearchBlockServiceTest extends BlockServiceTestCase
32
{
33
    /**
34
     * @var Pool
35
     */
36
    private $pool;
37
38
    /**
39
     * @var SearchHandler
40
     */
41
    private $searchHandler;
42
43
    protected function setUp(): void
44
    {
45
        parent::setUp();
46
47
        $this->pool = $this->createMock(Pool::class);
48
        $this->searchHandler = $this->createMock(SearchHandler::class);
49
    }
50
51
    /**
52
     * @expectedDeprecation Passing null as argument 2 to Sonata\AdminBundle\Block\AdminSearchBlockService::__construct() is deprecated since sonata-project/admin-bundle 3.x and will throw a \TypeError in version 4.0. You must pass an instance of Sonata\AdminBundle\Admin\Pool instead.
53
     */
54
    public function testDefaultSettings(): void
55
    {
56
        $blockService = new AdminSearchBlockService(
57
            $this->createMock(Environment::class),
58
            null,
59
            $this->pool,
0 ignored issues
show
Documentation introduced by
$this->pool is of type object<Sonata\AdminBundle\Admin\Pool>, but the function expects a object<Sonata\AdminBundle\Block\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
            $this->searchHandler
61
        );
62
        $blockContext = $this->getBlockContext($blockService);
63
64
        $this->assertSettings([
65
            'admin_code' => '',
66
            'query' => '',
67
            'page' => 0,
68
            'per_page' => 10,
69
            'icon' => '<i class="fa fa-list"></i>',
70
        ], $blockContext);
71
    }
72
73
    /**
74
     * @expectedDeprecation Passing null as argument 2 to Sonata\AdminBundle\Block\AdminSearchBlockService::__construct() is deprecated since sonata-project/admin-bundle 3.x and will throw a \TypeError in version 4.0. You must pass an instance of Sonata\AdminBundle\Admin\Pool instead.
75
     */
76
    public function testGlobalSearchReturnsEmptyWhenFiltersAreDisabled(): void
77
    {
78
        $admin = $this->createMock(AbstractAdmin::class);
79
80
        $blockService = new AdminSearchBlockService(
81
            $this->createMock(Environment::class),
82
            null,
83
            $this->pool,
0 ignored issues
show
Documentation introduced by
$this->pool is of type object<Sonata\AdminBundle\Admin\Pool>, but the function expects a object<Sonata\AdminBundle\Block\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
84
            $this->searchHandler
85
        );
86
        $blockContext = $this->getBlockContext($blockService);
87
88
        $this->searchHandler->expects(self::once())->method('search')->willReturn(false);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Search\SearchHandler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
        $this->pool->expects(self::once())->method('getAdminByAdminCode')->willReturn($admin);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Sonata\AdminBundle\Admin\Pool>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
        $admin->expects(self::once())->method('checkAccess')->with('list')->willReturn(true);
91
92
        $response = $blockService->execute($blockContext);
93
94
        static::assertSame('', $response->getContent());
95
        static::assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode());
96
    }
97
}
98