Completed
Push — master ( c1adf5...002a39 )
by Alex
02:26
created

TwigFormatterTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 44
rs 10
1
<?php
2
3
namespace Asmaster\EquipTwig\Tests;
4
5
use Asmaster\EquipTwig\TwigFormatter;
6
use Equip\Adr\PayloadInterface;
7
use PHPUnit_Framework_TestCase as TestCase;
8
use Twig_Environment as TwigEnvironment;
9
use Twig_Loader_Filesystem as TwigLoaderFilesystem;
10
11
class TwigFormatterTest extends TestCase
12
{
13
    /**
14
     * @var TwigFormatter
15
     */
16
    private $formatter;
17
18
    protected function setUp()
19
    {
20
        $loader = new TwigLoaderFilesystem(__DIR__.'/Asset/templates');
21
22
        $this->formatter = new TwigFormatter(
23
            new TwigEnvironment($loader)
24
        );
25
    }
26
27
    public function testAccepts()
28
    {
29
        $this->assertEquals(['text/html'], TwigFormatter::accepts());
30
    }
31
32
    public function testType()
33
    {
34
        $this->assertEquals('text/html', $this->formatter->type());
35
    }
36
37
    public function testResponse()
38
    {
39
        $template = 'test.html.twig';
40
        $output = [
41
            'header' => 'header',
42
            'body'   => 'body',
43
            'footer' => 'footer'
44
        ];
45
46
        $payload = $this->createMock(PayloadInterface::class);
47
        $payload->expects($this->any())->method('getOutput')->willReturn($output);
48
        $payload->expects($this->any())->method('getSetting')->willReturn($template);
49
50
        $body = $this->formatter->body($payload);
51
52
        $this->assertEquals("<h1>header</h1>\n<p>body</p>\n<span>footer</span>\n", $body);
53
    }
54
}
55