|
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
|
|
|
'publisher' => 'example publisher', |
|
78
|
|
|
'source' => 'example source', |
|
79
|
|
|
'images' => [ |
|
80
|
|
|
[ |
|
81
|
|
|
'url' => 'example.img.url', |
|
82
|
|
|
], |
|
83
|
|
|
], |
|
84
|
|
|
], |
|
85
|
|
|
], |
|
86
|
|
|
]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function test_company_name(): void |
|
90
|
|
|
{ |
|
91
|
|
|
self::assertEquals( |
|
92
|
|
|
(new CompanyName()) |
|
93
|
|
|
->setShortName('Short Company name, Inc.') |
|
94
|
|
|
->setLongName('Long Company name, Inc.'), |
|
95
|
|
|
$this->quote->getCompanyName(), |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function test_symbol(): void |
|
100
|
|
|
{ |
|
101
|
|
|
self::assertEquals('AMZN', $this->quote->getSymbol()); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function test_currency(): void |
|
105
|
|
|
{ |
|
106
|
|
|
self::assertEquals( |
|
107
|
|
|
(new Currency()) |
|
108
|
|
|
->setSymbol('$') |
|
109
|
|
|
->setCurrency('USD'), |
|
110
|
|
|
$this->quote->getCurrency(), |
|
111
|
|
|
); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function test_url(): void |
|
115
|
|
|
{ |
|
116
|
|
|
self::assertEquals('https://example.url.com', $this->quote->getUrl()); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function test_regular_market_price(): void |
|
120
|
|
|
{ |
|
121
|
|
|
self::assertEquals( |
|
122
|
|
|
(new RegularMarketPrice()) |
|
123
|
|
|
->setFmt('629.99') |
|
124
|
|
|
->setRaw(629.999), |
|
125
|
|
|
$this->quote->getRegularMarketPrice(), |
|
126
|
|
|
); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function test_regular_market_change(): void |
|
130
|
|
|
{ |
|
131
|
|
|
self::assertEquals( |
|
132
|
|
|
(new RegularMarketChange()) |
|
133
|
|
|
->setFmt('-3.29') |
|
134
|
|
|
->setRaw(-3.2900085), |
|
135
|
|
|
$this->quote->getRegularMarketChange(), |
|
136
|
|
|
); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function test_regular_market_change_percent(): void |
|
140
|
|
|
{ |
|
141
|
|
|
self::assertEquals( |
|
142
|
|
|
(new RegularMarketChangePercent()) |
|
143
|
|
|
->setFmt('-1.82%') |
|
144
|
|
|
->setRaw(-1.8199171), |
|
145
|
|
|
$this->quote->getRegularMarketChangePercent(), |
|
146
|
|
|
); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function test_market_cap(): void |
|
150
|
|
|
{ |
|
151
|
|
|
self::assertEquals( |
|
152
|
|
|
(new MarketCap()) |
|
153
|
|
|
->setRaw(797834477568) |
|
154
|
|
|
->setFmt('797.834B') |
|
155
|
|
|
->setLongFmt('797,834,477,568'), |
|
156
|
|
|
$this->quote->getMarketCap(), |
|
157
|
|
|
); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public function test_last_trend(): void |
|
161
|
|
|
{ |
|
162
|
|
|
self::assertEquals([ |
|
163
|
|
|
(new Trend()) |
|
164
|
|
|
->setPeriod('0m') |
|
165
|
|
|
->setStrongBuy(11) |
|
166
|
|
|
->setBuy(12) |
|
167
|
|
|
->setHold(13) |
|
168
|
|
|
->setSell(14) |
|
169
|
|
|
->setStrongSell(15), |
|
170
|
|
|
(new Trend()) |
|
171
|
|
|
->setPeriod('-1m') |
|
172
|
|
|
->setStrongBuy(21) |
|
173
|
|
|
->setBuy(22) |
|
174
|
|
|
->setHold(23) |
|
175
|
|
|
->setSell(24) |
|
176
|
|
|
->setStrongSell(25), |
|
177
|
|
|
], $this->quote->getLastTrend()); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
public function test_latest_news(): void |
|
181
|
|
|
{ |
|
182
|
|
|
self::assertEquals([ |
|
183
|
|
|
(new News()) |
|
184
|
|
|
->setDatetime('example datetime') |
|
185
|
|
|
->setTimezone('example timezone') |
|
186
|
|
|
->setUrl('example url') |
|
187
|
|
|
->setTitle('example title') |
|
188
|
|
|
->setPublisher('example publisher') |
|
189
|
|
|
->setSource('example source') |
|
190
|
|
|
->setSummary('example summary') |
|
191
|
|
|
->setImages([ |
|
192
|
|
|
[ |
|
193
|
|
|
'url' => 'example.img.url', |
|
194
|
|
|
], |
|
195
|
|
|
]), |
|
196
|
|
|
], $this->quote->getLatestNews()); |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|