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

QuoteTest::testCompanyName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chemaclass\StockTickerTests\Unit\Domain\WriteModel;
6
7
use Chemaclass\StockTicker\Domain\WriteModel\CompanyName;
8
use Chemaclass\StockTicker\Domain\WriteModel\Currency;
9
use Chemaclass\StockTicker\Domain\WriteModel\MarketCap;
10
use Chemaclass\StockTicker\Domain\WriteModel\News;
11
use Chemaclass\StockTicker\Domain\WriteModel\Quote;
12
use Chemaclass\StockTicker\Domain\WriteModel\RegularMarketChange;
13
use Chemaclass\StockTicker\Domain\WriteModel\RegularMarketChangePercent;
14
use Chemaclass\StockTicker\Domain\WriteModel\RegularMarketPrice;
15
use Chemaclass\StockTicker\Domain\WriteModel\Trend;
16
use PHPUnit\Framework\TestCase;
17
18
final class QuoteTest extends TestCase
19
{
20
    private Quote $quote;
21
22
    protected function setUp(): void
23
    {
24
        $this->quote = (new Quote())->fromArray([
25
            'symbol' => 'AMZN',
26
            'companyName' => [
27
                'shortName' => 'Short Company name, Inc.',
28
                'longName' => 'Long Company name, Inc.',
29
            ],
30
            'currency' => [
31
                'currency' => 'USD',
32
                'symbol' => '$',
33
            ],
34
            'url' => 'https://example.url.com',
35
            'regularMarketPrice' => [
36
                'raw' => 629.999,
37
                'fmt' => '629.99',
38
            ],
39
            'regularMarketChange' => [
40
                'raw' => -3.2900085,
41
                'fmt' => '-3.29',
42
            ],
43
            'regularMarketChangePercent' => [
44
                'raw' => -1.8199171,
45
                'fmt' => '-1.82%',
46
            ],
47
            'marketCap' => [
48
                'raw' => 797834477568,
49
                'fmt' => '797.834B',
50
                'longFmt' => '797,834,477,568',
51
            ],
52
            'lastTrend' => [
53
                [
54
                    'period' => '0m',
55
                    'strongBuy' => 11,
56
                    'buy' => 12,
57
                    'hold' => 13,
58
                    'sell' => 14,
59
                    'strongSell' => 15,
60
                ],
61
                [
62
                    'period' => '-1m',
63
                    'strongBuy' => 21,
64
                    'buy' => 22,
65
                    'hold' => 23,
66
                    'sell' => 24,
67
                    'strongSell' => 25,
68
                ],
69
            ],
70
            'latestNews' => [
71
                [
72
                    'datetime' => 'example datetime',
73
                    'timezone' => 'example timezone',
74
                    'url' => 'example url',
75
                    'title' => 'example title',
76
                    'summary' => 'example summary',
77
                ],
78
            ],
79
        ]);
80
    }
81
82
    public function testCompanyName(): void
83
    {
84
        self::assertEquals(
85
            (new CompanyName())
86
                ->setShortName('Short Company name, Inc.')
87
                ->setLongName('Long Company name, Inc.'),
88
            $this->quote->getCompanyName()
89
        );
90
    }
91
92
    public function testSymbol(): void
93
    {
94
        self::assertEquals('AMZN', $this->quote->getSymbol());
95
    }
96
97
    public function testCurrency(): void
98
    {
99
        self::assertEquals(
100
            (new Currency())
101
                ->setSymbol('$')
102
                ->setCurrency('USD'),
103
            $this->quote->getCurrency()
104
        );
105
    }
106
107
    public function testUrl(): void
108
    {
109
        self::assertEquals('https://example.url.com', $this->quote->getUrl());
110
    }
111
112
    public function testRegularMarketPrice(): void
113
    {
114
        self::assertEquals(
115
            (new RegularMarketPrice())
116
                ->setFmt('629.99')
117
                ->setRaw(629.999),
118
            $this->quote->getRegularMarketPrice()
119
        );
120
    }
121
122
    public function testRegularMarketChange(): void
123
    {
124
        self::assertEquals(
125
            (new RegularMarketChange())
126
                ->setFmt('-3.29')
127
                ->setRaw(-3.2900085),
128
            $this->quote->getRegularMarketChange()
129
        );
130
    }
131
132
    public function testRegularMarketChangePercent(): void
133
    {
134
        self::assertEquals(
135
            (new RegularMarketChangePercent())
136
                ->setFmt('-1.82%')
137
                ->setRaw(-1.8199171),
138
            $this->quote->getRegularMarketChangePercent()
139
        );
140
    }
141
142
    public function testMarketCap(): void
143
    {
144
        self::assertEquals(
145
            (new MarketCap())
146
                ->setRaw(797834477568)
147
                ->setFmt('797.834B')
148
                ->setLongFmt('797,834,477,568'),
149
            $this->quote->getMarketCap()
150
        );
151
    }
152
153
    public function testLastTrend(): void
154
    {
155
        self::assertEquals([
156
            (new Trend())
157
                ->setPeriod('0m')
158
                ->setStrongBuy(11)
159
                ->setBuy(12)
160
                ->setHold(13)
161
                ->setSell(14)
162
                ->setStrongSell(15),
163
            (new Trend())
164
                ->setPeriod('-1m')
165
                ->setStrongBuy(21)
166
                ->setBuy(22)
167
                ->setHold(23)
168
                ->setSell(24)
169
                ->setStrongSell(25),
170
        ], $this->quote->getLastTrend());
171
    }
172
173
    public function testLatestNews(): void
174
    {
175
        self::assertEquals([
176
            (new News())
177
                ->setDatetime('example datetime')
178
                ->setTimezone('example timezone')
179
                ->setUrl('example url')
180
                ->setTitle('example title')
181
                ->setSummary('example summary'),
182
        ], $this->quote->getLatestNews());
183
    }
184
}
185