| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace Chemaclass\StockTickerTests\Unit\Domain\Notifier\Policy\Condition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Chemaclass\StockTicker\Domain\Notifier\Policy\Condition\FoundMoreNews; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Chemaclass\StockTicker\Domain\ReadModel\Company; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Chemaclass\StockTicker\Domain\ReadModel\Symbol; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | final class FoundMoreNewsTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     public function testInvoke(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         $foundMoreNews = new FoundMoreNews(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $company = $this->createCompanyWithNews([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |                 'title' => 'the first article will be consider new', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |                 'datetime' => '2020-6-15 02:00', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |                 'title' => 'another article on the first round, but with an older datetime', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |                 'datetime' => '2020-1-01 00:00', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         self::assertTrue($foundMoreNews($company)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $company = $this->createCompanyWithNews([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                 'title' => 'it has an older datetime, so it wont be consider new', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                 'datetime' => '2020-2-19 01:00', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         self::assertFalse($foundMoreNews($company)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $company = $this->createCompanyWithNews([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                 'title' => 'it has an older date than the first article, so it is consider new', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 'datetime' => '2020-7-18 03:00', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         self::assertTrue($foundMoreNews($company)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     private function createCompanyWithNews(array $news): Company | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         return new Company( | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             Symbol::fromString('SYMBOL'), | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             [ | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |                 FoundMoreNews::NEWS => $news, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |  |