You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. use Luticate\Utils\Dbo\LuDboDeserializeException;
  3. use Luticate\Utils\Dbo\LuIntDboArray;
  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 LuIntDboArrayTest extends \PHPUnit_Framework_TestCase
  12. {
  13. public function testArrayEmpty()
  14. {
  15. $dbo = LuIntDboArray::jsonDeserialize([]);
  16. $this->assertSame([], $dbo->getArray());
  17. }
  18. public function testArrayString()
  19. {
  20. $dbo = LuIntDboArray::jsonDeserialize(["42"]);
  21. $this->assertSame([42], $dbo->getArray());
  22. }
  23. public function testArrayMultipleString()
  24. {
  25. $dbo = LuIntDboArray::jsonDeserialize(["42", "24", "48"]);
  26. $this->assertSame([42, 24, 48], $dbo->getArray());
  27. }
  28. public function testArrayInt()
  29. {
  30. $dbo = LuIntDboArray::jsonDeserialize([42]);
  31. $this->assertSame([42], $dbo->getArray());
  32. }
  33. public function testArrayMultipleInt()
  34. {
  35. $dbo = LuIntDboArray::jsonDeserialize([42, 24, 48]);
  36. $this->assertSame([42, 24, 48], $dbo->getArray());
  37. }
  38. public function testArrayStringIntPlusData()
  39. {
  40. $this->expectException(LuDboDeserializeException::class);
  41. LuIntDboArray::jsonDeserialize(["42test"]);
  42. }
  43. public function testArrayMultipleStringIntPlusData()
  44. {
  45. $this->expectException(LuDboDeserializeException::class);
  46. LuIntDboArray::jsonDeserialize(["42", 42, "42test"]);
  47. }
  48. public function testIntString()
  49. {
  50. $this->expectException(LuDboDeserializeException::class);
  51. LuIntDboArray::jsonDeserialize("42");
  52. }
  53. public function testInt()
  54. {
  55. $this->expectException(LuDboDeserializeException::class);
  56. LuIntDboArray::jsonDeserialize(42);
  57. }
  58. public function testIntNegativeString()
  59. {
  60. $this->expectException(LuDboDeserializeException::class);
  61. LuIntDboArray::jsonDeserialize("-42");
  62. }
  63. public function testIntNegative()
  64. {
  65. $this->expectException(LuDboDeserializeException::class);
  66. LuIntDboArray::jsonDeserialize(-42);
  67. }
  68. public function testFloat()
  69. {
  70. $this->expectException(LuDboDeserializeException::class);
  71. LuIntDboArray::jsonDeserialize(42.42);
  72. }
  73. public function testFloatString()
  74. {
  75. $this->expectException(LuDboDeserializeException::class);
  76. LuIntDboArray::jsonDeserialize("42.42");
  77. }
  78. public function testExponentialString()
  79. {
  80. $this->expectException(LuDboDeserializeException::class);
  81. LuIntDboArray::jsonDeserialize("42e+01");
  82. }
  83. public function testBool()
  84. {
  85. $this->expectException(LuDboDeserializeException::class);
  86. LuIntDboArray::jsonDeserialize(true);
  87. }
  88. public function testBoolString()
  89. {
  90. $this->expectException(LuDboDeserializeException::class);
  91. LuIntDboArray::jsonDeserialize("true");
  92. }
  93. public function testArrayFloat()
  94. {
  95. $this->expectException(LuDboDeserializeException::class);
  96. LuIntDboArray::jsonDeserialize([42.42]);
  97. }
  98. public function testNull()
  99. {
  100. $this->expectException(LuDboDeserializeException::class);
  101. LuIntDboArray::jsonDeserialize(null);
  102. }
  103. public function testObject()
  104. {
  105. $this->expectException(LuDboDeserializeException::class);
  106. LuIntDboArray::jsonDeserialize(new self());
  107. }
  108. }