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

JiraClientFacadeTest::testCanReadEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
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\JiraClient;
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 ForecastAutomation\JiraClient\JiraClientFacade;
24
use ForecastAutomation\JiraClient\JiraClientFactory;
25
use ForecastAutomation\JiraClient\Shared\Dto\JiraConfigDto;
26
use GuzzleHttp\Client;
27
use GuzzleHttp\Psr7\Response;
28
use JiraRestApi\Issue\Comment;
29
use JiraRestApi\Issue\Issue;
30
use JiraRestApi\Issue\IssueSearchResult;
31
use JiraRestApi\Issue\IssueService;
32
use JiraRestApi\JiraClient;
33
use JiraRestApi\Request\Author;
34
use PHPUnit\Framework\TestCase;
35
36
/**
37
 * @internal
38
 * @covers
39
 */
40
final class JiraClientFacadeTest extends TestCase
41
{
42
    const TESTUSER_EXAMPLE_COM = '[email protected]';
43
    const TICKET_COMMENT_UPDATED = '2021-01-02 11:00:00';
44
    const TICKET_COMMENT_BODY = 'test';
45
46
    public function testCanReadEvents(): void
47
    {
48
        $comments = $this->createGitlabClientFacade()->getComments(
49
            '2021-01-02 10:00:00'
50
        );
51
        static::assertArrayHasKey('test-key',$comments);
52
        static::assertSame(self::TICKET_COMMENT_BODY,$comments['test-key'][0]->body);
53
        static::assertSame('[email protected]',$comments['test-key'][0]->author->emailAddress);
54
        static::assertSame(self::TICKET_COMMENT_UPDATED,$comments['test-key'][0]->updated);
55
    }
56
57
    private function createGitlabClientFacade(): JiraClientFacade
58
    {
59
        $issueServiceMock = $this->getMockBuilder(IssueService::class)->disableOriginalConstructor()
60
            ->onlyMethods(['search','getComments'])
61
            ->getMock()
62
        ;
63
64
        $issueSearchResult = new IssueSearchResult();
65
66
        $testIssue = new Issue();
67
        $testIssue->key = 'test-key';
68
        $issueSearchResult->setIssues([$testIssue]);
69
        $this->returnValue($issueSearchResult);
70
71
        $issueServiceMock
72
            ->method('search')
73
            ->willReturn(
74
                $issueSearchResult
75
            )
76
        ;
77
78
        $testComment = new Comment();
79
        $testComment->body= self::TICKET_COMMENT_BODY;
80
        $testComment->updated= self::TICKET_COMMENT_UPDATED;
0 ignored issues
show
Documentation Bug introduced by
It seems like self::TICKET_COMMENT_UPDATED of type string is incompatible with the declared type DateTimeInterface of property $updated.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
81
82
        $testComments = new \stdClass();
83
        $testComments->comments = [$testComment];
84
        $testAuthor = new Author();
85
        $testAuthor->emailAddress = self::TESTUSER_EXAMPLE_COM;
86
        $testComment->author = $testAuthor;
0 ignored issues
show
Documentation Bug introduced by
It seems like $testAuthor of type JiraRestApi\Request\Author is incompatible with the declared type JiraRestApi\Issue\Reporter of property $author.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
87
        $issueServiceMock
88
            ->method('getComments')
89
            ->willReturn(
90
                $testComments
91
            )
92
        ;
93
94
        $jiraClientFactoryMock = $this->getMockBuilder(JiraClientFactory::class)
95
            ->onlyMethods(['createJiraClient', 'createJiraConfigDto'])
96
            ->getMock()
97
        ;
98
        $jiraClientFactoryMock
99
            ->method('createJiraClient')
100
            ->willReturn($issueServiceMock)
101
        ;
102
103
        $jiraClientFactoryMock->method('createJiraConfigDto')
104
            ->willReturn(new JiraConfigDto('', '', self::TESTUSER_EXAMPLE_COM,0,''))
105
        ;
106
107
        $jiraClientFacadeMock = $this->getMockBuilder(JiraClientFacade::class)
108
            ->onlyMethods(['getFactory'])
109
            ->getMock()
110
        ;
111
        $jiraClientFacadeMock
112
            ->method('getFactory')
113
            ->willReturn($jiraClientFactoryMock)
114
        ;
115
116
        return $jiraClientFacadeMock;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $jiraClientFacadeMock returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return ForecastAutomation\JiraClient\JiraClientFacade.
Loading history...
117
    }
118
}
119