PageRenderTime 372ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/functional/WindowsAzure/Table/FunctionalTestBase.php

https://bitbucket.org/skudatech/azure-sdk-for-php
PHP | 125 lines | 84 code | 15 blank | 26 comment | 16 complexity | 9238462d2ce91a3b30330876a589748e MD5 | raw file
  1. <?php
  2. /**
  3. * LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. * PHP version 5
  15. *
  16. * @category Microsoft
  17. * @package Tests\Functional\WindowsAzure\Table
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright 2012 Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. * @link https://github.com/windowsazure/azure-sdk-for-php
  22. */
  23. namespace Tests\Functional\WindowsAzure\Table;
  24. use WindowsAzure\Common\Internal\Utilities;
  25. use WindowsAzure\Table\Models\Entity;
  26. use WindowsAzure\Table\Models\Filters\Filter;
  27. class FunctionalTestBase extends IntegrationTestBase
  28. {
  29. public static function setUpBeforeClass()
  30. {
  31. parent::setUpBeforeClass();
  32. $testBase = new FunctionalTestBase();
  33. $testBase->setUp();
  34. TableServiceFunctionalTestData::setupData();
  35. foreach(TableServiceFunctionalTestData::$testTableNames as $name) {
  36. self::println('Creating Table: ' . $name);
  37. $testBase->restProxy->createTable($name);
  38. }
  39. }
  40. public static function tearDownAfterClass()
  41. {
  42. $testBase = new FunctionalTestBase();
  43. $testBase->setUp();
  44. foreach(TableServiceFunctionalTestData::$testTableNames as $name) {
  45. $testBase->safeDeleteTable($name);
  46. }
  47. parent::tearDownAfterClass();
  48. }
  49. /**
  50. * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::createTable
  51. * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::deleteTable
  52. */
  53. protected function clearTable($table)
  54. {
  55. $index = array_search($table, TableServiceFunctionalTestData::$testTableNames);
  56. if ($index !== false) {
  57. // This is a well-known table, so need to create a new one to replace it.
  58. TableServiceFunctionalTestData::$testTableNames[$index] = TableServiceFunctionalTestData::getInterestingTableName();
  59. $this->restProxy->createTable(TableServiceFunctionalTestData::$testTableNames[$index]);
  60. }
  61. $this->restProxy->deleteTable($table);
  62. }
  63. protected function getCleanTable()
  64. {
  65. $this->clearTable(TableServiceFunctionalTestData::$testTableNames[0]);
  66. return TableServiceFunctionalTestData::$testTableNames[0];
  67. }
  68. public static function println($msg)
  69. {
  70. error_log($msg);
  71. }
  72. public static function tmptostring($value)
  73. {
  74. if (is_null($value)) {
  75. return 'null';
  76. } else if (is_bool($value)) {
  77. return ($value == true ? 'true' : 'false');
  78. } else if ($value instanceof \DateTime) {
  79. return Utilities::convertToEdmDateTime($value);
  80. } else if ($value instanceof Entity) {
  81. return self::entityToString($value);
  82. } else if (is_array($value)) {
  83. return self::entityPropsToString($value);
  84. } else if ($value instanceof Filter) {
  85. return TableServiceFunctionalTestUtils::filtertoString($value);
  86. } else {
  87. return $value;
  88. }
  89. }
  90. public static function entityPropsToString($props)
  91. {
  92. $ret = '';
  93. foreach($props as $k => $value) {
  94. $ret .= $k . ':';
  95. if (is_null($value)) {
  96. $ret .= 'NULL PROP!';
  97. } else {
  98. $ret .= $value->getEdmType() . ':' . self::tmptostring($value->getValue());
  99. }
  100. $ret .= "\n";
  101. }
  102. return $ret;
  103. }
  104. public static function entityToString($ent)
  105. {
  106. $ret = 'ETag=' . self::tmptostring($ent->getETag()) . "\n";
  107. $ret .= 'Props=' . self::entityPropsToString($ent->getProperties());
  108. return $ret;
  109. }
  110. }