GitlabActivityPluginTest::testCanReadEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
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 8
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\Shared\Plugin;
13
14
use ForecastAutomation\GitlabClient\GitlabClientFacade;
15
use ForecastAutomation\GitlabClient\Shared\Plugin\GitlabActivityPlugin;
16
use PHPUnit\Framework\TestCase;
17
18
/**
19
 * @internal
20
 * @covers
21
 */
22
final class GitlabActivityPluginTest extends TestCase
23
{
24
    public const TICKET_PATTERN = 'TESTNR';
25
26
    public function testCanReadEvents(): void
27
    {
28
        $_ENV['GITLAB_PATTERN'] = self::TICKET_PATTERN;
29
        $activityDtoCollection = $this->createGitlabActivityPlugin()->collect()->wait();
30
        static::assertSame(self::TICKET_PATTERN.'-1234', $activityDtoCollection->offsetGet(0)->needle);
31
        static::assertSame('Entwicklungsprozess: TESTNR-1234 (commented on)', $activityDtoCollection->offsetGet(0)->description);
32
        static::assertSame('2021-01-01', $activityDtoCollection->offsetGet(0)->created->format('Y-m-d'));
33
        static::assertSame(GitlabActivityPlugin::ACTIVITY_DURATION, $activityDtoCollection->offsetGet(0)->duration);
34
    }
35
36
    private function createGitlabActivityPlugin(): GitlabActivityPlugin
37
    {
38
        $gitlabClientFacadeMock = $this->getMockBuilder(GitlabClientFacade::class)
39
            ->onlyMethods(['getEvents'])
40
            ->getMock()
41
        ;
42
43
        $testEvent1 = new \stdClass();
44
        $testEvent1->target_title = self::TICKET_PATTERN.'-1234';
45
        $testEvent1->action_name = GitlabActivityPlugin::ALLOWED_ACTION_NAMES[0];
46
        $testEvent1->created_at = '2021-01-01 00:00:00';
47
48
        $gitlabClientFacadeMock
49
            ->method('getEvents')
50
            ->willReturn(['event1' => $testEvent1])
51
        ;
52
53
        $gitlabActivityPluginMock = $this->getMockBuilder(GitlabActivityPlugin::class)
54
            ->onlyMethods(['getFacade'])
55
            ->getMock()
56
        ;
57
        $gitlabActivityPluginMock
58
            ->method('getFacade')
59
            ->willReturn($gitlabClientFacadeMock)
60
        ;
61
62
        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\Gitla...in\GitlabActivityPlugin.
Loading history...
63
    }
64
}
65