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

EmailChannelTest::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\Email;
6
7
use Chemaclass\StockTicker\Domain\Notifier\Channel\Email\EmailChannel;
8
use Chemaclass\StockTicker\Domain\Notifier\Channel\TemplateGeneratorInterface;
9
use Chemaclass\StockTicker\Domain\Notifier\NotifyResult;
10
use Chemaclass\StockTicker\Domain\ReadModel\Company;
11
use Chemaclass\StockTicker\Domain\ReadModel\Symbol;
12
use PHPUnit\Framework\MockObject\Rule\InvokedCount;
13
use PHPUnit\Framework\TestCase;
14
use Symfony\Component\Mailer\MailerInterface;
15
16
final class EmailChannelTest extends TestCase
17
{
18
    private const EXAMPLE_EMAIL = '[email protected]';
19
20
    public function testSend(): void
21
    {
22
        $channel = new EmailChannel(
23
            self::EXAMPLE_EMAIL,
24
            $this->mockMailer(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 mockMailer(InvokedCount $invokedCount): MailerInterface
36
    {
37
        $mailer = $this->createMock(MailerInterface::class);
38
        $mailer
39
            ->expects($invokedCount)
40
            ->method('send');
41
42
        return $mailer;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $mailer returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Symfony\Component\Mailer\MailerInterface.
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