SlackChannelTest::test_send()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chemaclass\StockTickerTests\Unit\Domain\Notifier\Channel\Slack;
6
7
use Chemaclass\StockTicker\Domain\Notifier\Channel\Slack\SlackChannel;
8
use Chemaclass\StockTicker\Domain\Notifier\Channel\Slack\SlackClientInterface;
9
use Chemaclass\StockTicker\Domain\Notifier\Channel\TemplateGeneratorInterface;
10
use Chemaclass\StockTicker\Domain\Notifier\NotifyResult;
11
use Chemaclass\StockTicker\Domain\WriteModel\Quote;
12
use PHPUnit\Framework\MockObject\Rule\InvokedCount;
13
use PHPUnit\Framework\TestCase;
14
15
final class SlackChannelTest extends TestCase
16
{
17
    private const EXAMPLE_SLACK_DESTINY_CHANNEL_ID = 'SLACK_DESTINY_CHANNEL_ID';
18
19
    public function test_send(): void
20
    {
21
        $channel = new SlackChannel(
22
            self::EXAMPLE_SLACK_DESTINY_CHANNEL_ID,
23
            $this->mockSlackClient(self::once()),
24
            $this->mockTemplateGenerator(self::once()),
25
        );
26
27
        $notifyResult = (new NotifyResult())
28
            ->add($this->createCompany('1'), ['condition name 1'])
29
            ->add($this->createCompany('2'), ['condition name 1']);
30
31
        $channel->send($notifyResult);
32
    }
33
34
    private function mockSlackClient(InvokedCount $invokedCount): SlackClientInterface
35
    {
36
        $SlackClient = $this->createMock(SlackClientInterface::class);
37
        $SlackClient
38
            ->expects($invokedCount)
39
            ->method('postToChannel');
40
41
        return $SlackClient;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $SlackClient returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Chemaclass\StockTicker\D...ck\SlackClientInterface.
Loading history...
42
    }
43
44
    private function mockTemplateGenerator(InvokedCount $invokedCount): TemplateGeneratorInterface
45
    {
46
        $templateGenerator = $this->createMock(TemplateGeneratorInterface::class);
47
        $templateGenerator
48
            ->expects($invokedCount)
49
            ->method('generateHtml');
50
51
        return $templateGenerator;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $templateGenerator returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Chemaclass\StockTicker\D...plateGeneratorInterface.
Loading history...
52
    }
53
54
    private function createCompany(string $symbol): Quote
55
    {
56
        return (new Quote())
57
            ->setSymbol($symbol);
58
    }
59
}
60