GalleryListBlockServiceTest::setUp()   A
last analyzed

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\MediaBundle\Tests\Block;
15
16
use Sonata\BlockBundle\Block\BlockContext;
17
use Sonata\BlockBundle\Model\Block;
18
use Sonata\BlockBundle\Test\BlockServiceTestCase;
19
use Sonata\DatagridBundle\Pager\PagerInterface;
20
use Sonata\MediaBundle\Block\GalleryListBlockService;
21
use Sonata\MediaBundle\Model\GalleryManagerInterface;
22
use Sonata\MediaBundle\Provider\Pool;
23
24
class GalleryListBlockServiceTest extends BlockServiceTestCase
25
{
26
    protected $galleryManager;
27
28
    protected $pool;
29
30
    protected function setUp(): void
31
    {
32
        parent::setUp();
33
34
        $this->galleryManager = $this->createMock(GalleryManagerInterface::class);
35
        $this->pool = $this->createMock(Pool::class);
36
    }
37
38
    public function testExecute(): void
39
    {
40
        $pager = $this->createMock(PagerInterface::class);
41
        $this->galleryManager->expects($this->once())->method('getPager')->willReturn($pager);
42
43
        $block = new Block();
44
45
        $settings = [
46
            'number' => 15,
47
            'mode' => 'public',
48
            'order' => 'createdAt',
49
            'sort' => 'desc',
50
            'context' => false,
51
            'template' => '@SonataMedia/Block/block_gallery_list.html.twig',
52
        ];
53
54
        $blockContext = new BlockContext($block, $settings);
55
56
        $blockService = new GalleryListBlockService($this->twig, null, $this->galleryManager, $this->pool);
57
58
        $this->twig
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Twig\Environment>.

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...
59
            ->expects($this->once())
60
            ->method('render')
61
            ->with('@SonataMedia/Block/block_gallery_list.html.twig', [
62
                'context' => $blockContext,
63
                'pager' => $pager,
64
                'block' => $block,
65
                'settings' => $settings,
66
            ]);
67
68
        $blockService->execute($blockContext);
69
    }
70
71
    public function testDefaultSettings(): void
72
    {
73
        $blockService = new GalleryListBlockService($this->twig, null, $this->galleryManager, $this->pool);
74
        $blockContext = $this->getBlockContext($blockService);
75
76
        $this->assertSettings([
77
            'number' => 15,
78
            'mode' => 'public',
79
            'order' => 'createdAt',
80
            'sort' => 'desc',
81
            'context' => false,
82
            'title' => null,
83
            'translation_domain' => null,
84
            'icon' => 'fa fa-images',
85
            'class' => null,
86
            'template' => '@SonataMedia/Block/block_gallery_list.html.twig',
87
        ], $blockContext);
88
    }
89
}
90