TableEntityTest.php 3.7 KB

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