|
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\ForecastClient; |
|
13
|
|
|
|
|
14
|
|
|
use ForecastAutomation\Activity\Shared\Dto\ActivityDto; |
|
15
|
|
|
use ForecastAutomation\Activity\Shared\Dto\ActivityDtoCollection; |
|
16
|
|
|
use ForecastAutomation\Cache\CacheFacade; |
|
17
|
|
|
use ForecastAutomation\ForecastClient\ForecastClientFacade; |
|
18
|
|
|
use ForecastAutomation\ForecastClient\ForecastClientFactory; |
|
19
|
|
|
use ForecastAutomation\ForecastClient\Shared\Dto\ForecastConfigDto; |
|
20
|
|
|
use ForecastAutomation\Log\LogFacade; |
|
21
|
|
|
use GuzzleHttp\Client; |
|
22
|
|
|
use GuzzleHttp\Psr7\Response; |
|
23
|
|
|
use PHPUnit\Framework\TestCase; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @internal |
|
27
|
|
|
* @covers |
|
28
|
|
|
*/ |
|
29
|
|
|
final class ForecastClientFacadeTest extends TestCase |
|
30
|
|
|
{ |
|
31
|
|
|
public function testCanWriteActivityCollection(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$writtenActivities = $this->createForecastClientFacade()->writeActivities( |
|
34
|
|
|
new ActivityDtoCollection(new ActivityDto('test-ticket-number', 'test', new \DateTime(), 1)) |
|
35
|
|
|
); |
|
36
|
|
|
static::assertSame(1, $writtenActivities); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
private function createCacheFacadeMock(): CacheFacade |
|
40
|
|
|
{ |
|
41
|
|
|
$cacheFacadeMock = $this->getMockBuilder(CacheFacade::class) |
|
42
|
|
|
->onlyMethods(['set', 'has']) |
|
43
|
|
|
->getMock(); |
|
44
|
|
|
$cacheFacadeMock->method('has') |
|
45
|
|
|
->willReturn( |
|
46
|
|
|
false |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
$cacheFacadeMock->method('set') |
|
50
|
|
|
->willReturn( |
|
51
|
|
|
true |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
return $cacheFacadeMock; |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function createLogFacadeMock(): LogFacade |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->getMockBuilder(LogFacade::class) |
|
|
|
|
|
|
60
|
|
|
->getMock(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
private function createForecastClientFacade(): ForecastClientFacade |
|
64
|
|
|
{ |
|
65
|
|
|
$clientMock = $this->getMockBuilder(Client::class) |
|
66
|
|
|
->onlyMethods(['request']) |
|
67
|
|
|
->getMock(); |
|
68
|
|
|
$clientMock |
|
69
|
|
|
->method('request') |
|
70
|
|
|
->willReturn( |
|
71
|
|
|
new Response(200, ['X-Foo' => 'Bar'], '[{"title":"test-ticket-number","id":1}]') |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$forecastClientFactoryMock = $this->getMockBuilder(ForecastClientFactory::class) |
|
75
|
|
|
->onlyMethods(['createClient', 'createForecastConfigDto', 'getLogFacade', 'getCacheFacade']) |
|
76
|
|
|
->getMock(); |
|
77
|
|
|
$forecastClientFactoryMock |
|
78
|
|
|
->method('createClient') |
|
79
|
|
|
->willReturn($clientMock); |
|
80
|
|
|
$forecastClientFactoryMock |
|
81
|
|
|
->method('getLogFacade') |
|
82
|
|
|
->willReturn($this->createLogFacadeMock()); |
|
83
|
|
|
$forecastClientFactoryMock |
|
84
|
|
|
->method('getCacheFacade') |
|
85
|
|
|
->willReturn($this->createCacheFacadeMock()); |
|
86
|
|
|
|
|
87
|
|
|
$forecastClientFactoryMock |
|
88
|
|
|
->method('createForecastConfigDto') |
|
89
|
|
|
->willReturn(new ForecastConfigDto('', '', '', '', '')); |
|
90
|
|
|
|
|
91
|
|
|
$forecastClientFacadeMock = $this->getMockBuilder(ForecastClientFacade::class) |
|
92
|
|
|
->onlyMethods(['getFactory']) |
|
93
|
|
|
->getMock(); |
|
94
|
|
|
$forecastClientFacadeMock |
|
95
|
|
|
->method('getFactory') |
|
96
|
|
|
->willReturn($forecastClientFactoryMock); |
|
97
|
|
|
|
|
98
|
|
|
return $forecastClientFacadeMock; |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|