|
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 PHPUnit\Framework\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @internal |
|
20
|
|
|
* @covers |
|
21
|
|
|
*/ |
|
22
|
|
|
final class MattermostActivityPluginTest extends TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
public const TICKET_PATTERN = 'TESTNR'; |
|
25
|
|
|
|
|
26
|
|
|
public function testCanReadEvents(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$_ENV['MATTERMOST_PATTERN'] = self::TICKET_PATTERN; |
|
29
|
|
|
$activityDtoCollection = $this->createMattermostActivityPlugin()->collect(); |
|
30
|
|
|
static::assertSame(self::TICKET_PATTERN.'-1234', $activityDtoCollection->offsetGet(0)->needle); |
|
31
|
|
|
static::assertSame(MattermostActivityPlugin::POST_SUFFIX.': TESTNR-1234', $activityDtoCollection->offsetGet(0)->description); |
|
32
|
|
|
static::assertSame((new \DateTime())->format('Y-m-d'), $activityDtoCollection->offsetGet(0)->created->format('Y-m-d')); |
|
33
|
|
|
static::assertSame(MattermostActivityPlugin::ACTIVITY_DURATION, $activityDtoCollection->offsetGet(0)->duration); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
private function createMattermostActivityPlugin(): MattermostActivityPlugin |
|
37
|
|
|
{ |
|
38
|
|
|
$mattermostClientFacadeMock = $this->getMockBuilder(MattermostClientFacade::class) |
|
39
|
|
|
->onlyMethods(['getChannel', 'getPosts']) |
|
40
|
|
|
->getMock() |
|
41
|
|
|
; |
|
42
|
|
|
|
|
43
|
|
|
$testChannel = new \stdClass(); |
|
44
|
|
|
$testChannel->id = 'test-channel-id'; |
|
45
|
|
|
|
|
46
|
|
|
$mattermostClientFacadeMock |
|
47
|
|
|
->method('getChannel') |
|
48
|
|
|
->willReturn([$testChannel]) |
|
49
|
|
|
; |
|
50
|
|
|
$mattermostClientFacadeMock |
|
51
|
|
|
->method('getPosts') |
|
52
|
|
|
->willReturn([['message' => 'testmessage '.self::TICKET_PATTERN.'-1234', 'create_at' => (new \DateTime())->format('U') * 1000]]) |
|
53
|
|
|
; |
|
54
|
|
|
|
|
55
|
|
|
$mattermostActivityPluginMock = $this->getMockBuilder(MattermostActivityPlugin::class) |
|
56
|
|
|
->onlyMethods(['getFacade']) |
|
57
|
|
|
->getMock() |
|
58
|
|
|
; |
|
59
|
|
|
$mattermostActivityPluginMock |
|
60
|
|
|
->method('getFacade') |
|
61
|
|
|
->willReturn($mattermostClientFacadeMock) |
|
62
|
|
|
; |
|
63
|
|
|
|
|
64
|
|
|
return $mattermostActivityPluginMock; |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|