/tests/unit/WindowsAzure/Common/Models/ServicePropertiesTest.php

https://bitbucket.org/skudatech/azure-sdk-for-php · PHP · 173 lines · 74 code · 25 blank · 74 comment · 0 complexity · 9349db0fd79f2e3e7a87562984497bb1 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\Unit\WindowsAzure\Common\Models
  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\Unit\WindowsAzure\Common\Models;
  24. use Tests\Framework\TestResources;
  25. use WindowsAzure\Common\Internal\Utilities;
  26. use WindowsAzure\Common\Models\Logging;
  27. use WindowsAzure\Common\Models\Metrics;
  28. use WindowsAzure\Common\Models\ServiceProperties;
  29. use WindowsAzure\Common\Models\GetServicePropertiesResult;
  30. use WindowsAzure\Common\Internal\Serialization\XmlSerializer;
  31. /**
  32. * Unit tests for class ServiceProperties
  33. *
  34. * @category Microsoft
  35. * @package Tests\Unit\WindowsAzure\Common\Models
  36. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  37. * @copyright 2012 Microsoft Corporation
  38. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  39. * @version Release: @package_version@
  40. * @link https://github.com/windowsazure/azure-sdk-for-php
  41. */
  42. class ServicePropertiesTest extends \PHPUnit_Framework_TestCase
  43. {
  44. /**
  45. * @covers WindowsAzure\Common\Models\ServiceProperties::create
  46. */
  47. public function testCreate()
  48. {
  49. // Setup
  50. $sample = TestResources::getServicePropertiesSample();
  51. $logging = Logging::create($sample['Logging']);
  52. $metrics = Metrics::create($sample['Metrics']);
  53. // Test
  54. $result = ServiceProperties::create($sample);
  55. // Assert
  56. $this->assertEquals($logging, $result->getLogging());
  57. $this->assertEquals($metrics, $result->getMetrics());
  58. }
  59. /**
  60. * @covers WindowsAzure\Common\Models\ServiceProperties::setLogging
  61. */
  62. public function testSetLogging()
  63. {
  64. // Setup
  65. $sample = TestResources::getServicePropertiesSample();
  66. $logging = Logging::create($sample['Logging']);
  67. $result = new ServiceProperties();
  68. // Test
  69. $result->setLogging($logging);
  70. // Assert
  71. $this->assertEquals($logging, $result->getLogging());
  72. }
  73. /**
  74. * @covers WindowsAzure\Common\Models\ServiceProperties::getLogging
  75. */
  76. public function testGetLogging()
  77. {
  78. // Setup
  79. $sample = TestResources::getServicePropertiesSample();
  80. $logging = Logging::create($sample['Logging']);
  81. $result = new ServiceProperties();
  82. $result->setLogging($logging);
  83. // Test
  84. $actual = $result->getLogging($logging);
  85. // Assert
  86. $this->assertEquals($logging, $actual);
  87. }
  88. /**
  89. * @covers WindowsAzure\Common\Models\ServiceProperties::setMetrics
  90. */
  91. public function testSetMetrics()
  92. {
  93. // Setup
  94. $sample = TestResources::getServicePropertiesSample();
  95. $metrics = Metrics::create($sample['Metrics']);
  96. $result = new ServiceProperties();
  97. // Test
  98. $result->setMetrics($metrics);
  99. // Assert
  100. $this->assertEquals($metrics, $result->getMetrics());
  101. }
  102. /**
  103. * @covers WindowsAzure\Common\Models\ServiceProperties::getMetrics
  104. */
  105. public function testGetMetrics()
  106. {
  107. // Setup
  108. $sample = TestResources::getServicePropertiesSample();
  109. $metrics = Metrics::create($sample['Metrics']);
  110. $result = new ServiceProperties();
  111. $result->setMetrics($metrics);
  112. // Test
  113. $actual = $result->getMetrics($metrics);
  114. // Assert
  115. $this->assertEquals($metrics, $actual);
  116. }
  117. /**
  118. * @covers WindowsAzure\Common\Models\ServiceProperties::toArray
  119. */
  120. public function testToArray()
  121. {
  122. // Setup
  123. $properties = ServiceProperties::create(TestResources::getServicePropertiesSample());
  124. $expected = array(
  125. 'Logging' => $properties->getLogging()->toArray(),
  126. 'Metrics' => $properties->getMetrics()->toArray()
  127. );
  128. // Test
  129. $actual = $properties->toArray();
  130. // Assert
  131. $this->assertEquals($expected, $actual);
  132. }
  133. /**
  134. * @covers WindowsAzure\Common\Models\ServiceProperties::toXml
  135. */
  136. public function testToXml()
  137. {
  138. // Setup
  139. $properties = ServiceProperties::create(TestResources::getServicePropertiesSample());
  140. $xmlSerializer = new XmlSerializer();
  141. // Test
  142. $actual = $properties->toXml($xmlSerializer);
  143. // Assert
  144. $actualParsed = Utilities::unserialize($actual);
  145. $actualProperties = GetServicePropertiesResult::create($actualParsed);
  146. $this->assertEquals($actualProperties->getValue(), $properties);
  147. }
  148. }