Passed
Push — master ( f32712...07732c )
by Vladislav
04:33 queued 01:39
created

InstrumentInfoTest::testInstrumentInfoResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 17
rs 9.9
1
<?php
2
namespace Carpenstar\ByBitAPI\Derivatives\MarketData\InstrumentInfo\Tests;
3
4
use Carpenstar\ByBitAPI\Core\Builders\ResponseHandlerBuilder;
5
use Carpenstar\ByBitAPI\Core\Enums\EnumOutputMode;
6
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection;
7
use Carpenstar\ByBitAPI\Core\Response\CurlResponseHandler;
8
use Carpenstar\ByBitAPI\Derivatives\MarketData\IndexPriceKline\Response\IndexPriceKlineResponse;
9
use PHPUnit\Framework\TestCase;
10
11
class InstrumentInfoTest extends TestCase
12
{
13
    private static string $indexPriceKlineApiResponse = '{"retCode":0,"retMsg":"","result":{"symbol":"ETHUSDT","category":"linear","list":[["1682935440000","1847.37","1847.65","1847.37","1847.4"],["1682935380000","1847.45","1847.57","1847.36","1847.37"],["1682935320000","1847.65","1847.79","1847.41","1847.45"],["1682935260000","1847.63","1847.66","1847.27","1847.65"],["1682935200000","1847.25","1847.68","1847.25","1847.63"]]},"retExtInfo":{},"time":1684006703286}';
14
15
    public function testInstrumentInfoResponse()
16
    {
17
        $indexPriceKlineData = ResponseHandlerBuilder::make(self::$indexPriceKlineApiResponse,
18
            CurlResponseHandler::class, IndexPriceKlineResponse::class, EnumOutputMode::MODE_ENTITY);
19
20
        $this->assertInstanceOf(EntityCollection::class, $indexPriceKlineData->getBody());
21
22
        $this->assertNotEmpty($indexPriceKlineData->getBody()->count());
23
24
        /** @var IndexPriceKlineResponse $klineItem */
25
        while(!empty($klineItem = $indexPriceKlineData->getBody()->fetch())) {
26
            $this->assertInstanceOf(IndexPriceKlineResponse::class, $klineItem);
27
            $this->assertInstanceOf(\DateTime::class, $klineItem->getStart());
28
            $this->assertIsFloat($klineItem->getOpen());
29
            $this->assertIsFloat($klineItem->getHigh());
30
            $this->assertIsFloat($klineItem->getLow());
31
            $this->assertIsFloat($klineItem->getClose());
32
        }
33
    }
34
}