-
Notifications
You must be signed in to change notification settings - Fork 17
/
ExchangeTest.php
112 lines (90 loc) · 3.16 KB
/
ExchangeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
use Dotenv\Dotenv;
use PHPUnit\Framework\TestCase;
use RadicalLoop\Eod\Config;
use RadicalLoop\Eod\Eod;
use org\bovigo\vfs\vfsStream;
class ExchangeTest extends TestCase
{
protected $exchange; //comment
protected function setUp(): void
{
parent::setUp();
$dotenv = Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();
$apiToken = $_ENV['API_TOKEN'];
$this->exchange = (new Eod(new Config($apiToken)))->exchange();
}
/** @test */
public function url_endpoint()
{
$uri = $this->exchange->getApiUri();
$this->assertSame('https://eodhistoricaldata.com/api/exchanges', $uri);
}
/** @test **/
public function exchange_symbol()
{
$content = $this->exchange->symbol('US')->json();
$data = json_decode($content, true);
$this->assertIsArray($data);
$this->assertCount(7, $data[0]);
$this->assertArrayHasKey('Code', $data[0]);
$this->assertArrayHasKey('Name', $data[0]);
$this->assertArrayHasKey('Country', $data[0]);
$this->assertArrayHasKey('Exchange', $data[0]);
$this->assertArrayHasKey('Currency', $data[0]);
$this->assertArrayHasKey('Type', $data[0]);
$this->assertArrayHasKey('Isin', $data[0]);
}
/** @test **/
public function multiple_ticker()
{
$content = $this->exchange->multipleTicker('US')->json();
$data = json_decode($content, true);
$this->assertTrue(is_array($data));
$this->assertNotEmpty($data);
$this->assertCount(9, $data[0]);
$this->assertArrayHasKey('code', $data[0]);
$this->assertArrayHasKey('exchange_short_name', $data[0]);
$this->assertArrayHasKey('date', $data[0]);
$this->assertArrayHasKey('open', $data[0]);
$this->assertArrayHasKey('high', $data[0]);
$this->assertArrayHasKey('low', $data[0]);
$this->assertArrayHasKey('close', $data[0]);
$this->assertArrayHasKey('adjusted_close', $data[0]);
$this->assertArrayHasKey('volume', $data[0]);
}
/** @test */
public function save_file()
{
$fileName = vfsStream::url('storage/test.csv');
$response = $this->exchange->symbol('US')->save($fileName);
$this->assertTrue($this->root->hasChild('test.csv'));
$content = $this->root->getChild('test.csv')->getContent();
$this->assertNotEmpty($content);
}
/** @test **/
public function details()
{
$content = $this->exchange->details('US')->json();
$data = json_decode($content, true);
$this->assertTrue(is_array($data));
$this->assertNotEmpty($data);
}
/** @test **/
public function it_lists_exchanges()
{
$content = $this->exchange->list('LSE')->json();
$data = json_decode($content, true);
$this->assertIsArray($data);
$this->assertNotEmpty($data);
}
/** @test **/
public function it_lists_delisted_exchanges()
{
$content = $this->exchange->delisted('LSE')->json();
$data = json_decode($content, true);
$this->assertIsArray($data);
$this->assertNotEmpty($data);
}
}