Completed
Pull Request — 3.x (#807)
by
unknown
01:55
created

AuditBlockServiceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A testExecute() 0 19 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 SimpleThings\EntityAudit\AuditReader as SimpleThingsAuditReader;
15
use Sonata\BlockBundle\Block\BlockContext;
16
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
17
use Sonata\DoctrineORMAdminBundle\Block\AuditBlockService;
18
19
/**
20
 * @author Marko Kunic <[email protected]>
21
 */
22
class AuditBlockServiceTest extends AbstractBlockServiceTestCase
23
{
24
    private $simpleThingsAuditReader;
25
    private $blockService;
26
27
    protected function setUp()
28
    {
29
        parent::setUp();
30
        $this->simpleThingsAuditReader = $this->prophesize(SimpleThingsAuditReader::class);
31
32
        $this->blockService = new AuditBlockService(
33
            'block.service',
34
            $this->templating,
35
            $this->simpleThingsAuditReader->reveal()
36
        );
37
    }
38
39
    /**
40
     * @group legacy
41
     */
42
    public function testExecute()
43
    {
44
        $blockContext = $this->prophesize(BlockContext::class);
45
46
        $blockContext->getSetting('limit')->willReturn($limit = 10)->shouldBeCalledTimes(1);
47
        $blockContext->getBlock()->shouldBeCalledTimes(1);
48
49
        $this->simpleThingsAuditReader->findRevisionHistory($limit, 0)
50
            ->willReturn([])
51
            ->shouldBeCalledTimes(1);
52
53
        $blockContext->getTemplate()->willReturn('template')->shouldBeCalledTimes(1);
54
        $blockContext->getSettings()->willReturn([])->shouldBeCalledTimes(1);
55
56
        $this->blockService->execute($blockContext->reveal());
57
58
        $this->assertSame('template', $this->templating->view);
59
        $this->assertInternalType('array', $this->templating->parameters['settings']);
60
    }
61
62
    public function testDefaultSettings()
63
    {
64
        $blockContext = $this->getBlockContext($this->blockService);
65
66
        $this->assertSettings([
67
            'attr' => [],
68
            'extra_cache_keys' => [],
69
            'limit' => 10,
70
            'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig',
71
            'ttl' => 0,
72
            'use_cache' => true,
73
        ], $blockContext);
74
    }
75
}
76