BetweenMbLenTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace EasySwoole\Validate\tests;
  3. /**
  4. * @internal
  5. */
  6. class BetweenMbLenTest extends BaseTestCase
  7. {
  8. /*
  9. * 合法
  10. */
  11. public function testValidCase()
  12. {
  13. $this->freeValidate();
  14. $this->validate->addColumn('name')->betweenMbLen(2, 6);
  15. $bool = $this->validate->validate(['name' => 'blank']);
  16. $this->assertTrue($bool);
  17. $this->freeValidate();
  18. $this->validate->addColumn('name')->betweenMbLen(2, 6);
  19. $bool = $this->validate->validate(['name' => '仙士可123']);
  20. $this->assertTrue($bool);
  21. /*
  22. * file
  23. */
  24. $this->freeValidate();
  25. $this->validate->addColumn('file')->betweenMbLen(1, 2);
  26. $bool = $this->validate->validate(['file' => (new UploadFile(__DIR__ . '/../res/easyswoole.png', 1, 200))]);
  27. $this->assertTrue($bool);
  28. }
  29. /*
  30. * 默认错误信息
  31. */
  32. public function testDefaultErrorMsgCase()
  33. {
  34. $this->freeValidate();
  35. $this->freeValidate();
  36. $this->validate->addColumn('name')->betweenMbLen(2, 4);
  37. $bool = $this->validate->validate(['name' => 'blank']);
  38. $this->assertFalse($bool);
  39. $this->assertEquals('name的长度只能在 2 - 4 之间', $this->validate->getError()->__toString());
  40. }
  41. /*
  42. * 自定义错误信息
  43. */
  44. public function testCustomErrorMsgCase()
  45. {
  46. $this->freeValidate();
  47. $this->freeValidate();
  48. $this->validate->addColumn('name')->betweenMbLen(2, 4, '姓名的长度只能2-4位');
  49. $bool = $this->validate->validate(['name' => '测试123']);
  50. $this->assertFalse($bool);
  51. $this->assertEquals('姓名的长度只能2-4位', $this->validate->getError()->__toString());
  52. }
  53. }