Completed
Push — 3.x ( b582dd...8b3829 )
by Jordi Sala
01:51
created

AuditBlockServiceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 5
dl 0
loc 60
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
B testExecute() 0 25 1
A testDefaultSettings() 0 13 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\DoctrineORMAdminBundle\Tests\Block;
13
14
use Prophecy\Argument;
15
use SimpleThings\EntityAudit\AuditReader as SimpleThingsAuditReader;
16
use SimpleThings\EntityAudit\Revision;
17
use Sonata\BlockBundle\Block\BlockContext;
18
use Sonata\BlockBundle\Model\Block;
19
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
20
use Sonata\DoctrineORMAdminBundle\Block\AuditBlockService;
21
22
/**
23
 * @author Marko Kunic <[email protected]>
24
 */
25
class AuditBlockServiceTest extends AbstractBlockServiceTestCase
26
{
27
    private $simpleThingsAuditReader;
28
    private $blockService;
29
30
    protected function setUp()
31
    {
32
        parent::setUp();
33
        $this->simpleThingsAuditReader = $this->prophesize(SimpleThingsAuditReader::class);
34
35
        $this->blockService = new AuditBlockService(
36
            'block.service',
37
            $this->templating,
38
            $this->simpleThingsAuditReader->reveal()
39
        );
40
    }
41
42
    /**
43
     * @group legacy
44
     */
45
    public function testExecute()
46
    {
47
        $blockContext = $this->prophesize(BlockContext::class);
48
49
        $blockContext->getBlock()->willReturn($block = new Block())->shouldBeCalledTimes(1);
50
        $blockContext->getSetting('limit')->willReturn($limit = 10)->shouldBeCalledTimes(1);
51
52
        $this->simpleThingsAuditReader->findRevisionHistory($limit, 0)
53
            ->willReturn([$revision = new Revision('test', '123', 'test')])
54
            ->shouldBeCalledTimes(1);
55
56
        $this->simpleThingsAuditReader->findEntitesChangedAtRevision(Argument::cetera())
57
            ->willReturn([])
58
            ->shouldBeCalledTimes(1);
59
60
        $blockContext->getTemplate()->willReturn('template')->shouldBeCalledTimes(1);
61
        $blockContext->getSettings()->willReturn([])->shouldBeCalledTimes(1);
62
63
        $this->blockService->execute($blockContext->reveal());
64
65
        $this->assertSame('template', $this->templating->view);
66
        $this->assertInternalType('array', $this->templating->parameters['settings']);
67
        $this->assertSame($revision, $this->templating->parameters['revisions'][0]['revision']);
68
        $this->assertSame($block, $this->templating->parameters['block']);
69
    }
70
71
    public function testDefaultSettings()
72
    {
73
        $blockContext = $this->getBlockContext($this->blockService);
74
75
        $this->assertSettings([
76
            'attr' => [],
77
            'extra_cache_keys' => [],
78
            'limit' => 10,
79
            'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig',
80
            'ttl' => 0,
81
            'use_cache' => true,
82
        ], $blockContext);
83
    }
84
}
85