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.

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