Passed
Pull Request — master (#233)
by Dmitriy
02:13
created

HtmlFormatterTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testFormatter() 0 11 1
A testFormatterEncoding() 0 12 1
1
<?php
2
3
namespace Yiisoft\Yii\Web\Tests;
4
5
use Nyholm\Psr7\Factory\Psr17Factory;
6
use Nyholm\Psr7\Response;
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Yii\Web\Formatter\HtmlResponseFormatter;
9
use Yiisoft\Yii\Web\Response as WebResponse;
10
11
class HtmlFormatterTest extends TestCase
12
{
13
    public function testFormatter(): void
14
    {
15
        $streamFactory = new Psr17Factory();
16
        $response = new Response();
17
        $webResponse = new WebResponse('test', $response, $streamFactory);
18
        $formatter = new HtmlResponseFormatter();
19
        $result = $formatter->format($webResponse);
20
        $result->getBody()->rewind();
21
22
        $this->assertSame('test', $response->getBody()->getContents());
23
        $this->assertSame(['text/html; charset=UTF-8'], $result->getHeader('Content-Type'));
24
    }
25
26
    public function testFormatterEncoding(): void
27
    {
28
        $streamFactory = new Psr17Factory();
29
        $response = new Response();
30
        $webResponse = new WebResponse('test', $response, $streamFactory);
31
        $formatter = new HtmlResponseFormatter();
32
        $formatter->setEncoding('ISO-8859-1');
33
        $result = $formatter->format($webResponse);
34
        $result->getBody()->rewind();
35
36
        $this->assertSame('test', $response->getBody()->getContents());
37
        $this->assertSame(['text/html; charset=ISO-8859-1'], $result->getHeader('Content-Type'));
38
    }
39
}
40