Test Failed
Pull Request — master (#13)
by Vladislav
09:26 queued 01:13
created

KlineTest::testBuildResponseData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 20
rs 9.7998
c 0
b 0
f 0
1
<?php
2
namespace Carpenstar\ByBitAPI\Spot\MarketData\Kline\Tests;
3
4
use Carpenstar\ByBitAPI\BybitAPI;
5
use Carpenstar\ByBitAPI\Core\Builders\ResponseDtoBuilder;
6
use Carpenstar\ByBitAPI\Core\Builders\ResponseHandlerBuilder;
7
use Carpenstar\ByBitAPI\Core\Builders\RestBuilder;
8
use Carpenstar\ByBitAPI\Core\Enums\EnumIntervals;
9
use Carpenstar\ByBitAPI\Core\Enums\EnumOutputMode;
10
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection;
11
use Carpenstar\ByBitAPI\Core\Response\CurlResponseDto;
0 ignored issues
show
Bug introduced by
The type Carpenstar\ByBitAPI\Core\Response\CurlResponseDto was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Carpenstar\ByBitAPI\Core\Response\CurlResponseHandler;
13
use Carpenstar\ByBitAPI\Spot\MarketData\Kline\Kline;
14
use Carpenstar\ByBitAPI\Spot\MarketData\Kline\Overrides\TestKline;
0 ignored issues
show
Bug introduced by
The type Carpenstar\ByBitAPI\Spot...ine\Overrides\TestKline was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Carpenstar\ByBitAPI\Spot\MarketData\Kline\Request\KlineRequest;
16
use Carpenstar\ByBitAPI\Spot\MarketData\Kline\Response\KlineResponse;
17
use Carpenstar\ByBitAPI\Spot\MarketData\Kline\Response\KlineResponseItem;
18
use PHPUnit\Framework\TestCase;
19
20
class KlineTest extends TestCase
21
{
22
    /**
23
     * Тестирование сборки объекта ответа
24
     *
25
     * @return void
26
     */
27
    public function testBuildResponseData()
28
    {
29
        $json = '{"retCode":0,"retMsg":"OK","result":{"list":[{"t":1683922260000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26413.58","h":"26444.15","l":"26413.58","o":"26440","v":"0.038419"},{"t":1683922320000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26405.44","h":"26420.02","l":"26402.16","o":"26413.58","v":"0.024527"},{"t":1683922380000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26390.96","h":"26406.3","l":"26390.95","o":"26405.44","v":"0.030255"},{"t":1683922440000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26397.07","h":"26399.92","l":"26390.95","o":"26390.96","v":"0.028976"},{"t":1683922500000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26390.98","h":"26397.07","l":"26390.95","o":"26397.07","v":"0.03669"},{"t":1683922560000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26409.24","h":"26409.24","l":"26389.68","o":"26390.98","v":"0.024756"},{"t":1683922620000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26443.27","h":"26453.24","l":"26390.95","o":"26409.24","v":"0.025462"},{"t":1683922680000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26451.86","h":"26451.89","l":"26440.91","o":"26443.27","v":"0.026304"},{"t":1683922740000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26426.59","h":"26451.86","l":"26424.63","o":"26451.86","v":"0.02513"},{"t":1683922800000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26429.66","h":"26435.5","l":"26419.97","o":"26426.59","v":"0.021732"},{"t":1683922860000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26426.6","h":"26435.01","l":"26421.77","o":"26429.66","v":"0.024761"},{"t":1683922920000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26404.56","h":"26434.34","l":"26401.55","o":"26426.6","v":"0.020718"},{"t":1683922980000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26403.24","h":"26414.24","l":"26386.61","o":"26404.56","v":"0.02995"},{"t":1683923040000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26391.6","h":"26403.24","l":"26391.57","o":"26403.24","v":"0.016944"},{"t":1683923100000,"s":"BTCUSDT","sn":"BTCUSDT","c":"26386.62","h":"26391.6","l":"26386.61","o":"26391.6","v":"0.03116"}]},"retExtInfo":{},"time":1683982237622}';
30
        $data = (new CurlResponseHandler())->build(json_decode($json, true), KlineResponse::class);
31
32
        $this->assertEquals(0, $data->getReturnCode());
33
        $this->assertEquals('OK', $data->getReturnMessage());
34
        $this->assertInstanceOf(KlineResponse::class, $data->getResult());
35
36
        /** @var KlineResponseItem $klineInfo */
37
        $klineInfo = current($data->getResult()->getKlineList());
0 ignored issues
show
Bug introduced by
The method getKlineList() does not exist on Carpenstar\ByBitAPI\Core\Objects\AbstractResponse. It seems like you code against a sub-type of Carpenstar\ByBitAPI\Core\Objects\AbstractResponse such as Carpenstar\ByBitAPI\Spot...\Response\KlineResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        $klineInfo = current($data->getResult()->/** @scrutinizer ignore-call */ getKlineList());
Loading history...
38
39
        $this->assertInstanceOf(\DateTime::class, $klineInfo->getTime());
40
        $this->assertEquals('BTCUSDT', $klineInfo->getSymbol());
41
        $this->assertEquals('BTCUSDT', $klineInfo->getAlias());
42
        $this->assertEquals(26413.58, $klineInfo->getClosePrice());
43
        $this->assertEquals(26444.15, $klineInfo->getHighPrice());
44
        $this->assertEquals(26413.58, $klineInfo->getLowPrice());
45
        $this->assertEquals(26440, $klineInfo->getOpenPrice());
46
        $this->assertEquals(0.038419, $klineInfo->getTradingVolume());
47
    }
48
}