PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/codes-php/phpjakarta/tests/functional/WindowsAzure/ServiceBus/IntegrationTestBase.php

http://bukuphpjs.codeplex.com
PHP | 105 lines | 70 code | 9 blank | 26 comment | 10 complexity | 80983ae4fc8204e0550d457b9d9a76bc MD5 | raw file
Possible License(s): Apache-2.0, MIT, LGPL-2.1
  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\ServiceBus
  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\ServiceBus;
  24. use Tests\Framework\FiddlerFilter;
  25. use Tests\Framework\ServiceBusRestProxyTestBase;
  26. use WindowsAzure\Common\Internal\Utilities;
  27. use WindowsAzure\ServiceBus\Models\ReceiveMessageOptions;
  28. use WindowsAzure\ServiceBus\Models\QueueInfo;
  29. class IntegrationTestBase extends ServiceBusRestProxyTestBase
  30. {
  31. public function setUp()
  32. {
  33. parent::setUp();
  34. $fiddlerFilter = new FiddlerFilter();
  35. $this->restProxy = $this->restProxy->withFilter($fiddlerFilter);
  36. }
  37. public static function setUpBeforeClass()
  38. {
  39. parent::setUpBeforeClass();
  40. self::initialize();
  41. }
  42. /**
  43. * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::createQueue
  44. * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::deleteQueue
  45. * @covers WindowsAzure\ServiceBus\ServiceBusRestProxy::receiveQueueMessage
  46. */
  47. public static function initialize()
  48. {
  49. $inst = new IntegrationTestBase();
  50. $inst->setUp();
  51. $restProxy = $inst->restProxy;
  52. $testAlphaExists = false;
  53. $queues = $restProxy->listQueues()->getQueueInfos();
  54. foreach($queues as $queue) {
  55. $queueName = $queue->getTitle();
  56. if (Utilities::startsWith($queueName, 'Test') || Utilities::startsWith($queueName, 'test')) {
  57. if (strtolower($queueName) == strtolower('TestAlpha')) {
  58. $testAlphaExists = true;
  59. $count = $queue->getQueueDescription()->getMessageCount();
  60. for ($i = 0; $i != $count; $i++) {
  61. $opts = new ReceiveMessageOptions();
  62. $opts->setTimeout(20);
  63. try {
  64. $restProxy->receiveQueueMessage($queueName, $opts);
  65. } catch (\Exception $ex) {
  66. error_log($ex->getMessage());
  67. }
  68. }
  69. } else {
  70. try {
  71. $restProxy->deleteQueue($queueName);
  72. } catch (\Exception $ex) {
  73. error_log($ex->getMessage());
  74. }
  75. }
  76. }
  77. }
  78. foreach($restProxy->listTopics()->getTopicInfos() as $topic) {
  79. $topicName = $topic->getTitle();
  80. if (Utilities::startsWith($topicName, 'Test') || Utilities::startsWith($topicName, 'test')) {
  81. try {
  82. $restProxy->deleteTopic($topicName);
  83. } catch (\Exception $ex) {
  84. error_log($ex->getMessage());
  85. }
  86. }
  87. }
  88. if (!$testAlphaExists) {
  89. try {
  90. $restProxy->createQueue(new QueueInfo('TestAlpha'));
  91. } catch (\Exception $ex) {
  92. error_log($ex->getMessage());
  93. }
  94. }
  95. }
  96. }