JiraActivityPluginTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 31
dl 0
loc 48
rs 10
c 2
b 0
f 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createJiraActivityPlugin() 0 32 1
A testCanReadEvents() 0 7 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\Shared\Plugin;
13
14
use ForecastAutomation\JiraClient\JiraClientFacade;
15
use ForecastAutomation\JiraClient\Shared\Plugin\JiraActivityPlugin;
16
use JiraRestApi\Issue\Comment;
17
use JiraRestApi\Request\Author;
18
use PHPUnit\Framework\TestCase;
19
20
/**
21
 * @internal
22
 * @covers
23
 */
24
final class JiraActivityPluginTest extends TestCase
25
{
26
    public const TICKET_PATTERN = 'TESTNR-1';
27
    public const TESTUSER_EXAMPLE_COM = '[email protected]';
28
    public const TICKET_COMMENT_UPDATED = '2021-01-02 11:00:00';
29
    public const TICKET_COMMENT_BODY = 'test';
30
31
    public function testCanReadEvents(): void
32
    {
33
        $comments = $this->createJiraActivityPlugin()->collect()->wait();
34
        static::assertSame(self::TICKET_PATTERN, $comments->offsetGet(0)->needle);
35
        static::assertSame('Ticket Bearbeitung: TESTNR-1 - test...', $comments->offsetGet(0)->description);
36
        static::assertSame('2021-01-02', $comments->offsetGet(0)->created->format('Y-m-d'));
37
        static::assertSame(JiraActivityPlugin::ACTIVITY_DURATION, $comments->offsetGet(0)->duration);
38
    }
39
40
    private function createJiraActivityPlugin(): JiraActivityPlugin
41
    {
42
        $gitlabClientFacadeMock = $this->getMockBuilder(JiraClientFacade::class)
43
            ->onlyMethods(['getComments'])
44
            ->getMock()
45
        ;
46
47
        $testComment = new Comment();
48
        $testComment->body = self::TICKET_COMMENT_BODY;
49
        $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...
50
51
        $testComments = new \stdClass();
52
        $testComments->comments = [$testComment];
53
        $testAuthor = new Author();
54
        $testAuthor->emailAddress = self::TESTUSER_EXAMPLE_COM;
55
        $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...
56
57
        $gitlabClientFacadeMock
58
            ->method('getComments')
59
            ->willReturn([self::TICKET_PATTERN => [$testComment]])
60
        ;
61
62
        $gitlabActivityPluginMock = $this->getMockBuilder(JiraActivityPlugin::class)
63
            ->onlyMethods(['getFacade'])
64
            ->getMock()
65
        ;
66
        $gitlabActivityPluginMock
67
            ->method('getFacade')
68
            ->willReturn($gitlabClientFacadeMock)
69
        ;
70
71
        return $gitlabActivityPluginMock;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $gitlabActivityPluginMock returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return ForecastAutomation\JiraC...ugin\JiraActivityPlugin.
Loading history...
72
    }
73
}
74