Passed
Pull Request — master (#233)
by Dmitriy
01:58
created

JsonFormatterTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 13
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testFormatter() 0 11 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\Serializer\JsonSerializer;
9
use Yiisoft\Yii\Web\Formatter\JsonResponseFormatter;
10
use Yiisoft\Yii\Web\Response as WebResponse;
11
12
class JsonFormatterTest extends TestCase
13
{
14
    public function testFormatter(): void
15
    {
16
        $streamFactory = new Psr17Factory();
17
        $response = new Response();
18
        $webResponse = new WebResponse(['test' => 'test'], $response, $streamFactory);
19
        $formatter = new JsonResponseFormatter(new JsonSerializer(), $streamFactory);
20
        $result = $formatter->format($webResponse);
21
        $result->getBody()->rewind();
22
23
        $this->assertSame('{"test":"test"}', $response->getBody()->getContents());
24
        $this->assertSame(['application/json'], $result->getHeader('Content-Type'));
25
    }
26
}
27