GitlabClientFacadeTest::createGitlabClientFacade()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 22
nc 1
nop 0
dl 0
loc 36
rs 9.568
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\GitlabClient\GitlabClientFacade;
15
use ForecastAutomation\GitlabClient\GitlabClientFactory;
16
use ForecastAutomation\GitlabClient\Shared\Dto\GitlabConfigDto;
17
use ForecastAutomation\GitlabClient\Shared\Dto\GitlabQueryDto;
18
use GuzzleHttp\Client;
19
use GuzzleHttp\Psr7\Response;
20
use PHPUnit\Framework\TestCase;
21
22
/**
23
 * @internal
24
 * @covers
25
 */
26
final class GitlabClientFacadeTest extends TestCase
27
{
28
    public function testCanReadEvents(): void
29
    {
30
        $events = $this->createGitlabClientFacade()->getEvents(
31
            new GitlabQueryDto('test')
32
        );
33
        static::assertSame('test-event', $events[0]->test);
34
    }
35
36
    private function createGitlabClientFacade(): GitlabClientFacade
37
    {
38
        $clientMock = $this->getMockBuilder(Client::class)
39
            ->onlyMethods(['request'])
40
            ->getMock()
41
        ;
42
        $clientMock
43
            ->method('request')
44
            ->willReturn(
45
                new Response(200, ['X-Foo' => 'Bar'], '[{"test":"test-event"}]')
46
            )
47
        ;
48
49
        $gitlabClientFactoryMock = $this->getMockBuilder(GitlabClientFactory::class)
50
            ->onlyMethods(['createClient', 'createGitlabConfigDto'])
51
            ->getMock()
52
        ;
53
        $gitlabClientFactoryMock
54
            ->method('createClient')
55
            ->willReturn($clientMock)
56
        ;
57
58
        $gitlabClientFactoryMock->method('createGitlabConfigDto')
59
            ->willReturn(new GitlabConfigDto('', ''))
60
        ;
61
62
        $gitlabClientFacadeMock = $this->getMockBuilder(GitlabClientFacade::class)
63
            ->onlyMethods(['getFactory'])
64
            ->getMock()
65
        ;
66
        $gitlabClientFacadeMock
67
            ->method('getFactory')
68
            ->willReturn($gitlabClientFactoryMock)
69
        ;
70
71
        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...
72
    }
73
}
74