123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Request;
- use PHPUnit\Framework\TestCase;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Request\RpcRequest;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use AlibabaCloud\Client\Tests\Mock\Services\Ecs\DescribeRegionsRequest;
- /**
- * Class RpcRequestTest
- *
- * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Request
- * @coversDefaultClass \AlibabaCloud\Client\Request\RpcRequest
- */
- class RpcRequestTest extends TestCase
- {
- /**
- * @throws ServerException
- * @throws ClientException
- */
- public function testWithCredential()
- {
- // Setup
- $nameClient = 'name';
- $regionId = \AlibabaCloud\Client\env('REGION_ID', 'cn-hangzhou');
- $accessKeyId = \getenv('ACCESS_KEY_ID');
- $accessKeySecret = \getenv('ACCESS_KEY_SECRET');
- // Test
- AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret)
- ->regionId($regionId)
- ->name($nameClient);
- // Assert
- $result = (new DescribeRegionsRequest())->client($nameClient)
- ->connectTimeout(25)
- ->timeout(30)
- ->request();
- static::assertNotNull($result->RequestId);
- static::assertNotNull($result->Regions->Region[0]->LocalName);
- static::assertNotNull($result->Regions->Region[0]->RegionId);
- }
- /**
- * @covers \AlibabaCloud\Client\Request\Request::setQueryParameters
- * @throws ClientException
- */
- public function testWithBearerTokenCredential()
- {
- // Setup
- $regionId = \AlibabaCloud\Client\env('REGION_ID', 'cn-hangzhou');
- $bearerToken = 'BEARER_TOKEN';
- // Test
- AlibabaCloud::bearerTokenClient($bearerToken)
- ->regionId($regionId)
- ->name($bearerToken);
- // Assert
- try {
- $request = new DescribeRegionsRequest();
- $request->options(
- [
- 'query' => [
- 'test_true' => 1,
- 'test_false' => 1,
- ],
- ]
- );
- static::assertEquals(1, $request->options['query']['test_true']);
- static::assertEquals(1, $request->options['query']['test_false']);
- $result = $request->connectTimeout(25)
- ->timeout(30)
- ->request();
- self::assertArrayHasKey('Regions', $result);
- } catch (ServerException $e) {
- static::assertEquals('UnsupportedSignatureType', $e->getErrorCode());
- }
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ServerException
- * @expectedExceptionMessageRegExp /Forbidden.RAM: User not authorized to operate on the specified resource, or this API doesn't support RAM/
- * @throws ClientException
- * @throws ServerException
- */
- public function testRpc()
- {
- AlibabaCloud::accessKeyClient(
- \getenv('ACCESS_KEY_ID'),
- \getenv('ACCESS_KEY_SECRET')
- )->asDefaultClient()->regionId('cn-hangzhou');
- $result = (new RpcRequest())->method('POST')
- ->product('Cdn')
- ->version('2014-11-11')
- ->action('DescribeCdnService')
- ->connectTimeout(25)
- ->timeout(30)
- ->request();
- // self::assertNotEmpty('PayByTraffic', $result['ChangingChargeType']);
- }
- }
|