Passed
Push — master ( c0f32c...e879f4 )
by Chema
04:17 queued 41s
created

RecentNewsWasFoundTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 29
c 0
b 0
f 0
dl 0
loc 44
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createCompanyWithNews() 0 5 1
A testInvoke() 0 35 1
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\RecentNewsWasFound;
8
use Chemaclass\StockTicker\Domain\WriteModel\News;
9
use Chemaclass\StockTicker\Domain\WriteModel\Quote;
10
use PHPUnit\Framework\TestCase;
11
12
final class RecentNewsWasFoundTest extends TestCase
13
{
14
    public function testInvoke(): void
15
    {
16
        $foundMoreNews = new RecentNewsWasFound();
17
18
        $company = $this->createCompanyWithNews([
19
            (new News())
20
                ->setTitle('the first article will be consider new')
21
                ->setDatetime('2020-10-02 02:00'),
22
            (new News())
23
                ->setTitle('another article on the first round, but with an older datetime')
24
                ->setDatetime('2019-01-01 00:00'),
25
        ]);
26
        self::assertTrue($foundMoreNews($company));
27
28
        $company = $this->createCompanyWithNews([
29
            (new News())
30
                ->setTitle('it has an older datetime, so it wont be consider new')
31
                ->setDatetime('2020-10-01 02:00'),
32
        ]);
33
        self::assertFalse($foundMoreNews($company));
34
35
        $company = $this->createCompanyWithNews([
36
            (new News())
37
                ->setTitle('it has an latest datetime, so it will be consider as new')
38
                ->setDatetime('2020-10-03 02:00'),
39
        ]);
40
        self::assertTrue($foundMoreNews($company));
41
42
        $company = (new Quote())
43
            ->setLatestNews([
44
                (new News())
45
                    ->setTitle('it has an latest datetime but no symbol in this quote, so it wont be processed')
46
                    ->setDatetime('2020-10-04 02:00'),
47
            ]);
48
        self::assertFalse($foundMoreNews($company));
49
    }
50
51
    private function createCompanyWithNews(array $news): Quote
52
    {
53
        return (new Quote())
54
            ->setSymbol('SYMBOL')
55
            ->setLatestNews($news);
56
    }
57
}
58