Passed
Push — master ( 20d3fa...58226a )
by Patrick
03:16 queued 13s
created

GitlabActivityPluginTest::testCanReadEvents()   A

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