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'));
 }
 protected function setUp()
 {
     parent::setUp();
     $this->request = ServiceLocator::getInstance()->getService('AccountRequest');
     $secretId = $this->request->getConfig('secretId');
     $secretKey = $this->request->getConfig('secretKey');
     if (empty($secretId) || empty($secretKey)) {
         $this->markTestSkipped('secretId or secretKey is not set in config file, test will skipped');
     }
 }
 protected function setUp()
 {
     parent::setUp();
     $this->mockCurlRequestTrait = ServiceLocator::getInstance()->getService('Request_for_upload');
 }
 protected function setUp()
 {
     parent::setUp();
     $this->request = ServiceLocator::getInstance()->getService('Request_config_api_cvm_from_wiki_example');
 }
Esempio n. 5
0
<?php

if (!class_exists('PHPUnit_TextUI_Command', false)) {
    exit('THIS IS FOR PHPUNIT RUN ONLY');
}
//SDK初始化
require __DIR__ . '/src/QcloudApi/Integrate/Loader.php';
\QcloudApi\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'));
\QcloudApi\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'));
$printPHPUnit = function ($buffer = "") {
    echo PHP_EOL;
    if (!empty($buffer)) {
        echo "" . $buffer . "";
    }
};
$printPHPUnit();
$printPHPUnit("PHPUnit Test Prepare OK");
$printPHPUnit();
$printPHPUnit();
<?php

/*
 * 使用依赖注入Service Locator调用本SDK的Request
 */
use QcloudApi\Integrate\ServiceLocator;
require __DIR__ . '/../common.php';
//(以下代码必须且只需要调用一次,用于初始化依赖注入Service Locator的实例(\QcloudApi\Integrate\ServiceLocator))
$SLConfig = array('configFile' => __DIR__ . '/ConfigServiceLocatorDefaultDemo.php');
ServiceLocator::setInstanceDefaultConfig($SLConfig);
//(以上代码必须且只需要调用一次)初始化依赖注入Service Locator的实例
//请注意这里和demo文件/demo/demo.php的不同。
//通过Service Locator,你可以随时调用,而无需重新初始化
$request = ServiceLocator::getInstance()->getService('AccountRequest');
$response = $request->send('DescribeProject', array(), 'GET');
if (!$response->isOk()) {
    exit("API Error!:" . var_export($response->getError(true)));
}
$result = $response->getResult();
var_export($result);