Completed
Push — master ( 1da4a7...53bb89 )
by Alex
02:34
created

TwigFormatterTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 45
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testAccepts() 0 4 1
A testType() 0 4 1
A testResponse() 0 19 1
1
<?php
2
3
namespace Asmaster\EquipTwig\Tests;
4
5
use PHPUnit_Framework_TestCase as TestCase;
6
use Equip\Adr\PayloadInterface;
7
use Asmaster\EquipTwig\TwigFormatter;
8
use Lukasoppermann\Httpstatus\Httpstatus;
9
use Twig_Environment as TwigEnvironment;
10
use Twig_Loader_Filesystem as TwigLoaderFilesystem;
11
12
class TwigFormatterTest extends TestCase
13
{
14
    /**
15
     * @var TwigFormatter
16
     */
17
    protected $formatter;
18
19
    public function setUp()
20
    {
21
        $loader = new TwigLoaderFilesystem(__DIR__.'/Asset/templates');
22
        $twig = new TwigEnvironment($loader);
23
24
        $this->formatter = new TwigFormatter($twig, new HttpStatus);
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
        $output = [
40
            'template' => 'index.html.twig',
41
            'header'   => 'header',
42
            'body'     => 'body',
43
            'footer'   => 'footer'
44
        ];
45
46
        /** @var PayloadInterface|\PHPUnit_Framework_MockObject_MockObject */
47
        $payload = $this->getMock(PayloadInterface::class);
48
        $payload
49
            ->expects($this->any())
50
            ->method('getOutput')
51
            ->will($this->returnValue($output));
52
53
        $body = (string) $this->formatter->body($payload);
54
        $this->assertEquals("<h1>header</h1>\n<p>body</p>\n<span>footer</span>\n", $body);
55
    }
56
}
57