RequiredTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace EasySwoole\Validate\tests;
  3. /**
  4. * 必填测试用例
  5. * Class RequiredTest
  6. *
  7. * @internal
  8. */
  9. class RequiredTest extends BaseTestCase
  10. {
  11. /*
  12. * 合法
  13. */
  14. public function testValidCase()
  15. {
  16. $this->freeValidate();
  17. $this->validate->addColumn('phone')->required();
  18. $bool = $this->validate->validate(['phone' => '18959261286']);
  19. $this->assertTrue($bool);
  20. }
  21. /*
  22. * 默认错误信息
  23. */
  24. public function testDefaultErrorMsgCase()
  25. {
  26. $this->freeValidate();
  27. $this->validate->addColumn('phone')->required();
  28. $bool = $this->validate->validate([]);
  29. $this->assertFalse($bool);
  30. $this->assertEquals('phone必须填写', $this->validate->getError()->__toString());
  31. }
  32. /*
  33. * 自定义错误信息
  34. */
  35. public function testCustomErrorMsgCase()
  36. {
  37. $this->freeValidate();
  38. $this->validate->addColumn('phone')->required('手机号码必填');
  39. $bool = $this->validate->validate([]);
  40. $this->assertFalse($bool);
  41. $this->assertEquals('手机号码必填', $this->validate->getError()->__toString());
  42. }
  43. }