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(); |
||
43 | $this->searchHandler = $this->getMockBuilder(SearchHandler::class)->disableOriginalConstructor()->getMock(); |
||
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' => '', |
||
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); |
||
0 ignored issues
–
show
|
|||
66 | $blockContext = $this->getBlockContext($blockService); |
||
67 | |||
68 | $this->searchHandler->expects(self::once())->method('search')->willReturn(false); |
||
0 ignored issues
–
show
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...
|
|||
69 | $this->pool->expects(self::once())->method('getAdminByAdminCode')->willReturn($admin); |
||
0 ignored issues
–
show
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...
|
|||
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 |
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: