123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Request;
- use PHPUnit\Framework\TestCase;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ServerException;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Tests\Mock\Services\Nlp\NlpRequest;
- /**
- * Class RoaRequestTest
- *
- * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Request
- */
- class RoaRequestTest extends TestCase
- {
- /**
- * @throws ClientException
- */
- public function testRoa()
- {
- // Setup
- $clusterId = \time();
- // Test
- try {
- AlibabaCloud::accessKeyClient(
- getenv('ACCESS_KEY_ID'),
- getenv('ACCESS_KEY_SECRET')
- )->asDefaultClient()->regionId('cn-hangzhou');
- $result = AlibabaCloud::roa()
- ->pathPattern('/clusters/[ClusterId]/services')
- ->method('GET')
- ->product('CS')
- ->version('2015-12-15')
- ->action('DescribeClusterServices')
- ->pathParameter('ClusterId', $clusterId)
- ->connectTimeout(25)
- ->timeout(30)
- ->request();
- self::assertNotEmpty($result->toArray());
- } catch (ServerException $e) {
- self::assertEquals(
- "cluster ($clusterId) not found in our records",
- $e->getErrorMessage()
- );
- }
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ServerException
- * @expectedExceptionMessageRegExp /ServiceUnavailable: The request has failed due to a temporary failure of the server./
- * @throws ClientException
- * @throws ServerException
- */
- public function testRoaContent()
- {
- AlibabaCloud::accessKeyClient(
- \getenv('ACCESS_KEY_ID'),
- \getenv('ACCESS_KEY_SECRET')
- )->name('content')->regionId('cn-shanghai');
- $request = new NlpRequest();
- $request->pathParameter('Domain', 'general');
- $request->jsonBody([
- 'lang' => 'ZH',
- 'text' => 'Iphone专用数据线'
- ]);
- $result = $request->client('content')
- ->connectTimeout(25)
- ->timeout(30)
- ->request();
- self::assertEquals('Iphone', $result['data'][0]['word']);
- }
- /**
- * @throws ClientException
- * @throws ServerException
- */
- public function testSearchImage()
- {
- AlibabaCloud::accessKeyClient(
- \getenv('ACCESS_KEY_ID'),
- \getenv('ACCESS_KEY_SECRET')
- )->regionId('cn-shanghai')->name('im');
- $request = AlibabaCloud::roa()
- ->connectTimeout(40)
- ->timeout(50)
- ->client('im')
- ->product('ImageSearch')
- ->version('2019-03-25')
- ->method('POST')
- ->action('SearchImage')
- ->pathPattern('/v2/image/search')
- ->accept('application/json')
- ->contentType('application/x-www-form-urlencoded; charset=UTF-8');
- $content = file_get_contents(__DIR__ . '/ImageSearch.jpg');
- try {
- $result = $request->options([
- 'form_params' => [
- 'InstanceName' => getenv('IMAGE_SEARCH_INSTANCE_NAME'),
- 'PicContent' => base64_encode($content),
- 'Start' => 0,
- 'Num' => 10
- ]
- ])
- ->request();
- self::assertArrayHasKey('Actions', $result);
- } catch (ServerException $e) {
- self::assertEquals(400, $e->getCode());
- }
- }
- }
|