<?php

namespace AlibabaCloud\Tests\Feature;

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use AlibabaCloud\CS\CS;
use AlibabaCloud\CS\V20151215\DescribeApiVersion;
use PHPUnit\Framework\TestCase;

/**
 * Class CsTest
 *
 * @package   AlibabaCloud\Tests\Feature
 */
class CsTest extends TestCase
{
    /**
     * @throws ClientException
     */
    public function setUp()
    {
        parent::setUp();

        AlibabaCloud::accessKeyClient(
            \getenv('ACCESS_KEY_ID'),
            \getenv('ACCESS_KEY_SECRET')
        )->regionId('cn-shanghai')->asDefaultClient();
    }

    public function testVersionResolve()
    {
        $request1 = AlibabaCloud::cS()
                                ->v20151215()
                                ->describeApiVersion()
                                ->connectTimeout(60)
                                ->timeout(65);

        $request2 = CS::v20151215()
                      ->describeApiVersion()
                      ->connectTimeout(60)
                      ->timeout(65);

        self::assertInstanceOf(DescribeApiVersion::class, $request1);
        self::assertInstanceOf(DescribeApiVersion::class, $request2);
        self::assertEquals($request1, $request2);
    }

    /**
     * @throws ServerException
     * @throws ClientException
     */
    public function testCs()
    {
        $result = CS::v20151215()
                    ->describeApiVersion()
                    ->connectTimeout(60)
                    ->timeout(65)
                    ->request();
        self::assertArrayHasKey('docker_region_versions', $result);
    }
}
