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

LuDboDeserializeTest.php 2.2KB

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