| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Regions;
- use PHPUnit\Framework\TestCase;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Regions\LocationService;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use AlibabaCloud\Client\Tests\Mock\Services\Rds\DeleteDatabaseRequest;
- /**
- * Class LocationServiceTest
- *
- * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Endpoint
- */
- class LocationServiceTest extends TestCase
- {
- /**
- * @throws ClientException
- * @throws ServerException
- */
- public function testAddHost()
- {
- // Setup
- $product = 'b';
- $host = 'c';
- $regionId = 'a';
- // Test
- $request = AlibabaCloud::rpc()->regionId($regionId)->product($product);
- LocationService::addHost($product, $host, $regionId);
- // Assert
- self::assertEquals(LocationService::resolveHost($request), $host);
- }
- /**
- * @throws ClientException
- * @throws ServerException
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessageRegExp /Not found Region ID in location.aliyuncs.com/
- */
- public function testResolveHostWithServiceUnknownError()
- {
- AlibabaCloud::mockResponse();
- $request = AlibabaCloud::rpc()->product(__METHOD__)
- ->regionId('regionId');
- $host = LocationService::resolveHost($request);
- self::assertEquals('', $host);
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Not found Region ID in location.aliyuncs.com
- * @throws ClientException
- * @throws ServerException
- */
- public function testResolveHostNotFound()
- {
- AlibabaCloud::mockResponse();
- $request = AlibabaCloud::rpc()->product(__METHOD__)->regionId('regionId');
- LocationService::resolveHost($request);
- }
- /**
- * @throws ClientException
- * @throws ServerException
- */
- public function testResolveHostSuccess()
- {
- $body = [
- 'Endpoints' => [
- 'Endpoint' => [
- 0 => [
- 'Endpoint' => 'cdn.aliyun.com',
- ],
- ],
- ],
- ];
- AlibabaCloud::mockResponse(200, [], $body);
- $request = AlibabaCloud::rpc()->product(__METHOD__)->regionId('regionId');
- $host = LocationService::resolveHost($request);
- self::assertEquals('cdn.aliyun.com', $host);
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Product cannot be empty
- * @throws ClientException
- */
- public function testAddHostWithProductEmpty()
- {
- LocationService::addHost('', 'host', 'regionId');
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Product must be a string
- * @throws ClientException
- */
- public function testAddHostWithProductFormat()
- {
- LocationService::addHost(null, 'host', 'regionId');
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Host cannot be empty
- * @throws ClientException
- */
- public function testAddHostWithHostEmpty()
- {
- LocationService::addHost('product', '', 'regionId');
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Host must be a string
- * @throws ClientException
- */
- public function testAddHostWithHostFormat()
- {
- LocationService::addHost('product', null, 'regionId');
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Region ID cannot be empty
- * @throws ClientException
- */
- public function testAddHostWithRegionIdEmpty()
- {
- LocationService::addHost('product', 'host', '');
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessage Region ID must be a string
- * @throws ClientException
- */
- public function testAddHostWithRegionIdFormat()
- {
- LocationService::addHost('product', 'host', null);
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ServerException
- * @expectedExceptionMessageRegExp /Specified access key is not found/
- * @throws ClientException
- * @throws ServerException
- */
- public function testLocationServiceException()
- {
- // Setup
- AlibabaCloud::accessKeyClient('key', 'secret')->asDefaultClient();
- AlibabaCloud::mockResponse(
- 401,
- [],
- [
- 'message' => 'Specified access key is not found',
- ]
- );
- $request = (new DeleteDatabaseRequest())
- ->regionId('cn-hangzhou')
- ->connectTimeout(25)
- ->timeout(30);
- // Test
- LocationService::resolveHost($request);
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ClientException
- * @expectedExceptionMessageRegExp /cURL error 6: Could not resolve/
- * @throws ClientException
- * @throws ServerException
- */
- public function testLocationServiceWithBadServiceDomain()
- {
- AlibabaCloud::accessKeyClient('key', 'secret')->asDefaultClient();
- $request = (new DeleteDatabaseRequest())->regionId('cn-hangzhou');
- LocationService::resolveHost($request, 'not.alibaba.com');
- }
- /**
- * @throws ClientException
- */
- protected function setUp()
- {
- AlibabaCloud::accessKeyClient('foo', 'bar')->asDefaultClient();
- }
- protected function tearDown()
- {
- AlibabaCloud::cancelMock();
- }
- }
|