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

TwigFormatterTest::testAccepts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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