Completed
Push — master ( b346da...606e51 )
by Alex
02:08
created

TwigFormatterTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 42
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 2
A testAccepts() 0 4 1
A testType() 0 4 1
A testResponse() 0 12 1
1
<?php
2
3
namespace Asmaster\EquipTwigTests;
4
5
use Asmaster\EquipTwig\TwigFormatter;
6
use Asmaster\EquipTwig\TemplatePayload;
7
use Lukasoppermann\Httpstatus\Httpstatus;
8
9
class TwigFormatterTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @var TwigFormatter
13
     */
14
    protected $formatter;
15
16
    public function setUp()
17
    {
18
        if (!class_exists('\Twig_Environment')) {
19
            $this->markTestSkipped('Twig is not installed');
20
        }
21
22
        $loader = new \Twig_Loader_Filesystem(__DIR__.'/_templates');
23
        $twig = new \Twig_Environment($loader);
24
25
        $this->formatter = new TwigFormatter($twig, new HttpStatus);
26
    }
27
28
    public function testAccepts()
29
    {
30
        $this->assertEquals(['text/html'], TwigFormatter::accepts());
31
    }
32
33
    public function testType()
34
    {
35
        $this->assertEquals('text/html', $this->formatter->type());
36
    }
37
38
    public function testResponse()
39
    {
40
        $payload = (new TemplatePayload)
41
            ->withOutput([
42
                'header' => 'header',
43
                'body'   => 'body',
44
                'footer' => 'footer',
45
            ])->withTemplate('index.html.twig');
46
47
        $body = (string) $this->formatter->body($payload);
48
        $this->assertEquals("<h1>header</h1>\n<p>body</p>\n<span>footer</span>\n", $body);
49
    }
50
}
51