Passed
Push — master ( 6045bf...dbb88a )
by Patrick
03:21
created

GitlabClientFacadeTest::testCanReadEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 1
b 0
f 1
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;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $gitlabClientFacadeMock returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return ForecastAutomation\GitlabClient\GitlabClientFacade.
Loading history...
77
    }
78
}
79