MattermostActivityPluginTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
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\MattermostClient\Shared\Plugin;
13
14
use ForecastAutomation\MattermostClient\MattermostClientFacade;
15
use ForecastAutomation\MattermostClient\Shared\Plugin\MattermostActivityPlugin;
16
use ForecastAutomationTests\GuzzleClient\Shared\GuzzleFactoryHelper;
17
use PHPUnit\Framework\TestCase;
18
19
/**
20
 * @internal
21
 * @covers
22
 */
23
final class MattermostActivityPluginTest extends TestCase
24
{
25
    public const TICKET_PATTERN = 'TESTNR';
26
27
    private GuzzleFactoryHelper $guzzleFactoryHelper;
28
29
    protected function setUp(): void
30
    {
31
        $this->guzzleFactoryHelper = new GuzzleFactoryHelper();
32
    }
33
34
    public function testCanReadEvents(): void
35
    {
36
        $_ENV['MATTERMOST_PATTERN'] = self::TICKET_PATTERN;
37
        $activityDtoCollection = $this->createMattermostActivityPlugin()->collect()->wait();
38
        static::assertSame(self::TICKET_PATTERN.'-1234', $activityDtoCollection->offsetGet(0)->needle);
39
        static::assertSame(
40
            MattermostActivityPlugin::POST_SUFFIX.': TESTNR-1234',
41
            $activityDtoCollection->offsetGet(0)->description
42
        );
43
        static::assertSame(
44
            (new \DateTime())->format('Y-m-d'),
45
            $activityDtoCollection->offsetGet(0)->created->format('Y-m-d')
46
        );
47
        static::assertSame(MattermostActivityPlugin::ACTIVITY_DURATION, $activityDtoCollection->offsetGet(0)->duration);
48
    }
49
50
    private function createMattermostActivityPlugin(): MattermostActivityPlugin
51
    {
52
        $mattermostClientFacadeMock = $this->getMockBuilder(MattermostClientFacade::class)
53
            ->onlyMethods(['getChannel', 'getPosts'])
54
            ->getMock()
55
        ;
56
57
        $testChannel = new \stdClass();
58
        $testChannel->id = 'test-channel-id';
59
60
        $mattermostClientFacadeMock
61
            ->method('getChannel')
62
            ->willReturn($this->guzzleFactoryHelper->createResolvedPromise([$testChannel]))
63
        ;
64
65
        $mattermostClientFacadeMock
66
            ->method('getPosts')
67
            ->willReturn(
68
                $this->guzzleFactoryHelper->createResolvedPromise(
69
                    [
70
                        [
71
                            'message' => 'testmessage '.self::TICKET_PATTERN.'-1234',
72
                            'create_at' => (new \DateTime())->format('U') * 1000,
73
                        ],
74
                    ]
75
                )
76
            )
77
        ;
78
79
        $mattermostActivityPluginMock = $this->getMockBuilder(MattermostActivityPlugin::class)
80
            ->onlyMethods(['getFacade'])
81
            ->getMock()
82
        ;
83
        $mattermostActivityPluginMock
84
            ->method('getFacade')
85
            ->willReturn($mattermostClientFacadeMock)
86
        ;
87
88
        return $mattermostActivityPluginMock;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $mattermostActivityPluginMock returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return ForecastAutomation\Matte...attermostActivityPlugin.
Loading history...
89
    }
90
}
91