Passed
Pull Request — master (#233)
by Dmitriy
04:17
created

JsonFormatterTest::testFormatter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
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\JsonResponseFormatter;
9
use Yiisoft\Yii\Web\WebResponse as WebResponse;
10
11
class JsonFormatterTest extends TestCase
12
{
13
    public function testFormatter(): void
14
    {
15
        $streamFactory = new Psr17Factory();
16
        $response = new Response();
17
        $webResponse = new WebResponse(['test' => 'test'], $response, $streamFactory);
18
        $formatter = new JsonResponseFormatter();
19
        $result = $formatter->format($webResponse);
20
        $result->getBody()->rewind();
21
22
        $this->assertSame('{"test":"test"}', $response->getBody()->getContents());
23
        $this->assertSame(['application/json'], $result->getHeader('Content-Type'));
24
    }
25
}
26