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; |
|
|
|
|
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; |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function createCompany(string $symbol): Quote |
55
|
|
|
{ |
56
|
|
|
return (new Quote()) |
57
|
|
|
->setSymbol($symbol); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|