TimestampAfterDateTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace EasySwoole\Validate\tests;
  3. /**
  4. * @internal
  5. */
  6. class TimestampAfterDateTest extends BaseTestCase
  7. {
  8. /*
  9. * 合法
  10. */
  11. public function testValidCase()
  12. {
  13. $this->freeValidate();
  14. $this->validate->addColumn('time')->timestampAfterDate(date('YmdHis', time() - 1));
  15. $bool = $this->validate->validate(['time' => time()]);
  16. $this->assertTrue($bool);
  17. }
  18. /*
  19. * 默认错误信息
  20. */
  21. public function testDefaultErrorMsgCase()
  22. {
  23. $this->freeValidate();
  24. $this->validate->addColumn('time')->timestampAfterDate($time = date('YmdHis', time() + 1));
  25. $bool = $this->validate->validate(['time' => time()]);
  26. $this->assertFalse($bool);
  27. $this->assertEquals("time必须在'{$time}'之后", $this->validate->getError()->__toString());
  28. }
  29. /*
  30. * 自定义错误信息
  31. */
  32. public function testCustomErrorMsgCase()
  33. {
  34. $this->freeValidate();
  35. $this->validate->addColumn('time')->timestampAfterDate(date('YmdHis', time() - 1), '无效时间戳');
  36. $bool = $this->validate->validate(['time' => 'blank']);
  37. $this->assertFalse($bool);
  38. $this->assertEquals('无效时间戳', $this->validate->getError()->__toString());
  39. }
  40. }