GreaterThanWithColumnTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace EasySwoole\Validate\tests;
  3. /**
  4. * @internal
  5. */
  6. class GreaterThanWithColumnTest extends BaseTestCase
  7. {
  8. public function testValidCase()
  9. {
  10. $this->freeValidate();
  11. $this->validate->addColumn('bar')->greaterThanWithColumn('foo');
  12. $validateResult = $this->validate->validate(['bar' => 11, 'foo' => 10]);
  13. $this->assertTrue($validateResult);
  14. }
  15. public function testDefaultErrorMsgCase()
  16. {
  17. $this->freeValidate();
  18. $this->validate->addColumn('bar')->greaterThanWithColumn('foo');
  19. $validateResult = $this->validate->validate(['bar' => 10, 'foo' => 11]);
  20. $this->assertFalse($validateResult);
  21. $this->assertEquals('bar必须大于foo的值', $this->validate->getError()->__toString());
  22. $this->freeValidate();
  23. $this->validate->addColumn('bar', 'Bar')->greaterThanWithColumn('foo');
  24. $this->validate->addColumn('foo', 'Foo');
  25. $validateResult = $this->validate->validate(['bar' => 10, 'foo' => 11]);
  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')->greaterThanWithColumn('foo', 'foo不能大于bar');
  34. $validateResult = $this->validate->validate(['bar' => 10, 'foo' => 11]);
  35. $this->assertFalse($validateResult);
  36. $this->assertEquals('foo不能大于bar', $this->validate->getError()->__toString());
  37. }
  38. }