|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace ForecastAutomationTests\ForecastClient; |
|
4
|
|
|
|
|
5
|
|
|
use ForecastAutomation\Activity\Shared\Dto\ActivityDto; |
|
6
|
|
|
use ForecastAutomation\Activity\Shared\Dto\ActivityDtoCollection; |
|
7
|
|
|
use ForecastAutomation\ForecastClient\ForecastClientFacade; |
|
8
|
|
|
use ForecastAutomation\ForecastClient\ForecastClientFactory; |
|
9
|
|
|
use ForecastAutomation\ForecastClient\Shared\Dto\ForecastConfigDto; |
|
10
|
|
|
use GuzzleHttp\Client; |
|
11
|
|
|
use GuzzleHttp\Psr7\Response; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
class ForecastClientFacadeTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
public function testCanWriteActivityCollection(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$writtenActivities = $this->createForecastClientFacade()->writeActivities( |
|
19
|
|
|
new ActivityDtoCollection(new ActivityDto('test-ticket-number', 'test', new \DateTime(), 1)) |
|
20
|
|
|
); |
|
21
|
|
|
$this->assertSame(1, $writtenActivities); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
private function createForecastClientFacade(): ForecastClientFacade |
|
25
|
|
|
{ |
|
26
|
|
|
$clientMock = $this->getMockBuilder(Client::class) |
|
27
|
|
|
->onlyMethods(['request']) |
|
28
|
|
|
->getMock(); |
|
29
|
|
|
$clientMock |
|
30
|
|
|
->method('request') |
|
31
|
|
|
->willReturn( |
|
32
|
|
|
new Response(200, ['X-Foo' => 'Bar'], '[{"title":"test-ticket-number","id":1}]') |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
$forecastClientFactoryMock = $this->getMockBuilder(ForecastClientFactory::class) |
|
36
|
|
|
->onlyMethods(['createClient','createForecastConfigDto']) |
|
37
|
|
|
->getMock(); |
|
38
|
|
|
$forecastClientFactoryMock |
|
39
|
|
|
->method('createClient') |
|
40
|
|
|
->willReturn($clientMock); |
|
41
|
|
|
|
|
42
|
|
|
$forecastClientFactoryMock->method('createForecastConfigDto') |
|
43
|
|
|
->willReturn(new ForecastConfigDto('','','','','')); |
|
44
|
|
|
|
|
45
|
|
|
$forecastClientFacadeMock = $this->getMockBuilder(ForecastClientFacade::class) |
|
46
|
|
|
->onlyMethods(['getFactory']) |
|
47
|
|
|
->getMock(); |
|
48
|
|
|
$forecastClientFacadeMock |
|
49
|
|
|
->method('getFactory') |
|
50
|
|
|
->willReturn($forecastClientFactoryMock); |
|
51
|
|
|
|
|
52
|
|
|
return $forecastClientFacadeMock; |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|