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

SlackChannelTest::createCompany()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
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