Passed
Push — master ( 3ec735...0b5e67 )
by Chema
01:36 queued 14s
created

OlderWasFoundTest::testInvoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 31
rs 9.7666
c 0
b 0
f 0
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\OlderWasFound;
8
use Chemaclass\StockTicker\Domain\ReadModel\Company;
9
use Chemaclass\StockTicker\Domain\ReadModel\Symbol;
10
use PHPUnit\Framework\TestCase;
11
12
final class OlderWasFoundTest extends TestCase
13
{
14
    private const NEWS = 'the key where the news are';
15
16
    public function testInvoke(): void
17
    {
18
        $foundMoreNews = new OlderWasFound(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