AlphaDashTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace EasySwoole\Validate\tests;
  3. /**
  4. * @internal
  5. */
  6. class AlphaDashTest extends BaseTestCase
  7. {
  8. /*
  9. * 合法
  10. */
  11. public function testValidCase()
  12. {
  13. $this->freeValidate();
  14. $this->validate->addColumn('no')->alphaDash();
  15. $bool = $this->validate->validate(['no' => 'A_1161709455']);
  16. $this->assertTrue($bool);
  17. }
  18. /*
  19. * 默认错误信息
  20. */
  21. public function testDefaultErrorMsgCase()
  22. {
  23. $this->freeValidate();
  24. $this->freeValidate();
  25. $this->validate->addColumn('no')->alphaDash();
  26. $bool = $this->validate->validate(['no' => '1161709455.999']);
  27. $this->assertFalse($bool);
  28. $this->assertEquals('no只能是字母数字下划线和破折号', $this->validate->getError()->__toString());
  29. }
  30. /*
  31. * 自定义错误信息
  32. */
  33. public function testCustomErrorMsgCase()
  34. {
  35. $this->freeValidate();
  36. $this->freeValidate();
  37. $this->validate->addColumn('no')->alphaDash('学号只能由字母数字下划线和破折号构成');
  38. $bool = $this->validate->validate(['no' => '1161709455.999']);
  39. $this->assertFalse($bool);
  40. $this->assertEquals('学号只能由字母数字下划线和破折号构成', $this->validate->getError()->__toString());
  41. }
  42. }