<?php

/**
 * TradeDataStreamApiTest
 * PHP version 8.1.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Binance Margin Trading REST API.
 *
 * OpenAPI Specification for the Binance Margin Trading REST API
 *
 * The version of the OpenAPI document: 1.0.0
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.12.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Please update the test case below to test the endpoint.
 */

namespace Binance\Client\MarginTrading\Test\Api;

use Binance\Client\MarginTrading\Api\TradeDataStreamApi;
use Binance\Client\MarginTrading\Model\KeepaliveIsolatedMarginUserDataStreamRequest;
use Binance\Client\MarginTrading\Model\KeepaliveMarginUserDataStreamRequest;
use Binance\Client\MarginTrading\Model\StartIsolatedMarginUserDataStreamRequest;
use Binance\Common\Configuration\ClientConfiguration;
use Binance\Common\Configuration\SignatureConfiguration;
use Binance\Common\HttpClient;
use GuzzleHttp\Psr7\Utils;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;

/**
 * TradeDataStreamApiTest Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @internal
 *
 * @coversNothing
 */
class TradeDataStreamApiTest extends TestCase
{
    public function getApiMock(&$request)
    {
        $clientMock = $this->createMock(HttpClient::class);
        $signatureConfig = new SignatureConfiguration();
        $signatureConfig->setApiKey('apiKey');
        $signatureConfig->setSecretKey('secretKey');
        $clientConfig = new ClientConfiguration();
        $clientConfig->setUrl('http://localhost:8080');
        $clientConfig->setSignatureConfiguration($signatureConfig);
        $responseMock = $this->createMock(ResponseInterface::class);

        $responseMock->expects($this->any())
            ->method('getStatusCode')
            ->willReturn(200)
        ;

        $responseMock->expects($this->any())
            ->method('getBody')
            ->willReturn(Utils::streamFor('{}'))
        ;

        $clientMock->expects($this->once())
            ->method('send')
            ->will($this->returnCallback(function ($actualRequest) use (&$request, $responseMock) {
                $request = $actualRequest;

                return $responseMock;
            }))
        ;

        $apiMock = $this->getMockBuilder(TradeDataStreamApi::class)
            ->setConstructorArgs([$clientConfig, $clientMock])
            ->onlyMethods(['getTimestamp'])
            ->getMock()
        ;

        $apiMock->method('getTimestamp')->willReturn('1736393892000');

        return $apiMock;
    }

    /**
     * Test case for closeIsolatedMarginUserDataStream.
     *
     * Close Isolated Margin User Data Stream (USER_STREAM).
     */
    public function testCloseIsolatedMarginUserDataStream()
    {
        $symbol = '';
        $listenkey = '';
        $this->getApiMock($request)->closeIsolatedMarginUserDataStream($symbol, $listenkey);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals('/sapi/v1/userDataStream/isolated', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for closeMarginUserDataStream.
     *
     * Close Margin User Data Stream (USER_STREAM).
     */
    public function testCloseMarginUserDataStream()
    {
        $listenkey = '';
        $this->getApiMock($request)->closeMarginUserDataStream($listenkey);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals('/sapi/v1/userDataStream', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for keepaliveIsolatedMarginUserDataStream.
     *
     * Keepalive Isolated Margin User Data Stream (USER_STREAM).
     */
    public function testKeepaliveIsolatedMarginUserDataStream()
    {
        $keepaliveIsolatedMarginUserDataStreamRequest = new KeepaliveIsolatedMarginUserDataStreamRequest();
        $keepaliveIsolatedMarginUserDataStreamRequest->setSymbol('');
        $keepaliveIsolatedMarginUserDataStreamRequest->setListenKey('');

        $this->getApiMock($request)->keepaliveIsolatedMarginUserDataStream($keepaliveIsolatedMarginUserDataStreamRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals('/sapi/v1/userDataStream/isolated', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for keepaliveMarginUserDataStream.
     *
     * Keepalive Margin User Data Stream (USER_STREAM).
     */
    public function testKeepaliveMarginUserDataStream()
    {
        $keepaliveMarginUserDataStreamRequest = new KeepaliveMarginUserDataStreamRequest();
        $keepaliveMarginUserDataStreamRequest->setListenKey('');

        $this->getApiMock($request)->keepaliveMarginUserDataStream($keepaliveMarginUserDataStreamRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals('/sapi/v1/userDataStream', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for startIsolatedMarginUserDataStream.
     *
     * Start Isolated Margin User Data Stream (USER_STREAM).
     */
    public function testStartIsolatedMarginUserDataStream()
    {
        $startIsolatedMarginUserDataStreamRequest = new StartIsolatedMarginUserDataStreamRequest();
        $startIsolatedMarginUserDataStreamRequest->setSymbol('');

        $response = $this->getApiMock($request)->startIsolatedMarginUserDataStream($startIsolatedMarginUserDataStreamRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/userDataStream/isolated', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }

    /**
     * Test case for startMarginUserDataStream.
     *
     * Start Margin User Data Stream (USER_STREAM).
     */
    public function testStartMarginUserDataStream()
    {
        $response = $this->getApiMock($request)->startMarginUserDataStream();

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/userDataStream', $request->getUri()->getPath());
        self::assertTrue(!isset($queryMap['signature']));
    }
}
