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.

LuIntDboTest.php 2.5KB

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