public function testDelService() { $this->mockTest->setService("test1", function ($locator) { $instance = new \stdClass(); $instance->rand = mt_rand(); return $instance; }); $this->assertNotEmpty($this->mockTest->getService('test1')); $this->mockTest->delService("test1"); $this->assertEmpty($this->mockTest->getService('test1')); }
/** * @link https://docs.aliyun.com/#/pub/ecs/open-api/requestmethod&signature */ public function testBuildSignature() { $aliyunClient = \AlibabaSDK\Integrate\ServiceLocator::getInstance()->getService('AliyunClientBuildSignatureTest'); $paramStr = 'TimeStamp=2012-12-26T10:33:56Z&Format=XML&AccessKeyId=testid&Action=DescribeRegions&SignatureMethod=HMAC-SHA1&RegionId=region1&SignatureNonce=NwDAxvLU6tFE0DVb&Version=2014-05-26&SignatureVersion=1.0'; parse_str($paramStr, $param); $sig = $aliyunClient->buildSignature($param, 'GET'); $this->assertEquals('K9fCVP6Jrklpd3rLYKh1pfrrFNo=', $sig); //文档说是“SDFQNvyH5rtkc9T5Fwo8DOjw5hc=”,文档有错误? }
protected function setUp() { parent::setUp(); $this->mockClient = \AlibabaSDK\Integrate\ServiceLocator::getInstance()->getService('AliyunClientRDS'); //模拟读取正式环境配置 $accessKey = $this->mockClient->getConfig('accessKeyId'); $accessKeySecret = $this->mockClient->getConfig('accessKeySecret'); if (empty($accessKey) || empty($accessKeySecret)) { $this->markTestSkipped('accessKeyId or accessKeySecret is not set in service config with service name "AliyunClientRDS", test will skipped'); } }
<?php /* * 使用依赖注入Service Locator调用本SDK:AliyunClient(调用ECS) */ use AlibabaSDK\Integrate\ServiceLocator; require __DIR__ . '/../CommonHeaderForDemoOnly.php'; //初始化依赖注入Service Locator的单实例配置(\AlibabaSDK\Integrate\ServiceLocator) $SLConfig = array('configFile' => __DIR__ . '/ConfigServiceLocatorDefaultDemo.php'); ServiceLocator::setInstanceDefaultConfig($SLConfig); //初始化依赖注入Service Locator的单实例配置完毕 //请注意这里和demo文件/demo/TaobaoClient/basicUsage.php的不同。 //通过Service Locator,你可以随时调用,而无需重新初始化 $aliyunClient = ServiceLocator::getInstance()->getService('AliyunClient'); $response = $aliyunClient->send('DescribeInstanceTypes'); if (!$response->isOk()) { exit("API Error!:" . var_export($response->getError(true))); } $result = $response->getResult(); var_export($result);
<?php /* * 使用依赖注入Service Locator调用本SDK:TaobaoClient */ use AlibabaSDK\Integrate\ServiceLocator; require __DIR__ . '/../CommonHeaderForDemoOnly.php'; //初始化依赖注入Service Locator的实例(\AlibabaSDK\Integrate\ServiceLocator) $SLConfig = array('configFile' => __DIR__ . '/ConfigServiceLocatorDefaultDemo.php'); ServiceLocator::setInstanceDefaultConfig($SLConfig); //初始化依赖注入Service Locator的实例完毕 //请注意这里和demo文件/demo/TaobaoClient/basicUsage.php的不同。 //通过Service Locator,你可以随时调用,而无需重新初始化 $taobaoClient = ServiceLocator::getInstance()->getService('TaobaoClient'); $response = $taobaoClient->send('alibaba.security.yundun.spam.validate', array('content' => '你好!')); if (!$response->isOk()) { exit("API Error!:" . var_export($response->getError(true))); } $result = $response->getResult(); var_export($result);
/** * @link http://open.taobao.com/doc/detail.htm?id=101617&spm=a219a.7386781.1998342838.20.juxYvY */ public function testBuildSignatureWithFile() { $taobaoClient = \AlibabaSDK\Integrate\ServiceLocator::getInstance()->getService('TaobaoClientBuildSignatureTest'); $sig = $taobaoClient->buildSignature(array('method' => 'taobao.user.seller.get', 'timestamp' => '2013-05-06 13:52:03', 'format' => 'xml', 'app_key' => 'test', 'v' => '2.0', 'fields' => 'nick', 'sign_method' => 'md5', 'session' => 'test', 'file' => $taobaoClient->curl_file_create(D_APP_DIR . '/Assets/1.txt')), 'POST'); $this->assertEquals('72CB4D809B375A54502C09360D879C64', $sig); }
protected function setUp() { parent::setUp(); $this->mockClient = \AlibabaSDK\Integrate\ServiceLocator::getInstance()->getService('TaobaoClientSandbox'); }
<?php if (!class_exists('PHPUnit_TextUI_Command', false)) { exit('THIS IS FOR PHPUNIT RUN ONLY'); } //SDK初始化 require __DIR__ . '/src/AlibabaSDK/Integrate/Loader.php'; \AlibabaSDK\Integrate\Loader::getInstance()->reg2SPL(); //初始化Service Locator $serviceLocatorConfig = array('configFile' => array(__DIR__ . '/testsmock/LoaderConfig/ServiceLocatorDefault.php', __DIR__ . '/testsmock/LoaderConfig/ServiceLocatorPHPUnit.php', __DIR__ . '/testsmock/LoaderConfig/ServiceLocatorProduction.php')); \AlibabaSDK\Integrate\ServiceLocator::getInstance($serviceLocatorConfig); //mock初始化 require __DIR__ . '/testsmock/Class/Testsmoke_Loader.php'; Testsmoke_Loader::regLoadClassPath("testcase", __DIR__ . '/tests'); Testsmoke_Loader::define(array('D_APP_DIR' => __DIR__ . '/testsmock', 'D_ENTRY_FILE' => __FILE__, 'D_ENV' => 'Dev', 'D_DEBUG' => 1)); $printPHPUnit = function ($buffer = "") { echo PHP_EOL; if (!empty($buffer)) { echo "[30;42m" . $buffer . "[0m"; } }; $printPHPUnit(); $printPHPUnit("PHPUnit Test Prepare OK"); $printPHPUnit(); $printPHPUnit();