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

HtmlFormatterTest::testFormatterEncoding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 9.9666
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\WebResponse 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