ActivityFacadeTest::createActivityFacade()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 26
nc 1
nop 0
dl 0
loc 41
rs 9.504
c 0
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\Activity;
13
14
use ForecastAutomation\Activity\ActivityFacade;
15
use ForecastAutomation\Activity\ActivityFactory;
16
use ForecastAutomation\Activity\Shared\Dto\ActivityDto;
17
use ForecastAutomation\Activity\Shared\Dto\ActivityDtoCollection;
18
use ForecastAutomation\Activity\Shared\Plugin\ActivityPluginCollection;
19
use ForecastAutomation\Activity\Shared\Plugin\ActivityPluginInterface;
20
use ForecastAutomationTests\GuzzleClient\Shared\GuzzleFactoryHelper;
21
use PHPUnit\Framework\TestCase;
22
23
/**
24
 * @internal
25
 * @covers
26
 */
27
final class ActivityFacadeTest extends TestCase
28
{
29
    public const TEST_NEEDLE_1 = 'testNeedle1';
30
    public const TEST_DESCRIPTION = 'testDescription';
31
    public const TEST_CREATED = '2021-01-01 00:00:01';
32
    public const TEST_DURATION = 100;
33
34
    private GuzzleFactoryHelper $guzzleFactoryHelper;
35
36
    protected function setUp(): void
37
    {
38
        $this->guzzleFactoryHelper = new GuzzleFactoryHelper();
39
    }
40
41
    public function testCanCollectActivityFromPlugins(): void
42
    {
43
        $activityDto = $this->createActivityFacade()->collect()->current();
44
        static::assertSame(self::TEST_NEEDLE_1, $activityDto->needle);
45
        static::assertSame(self::TEST_DESCRIPTION, $activityDto->description);
46
        static::assertSame(self::TEST_DURATION, $activityDto->duration);
47
    }
48
49
    private function createActivityFacade(): ActivityFacade
50
    {
51
        $activityPluginMock = $this->getMockBuilder(ActivityPluginInterface::class)
52
            ->onlyMethods(['collect'])
53
            ->getMock()
54
        ;
55
        $activityPluginMock
56
            ->method('collect')
57
            ->willReturn(
58
                $this->guzzleFactoryHelper->createResolvedPromise(
59
                    new ActivityDtoCollection(
60
                        new ActivityDto(
61
                            self::TEST_NEEDLE_1,
62
                            self::TEST_DESCRIPTION,
63
                            new \DateTime(self::TEST_CREATED),
64
                            self::TEST_DURATION
65
                        )
66
                    )
67
                )
68
            )
69
        ;
70
71
        $activityFactoryMock = $this->getMockBuilder(ActivityFactory::class)
72
            ->onlyMethods(['getActivityPlugins'])
73
            ->getMock()
74
        ;
75
        $activityFactoryMock
76
            ->method('getActivityPlugins')
77
            ->willReturn(new ActivityPluginCollection($activityPluginMock))
78
        ;
79
80
        $activityFacadeMock = $this->getMockBuilder(ActivityFacade::class)
81
            ->onlyMethods(['getFactory'])
82
            ->getMock()
83
        ;
84
        $activityFacadeMock
85
            ->method('getFactory')
86
            ->willReturn($activityFactoryMock)
87
        ;
88
89
        return $activityFacadeMock;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $activityFacadeMock returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return ForecastAutomation\Activity\ActivityFacade.
Loading history...
90
    }
91
}
92