KernelClientTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpKernelClient() 0 3 1
A setUp() 0 4 1
A testPerformsRequestOnKernel() 0 24 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gorynych\Tests\Http;
6
7
use Gorynych\Http\Kernel;
8
use Gorynych\Http\KernelClient;
9
use Gorynych\Http\RequestFactoryInterface;
10
use PHPUnit\Framework\MockObject\MockObject;
11
use PHPUnit\Framework\TestCase;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
15
class KernelClientTest extends TestCase
16
{
17
    /** @var Kernel|MockObject */
18
    private $kernelMock;
19
    /** @var RequestFactoryInterface|MockObject */
20
    private $requestFactoryMock;
21
22
    public function setUp(): void
23
    {
24
        $this->kernelMock = $this->createMock(Kernel::class);
25
        $this->requestFactoryMock = $this->createMock(RequestFactoryInterface::class);
26
    }
27
28
    public function testPerformsRequestOnKernel(): void
29
    {
30
        $request = Request::create('/resources', Request::METHOD_GET);
31
        $responseExpected = new Response('test_content');
32
33
        $this->requestFactoryMock
34
            ->expects($this->once())
35
            ->method('create')
36
            ->with(Request::METHOD_GET, '/resources')
37
            ->willReturn($request);
38
39
        $this->kernelMock
40
            ->expects($this->once())
41
            ->method('reboot')
42
            ->willReturn($this->kernelMock);
43
        $this->kernelMock
44
            ->expects($this->once())
45
            ->method('handleRequest')
46
            ->with($request)
47
            ->willReturn($responseExpected);
48
49
        $response = $this->setUpKernelClient()->request(Request::METHOD_GET, '/resources');
50
51
        $this->assertSame($responseExpected->getContent(), $response->getContent());
52
    }
53
54
    private function setUpKernelClient(): KernelClient
55
    {
56
        return new KernelClient($this->kernelMock, $this->requestFactoryMock);
57
    }
58
}
59