TableEntityTest.php 4.5 KB

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