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.

LuStringDboTest.php 2.6KB

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