|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of forecast.it.fill project. |
|
7
|
|
|
* (c) Patrick Jaja <[email protected]> |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace ForecastAutomationTests\GitlabClient; |
|
13
|
|
|
|
|
14
|
|
|
use ForecastAutomation\Activity\Shared\Dto\ActivityDto; |
|
15
|
|
|
use ForecastAutomation\Activity\Shared\Dto\ActivityDtoCollection; |
|
16
|
|
|
use ForecastAutomation\ForecastClient\ForecastClientFacade; |
|
17
|
|
|
use ForecastAutomation\ForecastClient\ForecastClientFactory; |
|
18
|
|
|
use ForecastAutomation\ForecastClient\Shared\Dto\ForecastConfigDto; |
|
19
|
|
|
use ForecastAutomation\GitlabClient\GitlabClientFacade; |
|
20
|
|
|
use ForecastAutomation\GitlabClient\GitlabClientFactory; |
|
21
|
|
|
use ForecastAutomation\GitlabClient\Shared\Dto\GitlabConfigDto; |
|
22
|
|
|
use ForecastAutomation\GitlabClient\Shared\Dto\GitlabQueryDto; |
|
23
|
|
|
use GuzzleHttp\Client; |
|
24
|
|
|
use GuzzleHttp\Psr7\Response; |
|
25
|
|
|
use PHPUnit\Framework\TestCase; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @internal |
|
29
|
|
|
* @covers |
|
30
|
|
|
*/ |
|
31
|
|
|
final class GitlabClientFacadeTest extends TestCase |
|
32
|
|
|
{ |
|
33
|
|
|
public function testCanReadEvents(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$events = $this->createGitlabClientFacade()->getEvents( |
|
36
|
|
|
new GitlabQueryDto('test') |
|
37
|
|
|
); |
|
38
|
|
|
static::assertSame('test-event', $events[0]->test); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
private function createGitlabClientFacade(): GitlabClientFacade |
|
42
|
|
|
{ |
|
43
|
|
|
$clientMock = $this->getMockBuilder(Client::class) |
|
44
|
|
|
->onlyMethods(['request']) |
|
45
|
|
|
->getMock() |
|
46
|
|
|
; |
|
47
|
|
|
$clientMock |
|
48
|
|
|
->method('request') |
|
49
|
|
|
->willReturn( |
|
50
|
|
|
new Response(200, ['X-Foo' => 'Bar'], '[{"test":"test-event"}]') |
|
51
|
|
|
) |
|
52
|
|
|
; |
|
53
|
|
|
|
|
54
|
|
|
$gitlabClientFactoryMock = $this->getMockBuilder(GitlabClientFactory::class) |
|
55
|
|
|
->onlyMethods(['createClient', 'createGitlabConfigDto']) |
|
56
|
|
|
->getMock() |
|
57
|
|
|
; |
|
58
|
|
|
$gitlabClientFactoryMock |
|
59
|
|
|
->method('createClient') |
|
60
|
|
|
->willReturn($clientMock) |
|
61
|
|
|
; |
|
62
|
|
|
|
|
63
|
|
|
$gitlabClientFactoryMock->method('createGitlabConfigDto') |
|
64
|
|
|
->willReturn(new GitlabConfigDto('', '')) |
|
65
|
|
|
; |
|
66
|
|
|
|
|
67
|
|
|
$gitlabClientFacadeMock = $this->getMockBuilder(GitlabClientFacade::class) |
|
68
|
|
|
->onlyMethods(['getFactory']) |
|
69
|
|
|
->getMock() |
|
70
|
|
|
; |
|
71
|
|
|
$gitlabClientFacadeMock |
|
72
|
|
|
->method('getFactory') |
|
73
|
|
|
->willReturn($gitlabClientFactoryMock) |
|
74
|
|
|
; |
|
75
|
|
|
|
|
76
|
|
|
return $gitlabClientFacadeMock; |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|