GalleryBlockServiceTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 74
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 14 1
A testExecute() 0 24 1
A testDefaultSettings() 0 22 1
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\MediaBundle\Block\GalleryBlockService;
20
use Sonata\MediaBundle\Model\GalleryInterface;
21
use Sonata\MediaBundle\Model\GalleryManagerInterface;
22
use Symfony\Component\DependencyInjection\ContainerInterface;
23
24
class GalleryBlockServiceTest extends BlockServiceTestCase
25
{
26
    protected $container;
27
28
    private $galleryManager;
29
30
    /**
31
     * @var GalleryBlockService
32
     */
33
    private $blockService;
34
35
    protected function setUp(): void
36
    {
37
        parent::setUp();
38
39
        $this->container = $this->prophesize(ContainerInterface::class);
40
        $this->galleryManager = $this->prophesize(GalleryManagerInterface::class);
41
42
        $this->blockService = new GalleryBlockService(
43
            $this->twig,
44
            null,
45
            $this->container->reveal(),
46
            $this->galleryManager->reveal()
47
        );
48
    }
49
50
    public function testExecute(): void
51
    {
52
        $block = $this->prophesize(Block::class);
53
        $gallery = $this->prophesize(GalleryInterface::class);
54
        $blockContext = $this->prophesize(BlockContext::class);
55
56
        $blockContext->getBlock()->willReturn($block->reveal());
57
        $blockContext->getSettings()->willReturn(['settings']);
58
        $blockContext->getTemplate()->willReturn('template');
59
        $block->getSetting('galleryId')->willReturn($gallery->reveal());
60
        $gallery->getGalleryItems()->willReturn([]);
61
62
        $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...
63
            ->expects($this->once())
64
            ->method('render')
65
            ->with('template', [
66
                'gallery' => $gallery->reveal(),
67
                'block' => $block->reveal(),
68
                'elements' => [],
69
                'settings' => ['settings'],
70
            ]);
71
72
        $this->blockService->execute($blockContext->reveal());
73
    }
74
75
    public function testDefaultSettings(): void
76
    {
77
        $blockContext = $this->getBlockContext($this->blockService);
78
79
        $this->assertSettings([
80
            'attr' => [],
81
            'context' => false,
82
            'extra_cache_keys' => [],
83
            'format' => false,
84
            'gallery' => false,
85
            'galleryId' => null,
86
            'pauseTime' => 3000,
87
            'startPaused' => false,
88
            'template' => '@SonataMedia/Block/block_gallery.html.twig',
89
            'title' => null,
90
            'translation_domain' => null,
91
            'icon' => null,
92
            'class' => null,
93
            'ttl' => 0,
94
            'use_cache' => true,
95
        ], $blockContext);
96
    }
97
}
98