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

LuBoolDboArrayTest.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. use Luticate\Utils\Dbo\LuDboDeserializeException;
  3. use Luticate\Utils\Dbo\LuBoolDboArray;
  4. use Luticate\Utils\Dbo\LuIntDbo;
  5. /**
  6. * Created by PhpStorm.
  7. * User: robin
  8. * Date: 5/29/16
  9. * Time: 2:57 PM
  10. */
  11. class LuBoolDboArrayTest extends \PHPUnit_Framework_TestCase
  12. {
  13. public function testArrayEmpty()
  14. {
  15. $dbo = LuBoolDboArray::jsonDeserialize([]);
  16. $this->assertSame([], $dbo->getArray());
  17. }
  18. public function testArrayStringTrue()
  19. {
  20. $dbo = LuBoolDboArray::jsonDeserialize(["true"]);
  21. $this->assertSame([true], $dbo->getArray());
  22. }
  23. public function testArrayStringTrueCase()
  24. {
  25. $dbo = LuBoolDboArray::jsonDeserialize(["tRue"]);
  26. $this->assertSame([true], $dbo->getArray());
  27. }
  28. public function testArrayStringFalse()
  29. {
  30. $dbo = LuBoolDboArray::jsonDeserialize(["false"]);
  31. $this->assertSame([false], $dbo->getArray());
  32. }
  33. public function testArrayStringFalseCase()
  34. {
  35. $dbo = LuBoolDboArray::jsonDeserialize(["faLse"]);
  36. $this->assertSame([false], $dbo->getArray());
  37. }
  38. public function testArrayMultipleString()
  39. {
  40. $dbo = LuBoolDboArray::jsonDeserialize(["true", "false", "true"]);
  41. $this->assertSame([true, false, true], $dbo->getArray());
  42. }
  43. public function testArrayMultipleStringPlusData()
  44. {
  45. $this->expectException(LuDboDeserializeException::class);
  46. LuBoolDboArray::jsonDeserialize(["true", null, "true"]);
  47. }
  48. public function testArrayInt()
  49. {
  50. $this->expectException(LuDboDeserializeException::class);
  51. LuBoolDboArray::jsonDeserialize([42]);
  52. }
  53. public function testArrayMultipleInt()
  54. {
  55. $this->expectException(LuDboDeserializeException::class);
  56. LuBoolDboArray::jsonDeserialize([42, 24, 48]);
  57. }
  58. public function testArrayMultipleStringInt()
  59. {
  60. $this->expectException(LuDboDeserializeException::class);
  61. LuBoolDboArray::jsonDeserialize(["42", "24", "48"]);
  62. }
  63. public function testArrayStringInt()
  64. {
  65. $this->expectException(LuDboDeserializeException::class);
  66. LuBoolDboArray::jsonDeserialize(["42"]);
  67. }
  68. public function testArrayStringIntPlusData()
  69. {
  70. $this->expectException(LuDboDeserializeException::class);
  71. LuBoolDboArray::jsonDeserialize(["42test"]);
  72. }
  73. public function testArrayMultipleStringIntPlusData()
  74. {
  75. $this->expectException(LuDboDeserializeException::class);
  76. LuBoolDboArray::jsonDeserialize(["42", 42, "42test"]);
  77. }
  78. public function testIntString()
  79. {
  80. $this->expectException(LuDboDeserializeException::class);
  81. LuBoolDboArray::jsonDeserialize("42");
  82. }
  83. public function testInt()
  84. {
  85. $this->expectException(LuDboDeserializeException::class);
  86. LuBoolDboArray::jsonDeserialize(42);
  87. }
  88. public function testIntNegativeString()
  89. {
  90. $this->expectException(LuDboDeserializeException::class);
  91. LuBoolDboArray::jsonDeserialize("-42");
  92. }
  93. public function testIntNegative()
  94. {
  95. $this->expectException(LuDboDeserializeException::class);
  96. LuBoolDboArray::jsonDeserialize(-42);
  97. }
  98. public function testFloat()
  99. {
  100. $this->expectException(LuDboDeserializeException::class);
  101. LuBoolDboArray::jsonDeserialize(42.42);
  102. }
  103. public function testFloatString()
  104. {
  105. $this->expectException(LuDboDeserializeException::class);
  106. LuBoolDboArray::jsonDeserialize("42.42");
  107. }
  108. public function testExponentialString()
  109. {
  110. $this->expectException(LuDboDeserializeException::class);
  111. LuBoolDboArray::jsonDeserialize("42e+01");
  112. }
  113. public function testBool()
  114. {
  115. $this->expectException(LuDboDeserializeException::class);
  116. LuBoolDboArray::jsonDeserialize(true);
  117. }
  118. public function testBoolString()
  119. {
  120. $this->expectException(LuDboDeserializeException::class);
  121. LuBoolDboArray::jsonDeserialize("true");
  122. }
  123. public function testArrayFloat()
  124. {
  125. $this->expectException(LuDboDeserializeException::class);
  126. LuBoolDboArray::jsonDeserialize([42.42]);
  127. }
  128. public function testNull()
  129. {
  130. $this->expectException(LuDboDeserializeException::class);
  131. LuBoolDboArray::jsonDeserialize(null);
  132. }
  133. public function testObject()
  134. {
  135. $this->expectException(LuDboDeserializeException::class);
  136. LuBoolDboArray::jsonDeserialize(new self());
  137. }
  138. }