Passed
Pull Request — master (#10)
by Vladislav
03:04
created

testGetExecutionListDTOBuilder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 5
rs 10
1
<?php
2
namespace Carpenstar\ByBitAPI\Derivatives\Contract\Position\GetExecutionList\Tests;
3
4
use Carpenstar\ByBitAPI\Core\Builders\ResponseDtoBuilder;
5
use Carpenstar\ByBitAPI\Core\Builders\ResponseHandlerBuilder;
6
use Carpenstar\ByBitAPI\Core\Builders\RestBuilder;
7
use Carpenstar\ByBitAPI\Core\Enums\EnumOutputMode;
8
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection;
9
use Carpenstar\ByBitAPI\Core\Response\CurlResponseDto;
10
use Carpenstar\ByBitAPI\Core\Response\CurlResponseHandler;
11
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\GetClosedPnL\Overrides\TestGetClosedPnL;
12
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\GetClosedPnL\Request\GetClosedPnLRequest;
13
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\GetClosedPnL\Response\GetClosedPnLResponse;
14
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\GetExecutionList\Overrides\TestGetExecutionList;
15
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\GetExecutionList\Request\GetExecutionListRequest;
16
use Carpenstar\ByBitAPI\Derivatives\Contract\Position\GetExecutionList\Response\GetExecutionListResponse;
17
use PHPUnit\Framework\TestCase;
18
19
class GetExecutionListTest extends TestCase
20
{
21
    static private string $closedPnLResponse = '{"retCode":0,"retMsg":"OK","result":{"list":[{"symbol":"ETHUSDT","execFee":"-0.08720013","execId":"208751d8-f70e-4570-a5fd-d208c82af99d","execPrice":"1263.77","execQty":"0.69","execType":"Funding","execValue":"872.0013","feeRate":"-0.0001","lastLiquidityInd":"UNKNOWN","leavesQty":"0.00","orderId":"1673136000-ETHUSDT-592334-Sell","orderLinkId":"","orderPrice":"0.00","orderQty":"0.00","orderType":"UNKNOWN","stopOrderType":"UNKNOWN","side":"Sell","execTime":"1673136000000","closedSize":"0.00","iv":"","blockTradeId":"","markPrice":"","markIv":"","underlyingPrice":"","indexPrice":"","isMaker":false}],"nextPageCursor": "ZzU3NlU4M1JlLzhFTWkzeW9hemRVcitqUk4wVW9LL21KVTRWV3JPR0tYTG9uTENWSkFvUDJuWk44OVBlNnB0ZjJHTTFwdlJRV0tpZFM0Z0RzUlQ0d2FSbzVRN2lpZ0ZrZmt2UTZuRlJVSHdQSHdoYXUvdDN6aExzOEpmcDNFY2NLc2dYTnRvOXhmTmY3NVNreVgzQ2RKUFZtekptU0NQNU1rOWd5YzZRV1ZDejVFM0t0MGdlMENNc04ybzQvc2JQQ3BVRkQycHU3MFdBK3RqdFlWaVRkMTNGQmZRUUZpaVc4MkE1SnRCT09iZDRNL2FlNDVSMithdU96NTROWGFxcTFucW1MSnJSaTluM29pZm85dHVkNzJMSVQwODk4UTJLbHEybDJ0Uk9UYmtCcU5ScU9zZWRCa2Znc0dwbmNEOWJoaCtnZkRkWjlrMEl6elRmWnljeHZpYXBPWVdzZSs0UEtvdnZ4cTJHQ2JZcm1UQkU3TXFKS01yU1dmaloyT3pVS1psbmVaamh3N3Ntc0hFbEgwckxtQT09","category":""},"retExtInfo":{},"time":1673150404910}';
22
23
    public function testGetExecutionListDTOBuilder()
24
    {
25
        foreach (json_decode(self::$closedPnLResponse, true)['result']["list"] as $feeRate) {
26
            $dto = ResponseDtoBuilder::make(GetExecutionListResponse::class, $feeRate);
27
            $this->assertInstanceOf(GetExecutionListResponse::class, $dto);
28
        }
29
    }
30
31
    public function testGetExecutionListResponseHandlerBuilder()
32
    {
33
        $handler = ResponseHandlerBuilder::make(self::$closedPnLResponse, CurlResponseHandler::class, GetExecutionListResponse::class);
34
        $this->assertInstanceOf(EntityCollection::class, $handler->getBody());
35
        $this->assertGreaterThan(0, $handler->getBody()->count());
36
    }
37
38
    public function testGetExecutionListEndpoint()
39
    {
40
        $endpoint = RestBuilder::make(TestGetExecutionList::class, (new GetExecutionListRequest()));
41
42
        $entityResponse = $endpoint->execute(EnumOutputMode::MODE_ENTITY, self::$closedPnLResponse);
43
44
        $this->assertInstanceOf(CurlResponseDto::class, $entityResponse);
45
        $body = $entityResponse->getBody();
46
        $this->assertInstanceOf(EntityCollection::class, $body);
47
48
        foreach ($body->fetch() as $wallet) {
49
            $dto = ResponseDtoBuilder::make(GetExecutionListResponse::class, $wallet);
50
            $this->assertInstanceOf(GetExecutionListResponse::class, $dto);
51
        }
52
    }
53
}
54
55