123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- <?php
- namespace Darabonba\OpenApi\Tests;
- use Darabonba\OpenApi\OpenApiClient;
- use AlibabaCloud\Tea\Model;
- use AlibabaCloud\Tea\Request;
- use AlibabaCloud\Tea\Utils\Utils;
- use PHPUnit\Framework\TestCase;
- /**
- * @internal
- * @coversNothing
- */
- class OpenApiClientTest extends TestCase
- {
- public function testConfig(){
- $globalParameters = new GlobalParameters([
- "headers" => [
- "global-key" => "global-value"
- ],
- "queries" => [
- "global-query" => "global-value"
- ]
- ]);
- $config = new Config([
- "endpoint" => "config.endpoint",
- "endpointType" => "regional",
- "network" => "config.network",
- "suffix" => "config.suffix",
- "protocol" => "config.protocol",
- "method" => "config.method",
- "regionId" => "config.regionId",
- "userAgent" => "config.userAgent",
- "readTimeout" => 3000,
- "connectTimeout" => 3000,
- "httpProxy" => "config.httpProxy",
- "httpsProxy" => "config.httpsProxy",
- "noProxy" => "config.noProxy",
- "socks5Proxy" => "config.socks5Proxy",
- "socks5NetWork" => "config.socks5NetWork",
- "maxIdleConns" => 128,
- "signatureVersion" => "config.signatureVersion",
- "signatureAlgorithm" => "config.signatureAlgorithm",
- "globalParameters" => $globalParameters
- ]);
- $creConfig = new \AlibabaCloud\Credentials\Credential\Config([
- "accessKeyId" => "accessKeyId",
- "accessKeySecret" => "accessKeySecret",
- "securityToken" => "securityToken",
- "type" => "sts"
- ]);
- $credential = new Credential($creConfig);
- $config->credential = $credential;
- $client = new OpenApiClient($config);
- $config->accessKeyId = "ak";
- $config->accessKeySecret = "secret";
- $config->securityToken = "token";
- $config->type = "sts";
- $client = new OpenApiClient($config);
- }
- /**
- * @return Config
- */
- public static function createConfig(){
- $globalParameters = new GlobalParameters([
- "headers" => [
- "global-key" => "global-value"
- ],
- "queries" => [
- "global-query" => "global-value"
- ]
- ]);
- $config = new Config([
- "accessKeyId" => "ak",
- "accessKeySecret" => "secret",
- "securityToken" => "token",
- "type" => "sts",
- "userAgent" => "config.userAgent",
- "readTimeout" => 3000,
- "connectTimeout" => 3000,
- "maxIdleConns" => 128,
- "signatureVersion" => "config.signatureVersion",
- "signatureAlgorithm" => "ACS3-HMAC-SHA256",
- "globalParameters" => $globalParameters
- ]);
- return $config;
- }
- /**
- * @return RuntimeOptions
- */
- public static function createRuntimeOptions(){
- $runtime = new RuntimeOptions([
- "readTimeout" => 4000,
- "connectTimeout" => 4000,
- "maxIdleConns" => 100,
- "autoretry" => true,
- "maxAttempts" => 1,
- "backoffPolicy" => "no",
- "backoffPeriod" => 1,
- "ignoreSSL" => true
- ]);
- return $runtime;
- }
- /**
- * @return OpenApiRequest
- */
- public static function createOpenApiRequest(){
- $query = [];
- $query["key1"] = "value";
- $query["key2"] = 1;
- $query["key3"] = true;
- $body = [];
- $body["key1"] = "value";
- $body["key2"] = 1;
- $body["key3"] = true;
- $headers = [
- "for-test" => "sdk"
- ];
- $req = new OpenApiRequest([
- "headers" => $headers,
- "query" => OpenApiUtilClient::query($query),
- "body" => OpenApiUtilClient::parseToMap($body)
- ]);
- return $req;
- }
- public function testCallApiForRPCWithV2Sign_AK_Form(){
- $config = self::createConfig();
- $runtime = self::createRuntimeOptions();
- $config->protocol = "HTTP";
- $config->signatureAlgorithm = "v2";
- $config->endpoint = "test.aliyuncs.com";
- $client = new OpenApiClient($config);
- $request = self::createOpenApiRequest();
- $params = new Params([
- "action" => "TestAPI",
- "version" => "2022-06-01",
- "protocol" => "HTTPS",
- "pathname" => "/",
- "method" => "POST",
- "authType" => "AK",
- "style" => "RPC",
- "reqBodyType" => "formData",
- "bodyType" => "json"
- ]);
- $client->callApi($params, $request, $runtime);
- }
- public function testCallApiForRPCWithV2Sign_Anonymous_JSON(){
- $config = self::createConfig();
- $runtime = self::createRuntimeOptions();
- $config->protocol = "HTTP";
- $config->signatureAlgorithm = "v2";
- $config->endpoint = "test.aliyuncs.com";
- $client = new OpenApiClient($config);
- $request = self::createOpenApiRequest();
- $params = new Params([
- "action" => "TestAPI",
- "version" => "2022-06-01",
- "protocol" => "HTTPS",
- "pathname" => "/",
- "method" => "POST",
- "authType" => "Anonymous",
- "style" => "RPC",
- "reqBodyType" => "json",
- "bodyType" => "json"
- ]);
- $client->callApi($params, $request, $runtime);
- }
- public function testCallApiForROAWithV2Sign_HTTPS_AK_Form(){
- $config = self::createConfig();
- $runtime = self::createRuntimeOptions();
- $config->signatureAlgorithm = "v2";
- $config->endpoint = "test.aliyuncs.com";
- $client = new OpenApiClient($config);
- $request = self::createOpenApiRequest();
- $params = new Params([
- "action" => "TestAPI",
- "version" => "2022-06-01",
- "protocol" => "HTTPS",
- "pathname" => "/test",
- "method" => "POST",
- "authType" => "AK",
- "style" => "ROA",
- "reqBodyType" => "formData",
- "bodyType" => "json"
- ]);
- $client->callApi($params, $request, $runtime);
- }
- public function testCallApiForROAWithV2Sign_Anonymous_JSON(){
- $config = self::createConfig();
- $runtime = self::createRuntimeOptions();
- $config->protocol = "HTTP";
- $config->signatureAlgorithm = "v2";
- $config->endpoint = "test.aliyuncs.com";
- $client = new OpenApiClient($config);
- $request = self::createOpenApiRequest();
- $params = new Params([
- "action" => "TestAPI",
- "version" => "2022-06-01",
- "protocol" => "HTTPS",
- "pathname" => "/test",
- "method" => "POST",
- "authType" => "Anonymous",
- "style" => "ROA",
- "reqBodyType" => "json",
- "bodyType" => "json"
- ]);
- $client->callApi($params, $request, $runtime);
- }
- public function testCallApiForRPCWithV3Sign_AK_Form(){
- $config = self::createConfig();
- $runtime = self::createRuntimeOptions();
- $config->protocol = "HTTP";
- $config->endpoint = "test.aliyuncs.com";
- $client = new OpenApiClient($config);
- $request = self::createOpenApiRequest();
- $params = new Params([
- "action" => "TestAPI",
- "version" => "2022-06-01",
- "protocol" => "HTTPS",
- "pathname" => "/",
- "method" => "POST",
- "authType" => "AK",
- "style" => "RPC",
- "reqBodyType" => "formData",
- "bodyType" => "json"
- ]);
- $client->callApi($params, $request, $runtime);
- }
- public function testCallApiForRPCWithV3Sign_Anonymous_JSON(){
- $config = self::createConfig();
- $runtime = self::createRuntimeOptions();
- $config->protocol = "HTTP";
- $config->endpoint = "test.aliyuncs.com";
- $client = new OpenApiClient($config);
- $request = self::createOpenApiRequest();
- $params = new Params([
- "action" => "TestAPI",
- "version" => "2022-06-01",
- "protocol" => "HTTPS",
- "pathname" => "/",
- "method" => "POST",
- "authType" => "Anonymous",
- "style" => "RPC",
- "reqBodyType" => "json",
- "bodyType" => "json"
- ]);
- $client->callApi($params, $request, $runtime);
- }
- public function testCallApiForROAWithV3Sign_AK_Form(){
- $config = self::createConfig();
- $runtime = self::createRuntimeOptions();
- $config->protocol = "HTTP";
- $config->endpoint = "test.aliyuncs.com";
- $client = new OpenApiClient($config);
- $request = self::createOpenApiRequest();
- $params = new Params([
- "action" => "TestAPI",
- "version" => "2022-06-01",
- "protocol" => "HTTPS",
- "pathname" => "/test",
- "method" => "POST",
- "authType" => "AK",
- "style" => "ROA",
- "reqBodyType" => "formData",
- "bodyType" => "json"
- ]);
- $client->callApi($params, $request, $runtime);
- }
- public function testCallApiForROAWithV3Sign_Anonymous_JSON(){
- $config = self::createConfig();
- $runtime = self::createRuntimeOptions();
- $config->protocol = "HTTP";
- $config->endpoint = "test.aliyuncs.com";
- $client = new OpenApiClient($config);
- $request = self::createOpenApiRequest();
- $params = new Params([
- "action" => "TestAPI",
- "version" => "2022-06-01",
- "protocol" => "HTTPS",
- "pathname" => "/test",
- "method" => "POST",
- "authType" => "Anonymous",
- "style" => "ROA",
- "reqBodyType" => "json",
- "bodyType" => "json"
- ]);
- $client->callApi($params, $request, $runtime);
- }
- public function testResponseBodyType(){
- $config = self::createConfig();
- $runtime = self::createRuntimeOptions();
- $config->protocol = "HTTP";
- $config->endpoint = "test.aliyuncs.com";
- $client = new OpenApiClient($config);
- $request = self::createOpenApiRequest();
- $params = new Params([
- "action" => "TestAPI",
- "version" => "2022-06-01",
- "protocol" => "HTTPS",
- "pathname" => "/test",
- "method" => "POST",
- "authType" => "AK",
- "style" => "ROA",
- "reqBodyType" => "formData",
- "bodyType" => "json"
- ]);
- $client->callApi($params, $request, $runtime);
- $params->bodyType = "array";
- $client->callApi($params, $request, $runtime);
- $params->bodyType = "string";
- $client->callApi($params, $request, $runtime);
- $params->bodyType = "byte";
- $client->callApi($params, $request, $runtime);
- }
- }
|