您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

LuDboDeserializeTest.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. use Luticate\Utils\Dbo\LuDbo;
  3. use Luticate\Utils\Dbo\LuDboConstraintException;
  4. /**
  5. * Created by PhpStorm.
  6. * User: robin
  7. * Date: 6/5/16
  8. * Time: 7:02 PM
  9. */
  10. class TestDbo extends LuDbo {
  11. /**
  12. * @var $_test string
  13. */
  14. private $_test;
  15. /**
  16. * @return string
  17. */
  18. public function getTest()
  19. {
  20. return $this->_test;
  21. }
  22. /**
  23. * @param string $test
  24. */
  25. public function setTest($test)
  26. {
  27. $this->_test = $test;
  28. }
  29. public function ensure42()
  30. {
  31. if ($this->_test != "42") {
  32. throw new LuDboConstraintException("Only 42 is allowed");
  33. }
  34. }
  35. }
  36. class TestDbo2 extends LuDbo {
  37. /**
  38. * @var $_test2 TestDbo[]
  39. */
  40. private $_test2;
  41. /**
  42. * @var $_test3 TestDbo
  43. * @nullable
  44. */
  45. private $_test3;
  46. /**
  47. * @return TestDbo[]
  48. */
  49. public function getTest2()
  50. {
  51. return $this->_test2;
  52. }
  53. /**
  54. * @param TestDbo[] $test2
  55. */
  56. public function setTest2($test2)
  57. {
  58. $this->_test2 = $test2;
  59. }
  60. /**
  61. * @return TestDbo
  62. */
  63. public function getTest3()
  64. {
  65. return $this->_test3;
  66. }
  67. /**
  68. * @param TestDbo $test3
  69. */
  70. public function setTest3($test3)
  71. {
  72. $this->_test3 = $test3;
  73. }
  74. }
  75. class LuDboDeserializeTest extends \PHPUnit_Framework_TestCase{
  76. public function test()
  77. {
  78. $json = ["test" => "Test."];
  79. $this->assertSame($json, LuDbo::deserializeValue($json, 'TestDbo')->jsonSerialize());
  80. }
  81. public function test2()
  82. {
  83. $json = [
  84. "test2" => [
  85. ["test" => "Test."],
  86. ["test" => "Test.2"]
  87. ],
  88. "test3" => ["test" => "Test.3"]
  89. ];
  90. $this->assertSame($json, LuDbo::deserializeValue($json, 'TestDbo2')->jsonSerialize());
  91. }
  92. public function test3()
  93. {
  94. $json = [
  95. "test2" => [
  96. ["test" => "Test."],
  97. ["test" => "Test.2"]
  98. ],
  99. "test3" => null
  100. ];
  101. $this->assertSame($json, LuDbo::deserializeValue($json, 'TestDbo2')->jsonSerialize());
  102. }
  103. public function test4()
  104. {
  105. $json = [
  106. "test2" => [
  107. ["test" => "Test."],
  108. null
  109. ],
  110. "test3" => null
  111. ];
  112. $this->assertSame($json, LuDbo::deserializeValue($json, 'TestDbo2')->jsonSerialize());
  113. }
  114. }