Passed
Push — master ( f6e659...bb9ac5 )
by Patrick
04:00
created

ForecastClientFacadeTest::createLogFacadeMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
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;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $cacheFacadeMock returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return ForecastAutomation\Cache\CacheFacade.
Loading history...
55
    }
56
57
    private function createLogFacadeMock(): LogFacade
58
    {
59
        return $this->getMockBuilder(LogFacade::class)
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getMockBui...cade::class)->getMock() returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return ForecastAutomation\Log\LogFacade.
Loading history...
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;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $forecastClientFacadeMock returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return ForecastAutomation\Forec...nt\ForecastClientFacade.
Loading history...
99
    }
100
}
101