TestBase.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Aliyun\OTS\Tests;
  3. include "TestConfig.php";
  4. use Aliyun\OTS;
  5. date_default_timezone_set ('Asia/Shanghai');
  6. // require(__DIR__ . "/../../../vendor/autoload.php");
  7. class SDKTestBase extends \PHPUnit_Framework_TestCase {
  8. protected $otsClient;
  9. public function __construct() {
  10. parent::__construct ();
  11. $this->otsClient = SDKTestBase::createOTSClient ();
  12. }
  13. public static function createOTSClient() {
  14. $sdkTestConfig = array (
  15. 'EndPoint' => SDK_TEST_END_POINT,
  16. 'AccessKeyID' => SDK_TEST_ACCESS_KEY_ID,
  17. 'AccessKeySecret' => SDK_TEST_ACCESS_KEY_SECRET,
  18. 'InstanceName' => SDK_TEST_INSTANCE_NAME
  19. );
  20. return new \Aliyun\OTS\OTSClient ($sdkTestConfig);
  21. }
  22. public function cleanUp(array $tables = null) {
  23. if ($tables != null) {
  24. $otsClient = SDKTestBase::createOTSClient ();
  25. $tableNames = $otsClient->listTable (array ());
  26. foreach ($tables as $tableName) {
  27. if (in_array ($tableName, $tableNames))
  28. $otsClient->deleteTable (array (
  29. 'table_name' => $tableName
  30. ));
  31. }
  32. } else {
  33. $otsClient = SDKTestBase::createOTSClient ();
  34. $tableNames = $otsClient->listTable (array ());
  35. foreach ($tableNames as $tableName) {
  36. $otsClient->deleteTable (array (
  37. 'table_name' => $tableName
  38. ));
  39. }
  40. }
  41. }
  42. public static function putInitialData(array $request) {
  43. $otsClient = SDKTestBase::createOTSClient ();
  44. $otsClient->putRow ($request);
  45. }
  46. public static function createInitialTable(array $request) {
  47. $otsClient = SDKTestBase::createOTSClient ();
  48. $otsClient->createTable ($request);
  49. }
  50. public static function waitForTableReady() {
  51. sleep (30);
  52. }
  53. public static function waitForCUAdjustmentInterval() {
  54. sleep (125);
  55. }
  56. public function tearDown() {
  57. }
  58. }