LessThanWithColumnTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace EasySwoole\Validate\tests;
  3. /**
  4. * @internal
  5. */
  6. class LessThanWithColumnTest extends BaseTestCase
  7. {
  8. public function testValidCase()
  9. {
  10. $this->freeValidate();
  11. $this->validate->addColumn('bar')->lessThanWithColumn('foo');
  12. $validateResult = $this->validate->validate(['bar' => 10, 'foo' => 11]);
  13. $this->assertTrue($validateResult);
  14. }
  15. public function testDefaultErrorMsgCase()
  16. {
  17. $this->freeValidate();
  18. $this->validate->addColumn('bar')->lessThanWithColumn('foo');
  19. $validateResult = $this->validate->validate(['bar' => 10, 'foo' => 9]);
  20. $this->assertFalse($validateResult);
  21. $this->assertEquals('bar必须小于foo的值', $this->validate->getError()->__toString());
  22. $this->freeValidate();
  23. $this->validate->addColumn('bar', 'Bar')->lessThanWithColumn('foo');
  24. $this->validate->addColumn('foo', 'Foo');
  25. $validateResult = $this->validate->validate(['bar' => 10, 'foo' => 9]);
  26. $this->assertFalse($validateResult);
  27. $this->assertEquals('Bar必须小于Foo的值', $this->validate->getError()->__toString());
  28. }
  29. // 自定义错误信息断言
  30. public function testCustomErrorMsgCase()
  31. {
  32. $this->freeValidate();
  33. $this->validate->addColumn('bar')->lessThanWithColumn('foo', 'bar不能大于foo');
  34. $validateResult = $this->validate->validate(['bar' => 10, 'foo' => 9]);
  35. $this->assertFalse($validateResult);
  36. $this->assertEquals('bar不能大于foo', $this->validate->getError()->__toString());
  37. }
  38. }