Passed
Push — master ( 3ec735...0b5e67 )
by Chema
01:36 queued 14s
created

SlackChannelTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testSend() 0 13 1
A mockTemplateGenerator() 0 8 1
A mockSlackClient() 0 8 1
A createCompany() 0 5 1
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\ReadModel\Company;
12
use Chemaclass\StockTicker\Domain\ReadModel\Symbol;
13
use PHPUnit\Framework\MockObject\Rule\InvokedCount;
14
use PHPUnit\Framework\TestCase;
15
16
final class SlackChannelTest extends TestCase
17
{
18
    private const EXAMPLE_SLACK_DESTINY_CHANNEL_ID = 'SLACK_DESTINY_CHANNEL_ID';
19
20
    public function testSend(): void
21
    {
22
        $channel = new SlackChannel(
23
            self::EXAMPLE_SLACK_DESTINY_CHANNEL_ID,
24
            $this->mockSlackClient(self::once()),
25
            $this->mockTemplateGenerator(self::once())
26
        );
27
28
        $notifyResult = (new NotifyResult())
29
            ->add($this->createCompany('1'), ['condition name 1'])
30
            ->add($this->createCompany('2'), ['condition name 1']);
31
32
        $channel->send($notifyResult);
33
    }
34
35
    private function mockSlackClient(InvokedCount $invokedCount): SlackClientInterface
36
    {
37
        $SlackClient = $this->createMock(SlackClientInterface::class);
38
        $SlackClient
39
            ->expects($invokedCount)
40
            ->method('postToChannel');
41
42
        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...
43
    }
44
45
    private function mockTemplateGenerator(InvokedCount $invokedCount): TemplateGeneratorInterface
46
    {
47
        $templateGenerator = $this->createMock(TemplateGeneratorInterface::class);
48
        $templateGenerator
49
            ->expects($invokedCount)
50
            ->method('generateHtml');
51
52
        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...
53
    }
54
55
    private function createCompany(string $symbol): Company
56
    {
57
        return new Company(
58
            Symbol::fromString($symbol),
59
            ['key1' => 'value 1']
60
        );
61
    }
62
}
63