| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595 |
- <?php
- namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Request;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use AlibabaCloud\Client\Request\RpcRequest;
- use PHPUnit\Framework\TestCase;
- /**
- * Class AcsTraitTest
- *
- * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Request
- *
- * @coversDefaultClass \AlibabaCloud\Client\Request\Request
- */
- class AcsTraitTest extends TestCase
- {
- /**
- * @throws ClientException
- */
- public function testAction()
- {
- // Setup
- $action = 'action';
- $request = new RpcRequest();
- // Test
- $request->action($action);
- // Assert
- self::assertEquals($action, $request->action);
- }
- /**
- * @throws ClientException
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Action cannot be empty
- */
- public function testActionWithEmpty()
- {
- // Setup
- $request = new RpcRequest();
- // Test
- $request->action('');
- }
- /**
- * @throws ClientException
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Action must be a string
- */
- public function testActionWithFormat()
- {
- // Setup
- $request = new RpcRequest();
- // Test
- $request->action(null);
- }
- /**
- * @throws ClientException
- */
- public function testVersion()
- {
- // Setup
- $version = 'version';
- $request = new RpcRequest();
- // Test
- $request->version($version);
- // Assert
- self::assertEquals($version, $request->version);
- }
- /**
- * @throws ClientException
- * @expectedExceptionMessage Version cannot be empty
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- */
- public function testVersionWithEmpty()
- {
- // Setup
- $request = new RpcRequest();
- // Test
- $request->version('');
- }
- /**
- * @throws ClientException
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Version must be a string
- */
- public function testVersionWithFormat()
- {
- // Setup
- $request = new RpcRequest();
- // Test
- $request->version(null);
- }
- /**
- * @throws ClientException
- */
- public function testProduct()
- {
- // Setup
- $product = 'product';
- $request = new RpcRequest();
- // Test
- $request->product($product);
- // Assert
- self::assertEquals($product, $request->product);
- }
- public function testNetwork()
- {
- // Setup
- $network = 'vpc';
- $request = new RpcRequest();
- // Test
- $request->network($network);
- // Assert
- self::assertEquals($network, $request->network);
- }
- /**
- * @throws ClientException
- * @expectedExceptionMessage Product cannot be empty
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- */
- public function testProductWithEmpty()
- {
- // Setup
- $request = new RpcRequest();
- // Test
- $request->product('');
- }
- /**
- * @throws ClientException
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Product must be a string
- */
- public function testProductWithFormat()
- {
- // Setup
- $request = new RpcRequest();
- // Test
- $request->product(null);
- }
- /**
- * @throws ClientException
- */
- public function testLocationEndpointType()
- {
- // Setup
- $endpointType = 'endpointType';
- $request = new RpcRequest();
- // Test
- $request->endpointType($endpointType);
- // Assert
- self::assertEquals(
- $endpointType,
- $request->endpointType
- );
- }
- /**
- * @throws ClientException
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Endpoint Type cannot be empty
- */
- public function testLocationEndpointTypeEmpty()
- {
- // Setup
- $request = new RpcRequest();
- // Test
- $request->endpointType('');
- }
- /**
- * @throws ClientException
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Endpoint Type must be a string
- */
- public function testLocationEndpointTypeFormat()
- {
- // Setup
- $request = new RpcRequest();
- // Test
- $request->endpointType(null);
- }
- /**
- * @throws ClientException
- */
- public function testLocationServiceCode()
- {
- // Setup
- $serviceCode = 'serviceCode';
- $request = new RpcRequest();
- // Test
- $request->serviceCode($serviceCode);
- // Assert
- self::assertEquals(
- $serviceCode,
- $request->serviceCode
- );
- }
- /**
- * @throws ClientException
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Service Code cannot be empty
- */
- public function testServiceCodeEmpty()
- {
- // Setup
- $request = new RpcRequest();
- // Test
- $request->serviceCode('');
- }
- /**
- * @throws ClientException
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Service Code must be a string
- */
- public function testServiceCodeFormat()
- {
- // Setup
- $request = new RpcRequest();
- // Test
- $request->serviceCode(null);
- }
- /**
- * @throws ClientException
- */
- public function testRealRegionIdOnRequest()
- {
- // Setup
- $regionId = 'regionId';
- $request = new RpcRequest();
- // Test
- $request->regionId($regionId);
- // Assert
- self::assertEquals(
- strtolower($regionId),
- $request->realRegionId()
- );
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Region ID cannot be empty
- * @throws ClientException
- */
- public function testRegionIdEmpty()
- {
- // Setup
- $regionId = '';
- $request = new RpcRequest();
- // Test
- $request->regionId($regionId);
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Region ID must be a string
- * @throws ClientException
- */
- public function testRegionIdFormat()
- {
- // Setup
- $regionId = null;
- $request = new RpcRequest();
- // Test
- $request->regionId($regionId);
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Timeout cannot be empty
- * @throws ClientException
- */
- public function testTimeoutEmpty()
- {
- // Setup
- $request = new RpcRequest();
- // Test
- $request->timeout('');
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Connect Timeout cannot be empty
- * @throws ClientException
- */
- public function testConnectTimeout()
- {
- // Setup
- $request = new RpcRequest();
- // Test
- $request->connectTimeout('');
- }
- /**
- * @throws ClientException
- */
- public function testRealRegionIdOnClient()
- {
- // Setup
- $regionId = 'regionId';
- AlibabaCloud::accessKeyClient('foo', 'bar')
- ->regionId($regionId)
- ->name('regionId');
- $request = new RpcRequest();
- // Test
- $request->client('regionId');
- // Assert
- self::assertEquals(
- strtolower($regionId),
- $request->realRegionId()
- );
- }
- /**
- * @throws ClientException
- */
- public function testRealRegionIdOnDefault()
- {
- // Setup
- $regionId = 'regionId';
- AlibabaCloud::accessKeyClient('foo', 'bar')
- ->name('regionId');
- AlibabaCloud::setDefaultRegionId($regionId);
- // Test
- $request = new RpcRequest();
- $request->client('regionId');
- // Assert
- self::assertEquals(
- strtolower($regionId),
- $request->realRegionId()
- );
- }
- /**
- * @throws ClientException
- * @throws ServerException
- */
- public function testEndpointMap()
- {
- // Setup
- $request = AlibabaCloud::rpc();
- $region = 'cn-hangzhou';
- $request->regionId($region);
- $request->endpointMap[$region] = 'b.com';
- // Test
- $request->resolveHost();
- self::assertEquals('http://b.com', (string)$request->uri);
- // Setup
- $request = AlibabaCloud::rpc();
- $region = 'cn-shanghai';
- $request->regionId($region);
- $request->product('ecs');
- // Test
- $request->resolveHost();
- self::assertEquals('http://ecs-cn-hangzhou.aliyuncs.com', (string)$request->uri);
- }
- /**
- * @throws ClientException
- * @throws ServerException
- */
- public function testEndpointRegional()
- {
- // Setup
- $request = AlibabaCloud::rpc();
- $region = 'cn-hangzhou';
- $request->regionId($region);
- $request->product('ecs');
- $request->endpointRegional = 'regional';
- // Test
- $request->resolveHost();
- self::assertEquals('http://ecs.cn-hangzhou.aliyuncs.com', (string)$request->uri);
- }
- /**
- * @throws ClientException
- * @throws ServerException
- */
- public function testEndpointCentral()
- {
- // Setup
- $request = AlibabaCloud::rpc();
- $region = 'cn-hangzhou';
- $request->regionId($region);
- $request->product('ecs');
- $request->endpointRegional = 'central';
- // Test
- $request->resolveHost();
- self::assertEquals('http://ecs.aliyuncs.com', (string)$request->uri);
- }
- /**
- * @throws ClientException
- * @throws ServerException
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage endpointRegional is invalid.
- */
- public function testEndpointRegionalRnvalid()
- {
- // Setup
- $request = AlibabaCloud::rpc();
- $region = 'cn-hangzhou';
- $request->regionId($region);
- $request->product('ecs');
- $request->endpointRegional = 'invalid';
- // Test
- $request->resolveHost();
- }
- /**
- * @expectedExceptionMessage Missing required 'RegionId' for Request
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @throws ClientException
- */
- public function testRealRegionIdException()
- {
- // Setup
- AlibabaCloud::flush();
- AlibabaCloud::accessKeyClient('foo', 'bar')
- ->name('regionId');
- // Test
- $request = new RpcRequest();
- $request->client('regionId');
- $request->realRegionId();
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Region ID must be a string
- * @throws ClientException
- */
- public function testSetDefaultRegionIdNull()
- {
- // Test
- AlibabaCloud::accessKeyClient('foo', 'bar')
- ->name('regionId');
- AlibabaCloud::setDefaultRegionId(null);
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Region ID cannot be empty
- * @throws ClientException
- */
- public function testSetDefaultRegionIdEmpty()
- {
- // Test
- AlibabaCloud::accessKeyClient('foo', 'bar')
- ->name('regionId');
- AlibabaCloud::setDefaultRegionId('');
- }
- /**
- * @throws ClientException
- * @throws ServerException
- */
- public function testFindDomainInConfig()
- {
- // Setup
- $request = new RpcRequest();
- $request->product('ecs');
- $request->regionId('eu-central-1');
- // Test
- $request->resolveHost();
- // Assert
- self::assertEquals(
- 'ecs.eu-central-1.aliyuncs.com',
- $request->uri->getHost()
- );
- }
- /**
- * @throws ClientException
- * @throws ServerException
- */
- public function testFindDomainOnLocationService()
- {
- // Setup
- $body = [
- 'Endpoints' => [
- 'Endpoint' => [
- 0 => [
- 'Endpoint' => 'ecs-cn-hangzhou.aliyuncs.com',
- ],
- ],
- ],
- ];
- AlibabaCloud::mockResponse(200, [], $body);
- AlibabaCloud::accessKeyClient('foo', 'bar')->asDefaultClient()->regionId('cn-hangzhou');
- // Test
- $request = new RpcRequest();
- $request->product('ecs2');
- $request->serviceCode('ecs');
- // Assert
- $request->resolveHost();
- self::assertEquals('ecs-cn-hangzhou.aliyuncs.com', $request->uri->getHost());
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage No host found for no in the cn-hangzhou, you can specify host by host() method. Like
- * $request->host('xxx.xxx.aliyuncs.com')
- * @throws ClientException
- * @throws ServerException
- */
- public function testFindDomainOnLocationServiceWithEmpty()
- {
- // Setup
- $body = [
- 'Endpoints' => [
- 'Endpoint' => [
- 0 => [
- 'Endpoint' => '',
- ],
- ],
- ],
- ];
- AlibabaCloud::mockResponse(200, [], $body);
- AlibabaCloud::setDefaultRegionId('cn-hangzhou');
- AlibabaCloud::accessKeyClient('ak', 'bar')->asDefaultClient();
- // Test
- $request = new RpcRequest();
- $request->product('no');
- $request->serviceCode('no');
- // Assert
- $request->resolveHost();
- self::assertEquals('ecs-cn-hangzhou.aliyuncs.com', $request->uri->getHost());
- }
- protected function tearDown()
- {
- AlibabaCloud::cancelMock();
- }
- }
|