Passed
Push — master ( 7873d0...1233c7 )
by Patrick
03:49 queued 11s
created

MattermostActivityPluginTest::setUp()   A

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
        $testChannel = new \stdClass();
57
        $testChannel->id = 'test-channel-id';
58
59
        $mattermostClientFacadeMock
60
            ->method('getChannel')
61
            ->willReturn($this->guzzleFactoryHelper->createResolvedPromise([$testChannel]));
62
63
        $mattermostClientFacadeMock
64
            ->method('getPosts')
65
            ->willReturn(
66
                $this->guzzleFactoryHelper->createResolvedPromise(
67
                    [
68
                        [
69
                            'message' => 'testmessage ' . self::TICKET_PATTERN . '-1234',
70
                            'create_at' => (new \DateTime())->format('U') * 1000,
71
                        ],
72
                    ]
73
                )
74
            );
75
76
        $mattermostActivityPluginMock = $this->getMockBuilder(MattermostActivityPlugin::class)
77
            ->onlyMethods(['getFacade'])
78
            ->getMock();
79
        $mattermostActivityPluginMock
80
            ->method('getFacade')
81
            ->willReturn($mattermostClientFacadeMock);
82
83
        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...
84
    }
85
}
86