|
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\MoreNewsWasFound; |
|
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
|
|
|
private const NEWS = 'the-key-for-news'; |
|
15
|
|
|
|
|
16
|
|
|
public function testInvoke(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$foundMoreNews = new MoreNewsWasFound(self::NEWS); |
|
19
|
|
|
|
|
20
|
|
|
$company = $this->createCompanyWithNews([ |
|
21
|
|
|
[ |
|
22
|
|
|
'title' => 'the first article will be consider new', |
|
23
|
|
|
'datetime' => '2020-6-15 02:00', |
|
24
|
|
|
], |
|
25
|
|
|
[ |
|
26
|
|
|
'title' => 'another article on the first round, but with an older datetime', |
|
27
|
|
|
'datetime' => '2020-1-01 00:00', |
|
28
|
|
|
], |
|
29
|
|
|
]); |
|
30
|
|
|
self::assertTrue($foundMoreNews($company)); |
|
31
|
|
|
|
|
32
|
|
|
$company = $this->createCompanyWithNews([ |
|
33
|
|
|
[ |
|
34
|
|
|
'title' => 'it has an older datetime, so it wont be consider new', |
|
35
|
|
|
'datetime' => '2020-2-19 01:00', |
|
36
|
|
|
], |
|
37
|
|
|
]); |
|
38
|
|
|
self::assertFalse($foundMoreNews($company)); |
|
39
|
|
|
|
|
40
|
|
|
$company = $this->createCompanyWithNews([ |
|
41
|
|
|
[ |
|
42
|
|
|
'title' => 'it has an older date than the first article, so it is consider new', |
|
43
|
|
|
'datetime' => '2020-7-18 03:00', |
|
44
|
|
|
], |
|
45
|
|
|
]); |
|
46
|
|
|
self::assertTrue($foundMoreNews($company)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
private function createCompanyWithNews(array $news): Company |
|
50
|
|
|
{ |
|
51
|
|
|
return new Company( |
|
52
|
|
|
Symbol::fromString('SYMBOL'), |
|
53
|
|
|
[ |
|
54
|
|
|
self::NEWS => $news, |
|
55
|
|
|
] |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|