| 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; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |  |