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

OlderWasFoundTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 43
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createCompanyWithNews() 0 6 1
A testInvoke() 0 31 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\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