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
|
|
|
|