Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LuStringDboTest.php 2.7KB

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