Completed
Push — master ( 5c37fe...c17fc1 )
by Vincent
14s queued 12s
created

DeprecatedAuditBlockServiceTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
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\DoctrineORMAdminBundle\Tests\Block;
15
16
use Prophecy\Argument;
17
use SimpleThings\EntityAudit\AuditReader as SimpleThingsAuditReader;
18
use SimpleThings\EntityAudit\Revision;
19
use Sonata\BlockBundle\Block\BlockContext;
20
use Sonata\BlockBundle\Model\Block;
21
use Sonata\BlockBundle\Test\BlockServiceTestCase;
22
use Sonata\DoctrineORMAdminBundle\Block\AuditBlockService;
23
24
/**
25
 * NEXT_MAJOR: Remove this class.
26
 *
27
 * @group legacy
28
 *
29
 * @author Marko Kunic <[email protected]>
30
 */
31
class DeprecatedAuditBlockServiceTest extends BlockServiceTestCase
32
{
33
    private $simpleThingsAuditReader;
34
    private $blockService;
35
36
    protected function setUp(): void
37
    {
38
        parent::setUp();
39
        $this->simpleThingsAuditReader = $this->prophesize(SimpleThingsAuditReader::class);
40
41
        $this->blockService = new AuditBlockService(
42
            'block.service',
43
            $this->templating,
44
            $this->simpleThingsAuditReader->reveal()
45
        );
46
    }
47
48
    /**
49
     * @expectedDeprecation Passing Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as argument 2 to Sonata\DoctrineORMAdminBundle\Block\AuditBlockService::__construct() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.x and will throw a \TypeError in version 4.0. You must pass an instance of SimpleThings\EntityAudit\AuditReader instead.
50
     */
51
    public function testExecute(): void
52
    {
53
        $blockContext = $this->prophesize(BlockContext::class);
54
55
        $blockContext->getBlock()->willReturn($block = new Block())->shouldBeCalledTimes(1);
56
        $blockContext->getSetting('limit')->willReturn($limit = 10)->shouldBeCalledTimes(1);
57
58
        $this->simpleThingsAuditReader->findRevisionHistory($limit, 0)
59
            ->willReturn([$revision = new Revision('test', '123', 'test')])
60
            ->shouldBeCalledTimes(1);
61
62
        $this->simpleThingsAuditReader->findEntitiesChangedAtRevision(Argument::cetera())
63
            ->willReturn([])
64
            ->shouldBeCalledTimes(1);
65
66
        $blockContext->getTemplate()->willReturn('template')->shouldBeCalledTimes(1);
67
        $blockContext->getSettings()->willReturn([])->shouldBeCalledTimes(1);
68
69
        $this->blockService->execute($blockContext->reveal());
70
71
        $this->assertSame('template', $this->templating->view);
72
        $this->assertIsArray($this->templating->parameters['settings']);
73
        $this->assertSame($revision, $this->templating->parameters['revisions'][0]['revision']);
74
        $this->assertSame($block, $this->templating->parameters['block']);
75
    }
76
77
    /**
78
     * @expectedDeprecation Passing Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as argument 2 to Sonata\DoctrineORMAdminBundle\Block\AuditBlockService::__construct() is deprecated since sonata-project/doctrine-orm-admin-bundle 3.x and will throw a \TypeError in version 4.0. You must pass an instance of SimpleThings\EntityAudit\AuditReader instead.
79
     */
80
    public function testDefaultSettings(): void
81
    {
82
        $blockContext = $this->getBlockContext($this->blockService);
83
84
        $this->assertSettings([
85
            'attr' => [],
86
            'extra_cache_keys' => [],
87
            'limit' => 10,
88
            'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig',
89
            'ttl' => 0,
90
            'use_cache' => true,
91
        ], $blockContext);
92
    }
93
}
94