forked from radicalloop/eodhistoricaldata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExchangeTest.php
77 lines (64 loc) · 2.33 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
<?php
use PHPUnit\Framework\TestCase;
use RadicalLoop\Eod\Config;
use RadicalLoop\Eod\Eod;
use org\bovigo\vfs\vfsStream;
class ExchangeTest extends TestCase
{
protected $exchange; //comment
private $root;
protected function setUp()
{
parent::setUp();
$this->root = vfsStream::setup('storage');
$apiToken = getenv('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->assertInternalType('array', $data);
$this->assertNotEmpty($data);
$this->assertCount(5, $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]);
}
/** @test **/
public function multiple_ticker()
{
$content = $this->exchange->multipleTicker('US')->json();
$data = json_decode($content, true);
$this->assertInternalType('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);
}
}