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.

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