DeleteTableTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Aliyun\OTS\Tests;
  3. use Aliyun\OTS;
  4. use Aliyun\OTS\ColumnTypeConst;
  5. require __DIR__ . "/TestBase.php";
  6. require __DIR__ . "/../../../vendor/autoload.php";
  7. $usedTables = array (
  8. "myTable"
  9. );
  10. SDKTestBase::cleanUp ($usedTables);
  11. class DeleteTableTest extends SDKTestBase {
  12. /*
  13. *
  14. * DeleteTable
  15. * 创建一个表,并删除,ListTable期望返回0个TableName。
  16. */
  17. public function testDeleteTable() {
  18. global $usedTables;
  19. $tablebody = array (
  20. "table_meta" => array (
  21. "table_name" => $usedTables[0],
  22. "primary_key_schema" => array (
  23. "PK1" => ColumnTypeConst::CONST_STRING,
  24. "PK2" => ColumnTypeConst::CONST_INTEGER,
  25. "PK3" => ColumnTypeConst::CONST_STRING,
  26. "PK4" => ColumnTypeConst::CONST_INTEGER
  27. )
  28. ),
  29. "reserved_throughput" => array (
  30. "capacity_unit" => array (
  31. "read" => 0,
  32. "write" => 0
  33. )
  34. )
  35. );
  36. $this->otsClient->createTable ($tablebody);
  37. $request = array (
  38. "table_name" => $usedTables[0]
  39. );
  40. // print_r($this->listtable->ListTable());
  41. $response = $this->otsClient->deleteTable ($request);
  42. $this->assertEquals ($response, array ());
  43. $this->assertEmpty ($this->otsClient->listTable (array ()));
  44. }
  45. /*
  46. *
  47. * DeleteTableEmpty
  48. * 指定表名为空,抛出对应错误信息 Invalid table name: ''.
  49. */
  50. public function testDeleteTableEmpty() {
  51. $request = array (
  52. "table_name" => ""
  53. );
  54. try {
  55. $this->otsClient->deleteTable ($request);
  56. $this->fail ('An expected exception has not been raised.');
  57. } catch (\Aliyun\OTS\OTSServerException $exc) {
  58. $c = "Invalid table name: ''.";
  59. $this->assertEquals ($c, $exc->getOTSErrorMessage ());
  60. }
  61. }
  62. /*
  63. *
  64. * DeleteTableEmpty
  65. * 指定不存在的表,抛出对应错误信息 Requested table does not exist
  66. */
  67. public function testNotExiteTableName() {
  68. $request = array (
  69. "table_name" => "TableThatNotExisting"
  70. );
  71. try {
  72. $this->otsClient->deleteTable ($request);
  73. $this->fail ('An expected exception has not been raised.');
  74. } catch (\Aliyun\OTS\OTSServerException $exc) {
  75. $c = "Requested table does not exist.";
  76. $this->assertEquals ($c, $exc->getOTSErrorMessage ());
  77. }
  78. }
  79. }