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

tests/Block/GalleryBlockServiceTest.php (2 issues)

Severity

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\Test\AbstractBlockServiceTestCase;
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 AbstractBlockServiceTestCase
25
{
26
    protected $container;
27
    private $galleryManager;
28
    private $blockService;
29
30
    protected function setUp(): void
31
    {
32
        parent::setUp();
33
34
        $this->container = $this->prophesize(ContainerInterface::class);
35
        $this->galleryManager = $this->prophesize(GalleryManagerInterface::class);
36
37
        $this->blockService = new GalleryBlockService(
38
            'block.service',
39
            $this->templating,
40
            $this->container->reveal(),
41
            $this->galleryManager->reveal()
42
        );
43
    }
44
45
    public function testExecute(): void
46
    {
47
        $block = $this->prophesize(Block::class);
48
        $gallery = $this->prophesize(GalleryInterface::class);
49
        $blockContext = $this->prophesize(BlockContext::class);
50
51
        $blockContext->getBlock()->willReturn($block->reveal());
52
        $blockContext->getSettings()->willReturn(['settings']);
53
        $blockContext->getTemplate()->willReturn('template');
54
        $block->getSetting('galleryId')->willReturn($gallery->reveal());
55
        $gallery->getGalleryItems()->willReturn([]);
56
57
        $this->blockService->execute($blockContext->reveal());
58
59
        $this->assertSame('template', $this->templating->view);
60
        $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...
61
        $this->assertInternalType('array', $this->templating->parameters['elements']);
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...
62
        $this->assertSame($gallery->reveal(), $this->templating->parameters['gallery']);
63
        $this->assertSame($block->reveal(), $this->templating->parameters['block']);
64
    }
65
66
    public function testDefaultSettings(): void
67
    {
68
        $blockContext = $this->getBlockContext($this->blockService);
69
70
        $this->assertSettings([
71
            'attr' => [],
72
            'context' => false,
73
            'extra_cache_keys' => [],
74
            'format' => false,
75
            'gallery' => false,
76
            'galleryId' => null,
77
            'pauseTime' => 3000,
78
            'startPaused' => false,
79
            'template' => '@SonataMedia/Block/block_gallery.html.twig',
80
            'title' => null,
81
            'translation_domain' => null,
82
            'icon' => null,
83
            'class' => null,
84
            'ttl' => 0,
85
            'use_cache' => true,
86
        ], $blockContext);
87
    }
88
}
89