DecimalTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace EasySwoole\Validate\tests;
  3. /**
  4. * @internal
  5. */
  6. class DecimalTest extends BaseTestCase
  7. {
  8. /*
  9. * 合法
  10. */
  11. public function testValidCase()
  12. {
  13. $this->freeValidate();
  14. $this->validate->addColumn('no')->decimal();
  15. $bool = $this->validate->validate(['no' => 1111]);
  16. $this->assertTrue($bool);
  17. $this->freeValidate();
  18. $this->validate->addColumn('no')->decimal(1);
  19. $bool = $this->validate->validate(['no' => 1111.1]);
  20. $this->assertTrue($bool);
  21. }
  22. /*
  23. * 默认错误信息
  24. */
  25. public function testDefaultErrorMsgCase()
  26. {
  27. $this->freeValidate();
  28. $this->freeValidate();
  29. $this->validate->addColumn('no')->decimal(2);
  30. $bool = $this->validate->validate(['no' => 1234]);
  31. $this->assertFalse($bool);
  32. $this->assertEquals('no只能是小数', $this->validate->getError()->__toString());
  33. }
  34. /*
  35. * 自定义错误信息
  36. */
  37. public function testCustomErrorMsgCase()
  38. {
  39. $this->freeValidate();
  40. $this->freeValidate();
  41. $this->validate->addColumn('no')->decimal(2, 'no只能是小数');
  42. $bool = $this->validate->validate(['no' => 1161709455.999]);
  43. $this->assertFalse($bool);
  44. $this->assertEquals('no只能是小数', $this->validate->getError()->__toString());
  45. }
  46. }