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.

LuFloatDboArrayTest.php 3.8KB

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