TableEntityTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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-2012 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. require_once 'PHPUnit/Framework/TestCase.php';
  31. /** Zend_Service_WindowsAzure_Storage_TableEntity */
  32. require_once 'Zend/Service/WindowsAzure/Storage/TableEntity.php';
  33. /**
  34. * @category Zend
  35. * @package Zend_Service_WindowsAzure
  36. * @subpackage UnitTests
  37. * @version $Id$
  38. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Service_WindowsAzure_TableEntityTest extends PHPUnit_Framework_TestCase
  42. {
  43. public static function main()
  44. {
  45. $suite = new PHPUnit_Framework_TestSuite("Zend_Service_WindowsAzure_TableEntityTest");
  46. $result = PHPUnit_TextUI_TestRunner::run($suite);
  47. }
  48. /**
  49. * Test constructor
  50. */
  51. public function testConstructor()
  52. {
  53. $target = new TSETTest_TestEntity('partition1', '000001');
  54. $this->assertEquals('partition1', $target->getPartitionKey());
  55. $this->assertEquals('000001', $target->getRowKey());
  56. }
  57. /**
  58. * Test get Azure values
  59. */
  60. public function testGetAzureValues()
  61. {
  62. $target = new TSETTest_TestEntity('partition1', '000001');
  63. $result = $target->getAzureValues();
  64. $this->assertEquals('Name', $result[0]->Name);
  65. $this->assertEquals(null, $result[0]->Value);
  66. $this->assertEquals('Age', $result[1]->Name);
  67. $this->assertEquals('Edm.Int64', $result[1]->Type);
  68. $this->assertEquals('Visible', $result[2]->Name);
  69. $this->assertEquals(false, $result[2]->Value);
  70. $this->assertEquals('partition1', $result[3]->Value);
  71. $this->assertEquals('000001', $result[4]->Value);
  72. }
  73. /**
  74. * Test set Azure values
  75. */
  76. public function testSetAzureValuesSuccess()
  77. {
  78. $values = array(
  79. 'PartitionKey' => 'partition1',
  80. 'RowKey' => '000001',
  81. 'Name' => 'Maarten',
  82. 'Age' => 25,
  83. 'Visible' => true
  84. );
  85. $target = new TSETTest_TestEntity();
  86. $target->setAzureValues($values);
  87. $this->assertEquals('partition1', $target->getPartitionKey());
  88. $this->assertEquals('000001', $target->getRowKey());
  89. $this->assertEquals('Maarten', $target->FullName);
  90. $this->assertEquals(25, $target->Age);
  91. $this->assertEquals(true, $target->Visible);
  92. }
  93. /**
  94. * Test set Azure values
  95. */
  96. public function testSetAzureValuesFailure()
  97. {
  98. $values = array(
  99. 'PartitionKey' => 'partition1',
  100. 'RowKey' => '000001'
  101. );
  102. $exceptionRaised = false;
  103. $target = new TSETTest_TestEntity();
  104. try
  105. {
  106. $target->setAzureValues($values, true);
  107. }
  108. catch (Exception $ex) {
  109. $exceptionRaised = true;
  110. }
  111. $this->assertTrue($exceptionRaised);
  112. }
  113. }
  114. /**
  115. * Test entity
  116. */
  117. class TSETTest_TestEntity extends Zend_Service_WindowsAzure_Storage_TableEntity
  118. {
  119. /**
  120. * @azure Name
  121. */
  122. public $FullName;
  123. /**
  124. * @azure Age Edm.Int64
  125. */
  126. public $Age;
  127. /**
  128. * @azure Visible Edm.Boolean
  129. */
  130. public $Visible = false;
  131. }
  132. // Call Zend_Service_WindowsAzure_TableEntityTest::main() if this source file is executed directly.
  133. if (PHPUnit_MAIN_METHOD == "Zend_Service_WindowsAzure_TableEntityTest::main") {
  134. Zend_Service_WindowsAzure_TableEntityTest::main();
  135. }