Passed
Push — master ( 95786b...34331f )
by Paweł
05:27 queued 02:18
created

KernelClientTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace 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
        $responseExpected = new Response('test_content');
31
32
        $this->kernelMock->expects($this->once())->method('reboot')->willReturn($this->kernelMock);
33
        $this->kernelMock->expects($this->once())->method('handleRequest')->willReturn($responseExpected);
34
35
        $this->requestFactoryMock
36
            ->expects($this->once())
37
            ->method('create')
38
            ->with(Request::METHOD_GET, '/resources')
39
            ->willReturn(new Request());
40
41
        $response = $this->setUpKernelClient()->request(Request::METHOD_GET, '/resources');
42
43
        $this->assertSame($responseExpected->getContent(), $response->getContent());
44
    }
45
46
    private function setUpKernelClient(): KernelClient
47
    {
48
        return new KernelClient($this->kernelMock, $this->requestFactoryMock);
49
    }
50
}
51