Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KerryJones committed Jul 28, 2024
1 parent 1126273 commit d45bf4d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/ClientBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ protected function async($method, array $arguments = []): PromiseInterface
* @throws GuzzleException
* @throws ApiException
*/
public function execute($method, array $arguments = ['format' => 'json']): object
public function execute($method, array $arguments = []): object
{
try {
$format = array_key_exists('format', $arguments) ? $arguments['format'] : 'json';
$response = $this->guzzle->get($method, [
'headers' => $this->headers($arguments['format']),
'headers' => $this->headers($format),
'query' => $arguments,
]);
} catch (\GuzzleHttp\Exception\ClientException $e) {
Expand All @@ -70,7 +71,7 @@ public function execute($method, array $arguments = ['format' => 'json']): objec
};
}

switch ($arguments['format']) {
switch ($format) {
case 'csv':
case 'html':
$object_response = (object)array(
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/IndicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,28 @@ public function testCandles_fromTo_success()
}
}


/**
* @throws GuzzleException|ApiException
*/
public function testCandles_csv_success()
{
$mocked_response = "s, c, h, l, o, t\r\n";
$this->setMockResponses([new Response(200, [], $mocked_response)]);

$response = $this->client->indices->candles(
symbol: "DJI",
from: '2022-09-01',
to: '2022-09-05',
resolution: 'D',
parameters: new Parameters(format: Format::CSV)
);

// Verify that the response is an object of the correct type.
$this->assertInstanceOf(Candles::class, $response);
$this->assertEquals($mocked_response, $response->getCsv());
}

/**
* @throws GuzzleException
*/
Expand Down Expand Up @@ -229,6 +251,8 @@ public function testCandles_noDataNextTimePrevTime_success()
// Verify that the response is an object of the correct type.
$this->assertInstanceOf(Candles::class, $response);
$this->assertEmpty($response->candles);
$this->assertFalse($response->isCsv());
$this->assertFalse($response->isHtml());
$this->assertEquals($mocked_response['s'], $response->status);
$this->assertEquals(Carbon::parse($mocked_response['nextTime']), $response->next_time);
$this->assertEquals(Carbon::parse($mocked_response['prevTime']), $response->next_time);
Expand Down

0 comments on commit d45bf4d

Please sign in to comment.