EmailChannelTest::mockTemplateGenerator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 1
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\WriteModel\Quote;
11
use PHPUnit\Framework\MockObject\Rule\InvokedCount;
12
use PHPUnit\Framework\TestCase;
13
use Symfony\Component\Mailer\MailerInterface;
14
15
final class EmailChannelTest extends TestCase
16
{
17
    private const EXAMPLE_EMAIL = '[email protected]';
18
19
    public function test_send(): void
20
    {
21
        $channel = new EmailChannel(
22
            self::EXAMPLE_EMAIL,
23
            $this->mockMailer(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 mockMailer(InvokedCount $invokedCount): MailerInterface
35
    {
36
        $mailer = $this->createMock(MailerInterface::class);
37
        $mailer
38
            ->expects($invokedCount)
39
            ->method('send');
40
41
        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...
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