BetweenLenTest.php 1.5 KB

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