Completed
Push — master ( bb6905...021686 )
by Grégoire
18s queued 12s
created

tests/Block/GalleryListBlockServiceTest.php (3 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\MediaBundle\Tests\Block;
15
16
use Sonata\BlockBundle\Block\BlockContext;
17
use Sonata\BlockBundle\Model\Block;
18
use Sonata\BlockBundle\Model\BlockInterface;
19
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
20
use Sonata\DatagridBundle\Pager\PagerInterface;
21
use Sonata\MediaBundle\Block\GalleryListBlockService;
22
use Sonata\MediaBundle\Model\GalleryManagerInterface;
23
use Sonata\MediaBundle\Provider\Pool;
24
25
class GalleryListBlockServiceTest extends AbstractBlockServiceTestCase
26
{
27
    /**
28
     * @var \PHPUnit_Framework_MockObject_MockObject|GalleryManagerInterface
29
     */
30
    protected $galleryManager;
31
32
    /**
33
     * @var \PHPUnit_Framework_MockObject_MockObject|Pool
34
     */
35
    protected $pool;
36
37
    protected function setUp(): void
38
    {
39
        parent::setUp();
40
41
        $this->galleryManager = $this->createMock(GalleryManagerInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Sonat...anagerInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<PHPUnit_Framework...alleryManagerInterface> of property $galleryManager.

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...
42
        $this->pool = $this->createMock(Pool::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Sonat...e\Provider\Pool::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<PHPUnit_Framework...iaBundle\Provider\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
    }
44
45
    public function testExecute(): void
46
    {
47
        $pager = $this->createMock(PagerInterface::class);
48
        $this->galleryManager->expects($this->once())->method('getPager')->willReturn($pager);
49
50
        $block = new Block();
51
52
        $blockContext = new BlockContext($block, [
53
            'number' => 15,
54
            'mode' => 'public',
55
            'order' => 'createdAt',
56
            'sort' => 'desc',
57
            'context' => false,
58
            'template' => '@SonataMedia/Block/block_gallery_list.html.twig',
59
        ]);
60
61
        $blockService = new GalleryListBlockService('block.service', $this->templating, $this->galleryManager, $this->pool);
62
        $blockService->execute($blockContext);
63
64
        $this->assertSame('@SonataMedia/Block/block_gallery_list.html.twig', $this->templating->view);
65
66
        $this->assertSame($blockContext, $this->templating->parameters['context']);
67
        $this->assertInternalType('array', $this->templating->parameters['settings']);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
68
        $this->assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']);
69
        $this->assertSame($pager, $this->templating->parameters['pager']);
70
    }
71
72
    public function testDefaultSettings(): void
73
    {
74
        $blockService = new GalleryListBlockService('block.service', $this->templating, $this->galleryManager, $this->pool);
75
        $blockContext = $this->getBlockContext($blockService);
76
77
        $this->assertSettings([
78
            'number' => 15,
79
            'mode' => 'public',
80
            'order' => 'createdAt',
81
            'sort' => 'desc',
82
            'context' => false,
83
            'title' => null,
84
            'translation_domain' => null,
85
            'icon' => 'fa fa-images',
86
            'class' => null,
87
            'template' => '@SonataMedia/Block/block_gallery_list.html.twig',
88
        ], $blockContext);
89
    }
90
}
91