TableEntityTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_WindowsAzure
  17. * @subpackage UnitTests
  18. * @version $Id$
  19. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Service_WindowsAzure_TableEntityTest::main');
  24. }
  25. /**
  26. * Test helpers
  27. */
  28. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  29. require_once dirname(__FILE__) . '/../../../TestConfiguration.php.dist';
  30. /** Zend_Service_WindowsAzure_Storage_TableEntity */
  31. require_once 'Zend/Service/WindowsAzure/Storage/TableEntity.php';
  32. /**
  33. * @category Zend
  34. * @package Zend_Service_WindowsAzure
  35. * @subpackage UnitTests
  36. * @version $Id$
  37. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Service_WindowsAzure_TableEntityTest extends PHPUnit_Framework_TestCase
  41. {
  42. public static function main()
  43. {
  44. $suite = new PHPUnit_Framework_TestSuite("Zend_Service_WindowsAzure_TableEntityTest");
  45. $result = PHPUnit_TextUI_TestRunner::run($suite);
  46. }
  47. /**
  48. * Test constructor
  49. */
  50. public function testConstructor()
  51. {
  52. $target = new TSETTest_TestEntity('partition1', '000001');
  53. $this->assertEquals('partition1', $target->getPartitionKey());
  54. $this->assertEquals('000001', $target->getRowKey());
  55. }
  56. /**
  57. * Test get Azure values
  58. */
  59. public function testGetAzureValues()
  60. {
  61. $target = new TSETTest_TestEntity('partition1', '000001');
  62. $result = $target->getAzureValues();
  63. $this->assertEquals('Name', $result[0]->Name);
  64. $this->assertEquals(null, $result[0]->Value);
  65. $this->assertEquals('Age', $result[1]->Name);
  66. $this->assertEquals('Edm.Int64', $result[1]->Type);
  67. $this->assertEquals('Visible', $result[2]->Name);
  68. $this->assertEquals(false, $result[2]->Value);
  69. $this->assertEquals('partition1', $result[3]->Value);
  70. $this->assertEquals('000001', $result[4]->Value);
  71. }
  72. /**
  73. * Test set Azure values
  74. */
  75. public function testSetAzureValuesSuccess()
  76. {
  77. $values = array(
  78. 'PartitionKey' => 'partition1',
  79. 'RowKey' => '000001',
  80. 'Name' => 'Maarten',
  81. 'Age' => 25,
  82. 'Visible' => true
  83. );
  84. $target = new TSETTest_TestEntity();
  85. $target->setAzureValues($values);
  86. $this->assertEquals('partition1', $target->getPartitionKey());
  87. $this->assertEquals('000001', $target->getRowKey());
  88. $this->assertEquals('Maarten', $target->FullName);
  89. $this->assertEquals(25, $target->Age);
  90. $this->assertEquals(true, $target->Visible);
  91. }
  92. /**
  93. * Test set Azure values
  94. */
  95. public function testSetAzureValuesFailure()
  96. {
  97. $values = array(
  98. 'PartitionKey' => 'partition1',
  99. 'RowKey' => '000001'
  100. );
  101. $exceptionRaised = false;
  102. $target = new TSETTest_TestEntity();
  103. try
  104. {
  105. $target->setAzureValues($values, true);
  106. }
  107. catch (Exception $ex) {
  108. $exceptionRaised = true;
  109. }
  110. $this->assertTrue($exceptionRaised);
  111. }
  112. }
  113. /**
  114. * Test entity
  115. */
  116. class TSETTest_TestEntity extends Zend_Service_WindowsAzure_Storage_TableEntity
  117. {
  118. /**
  119. * @azure Name
  120. */
  121. public $FullName;
  122. /**
  123. * @azure Age Edm.Int64
  124. */
  125. public $Age;
  126. /**
  127. * @azure Visible Edm.Boolean
  128. */
  129. public $Visible = false;
  130. }
  131. // Call Zend_Service_WindowsAzure_TableEntityTest::main() if this source file is executed directly.
  132. if (PHPUnit_MAIN_METHOD == "Zend_Service_WindowsAzure_TableEntityTest::main") {
  133. Zend_Service_WindowsAzure_TableEntityTest::main();
  134. }