123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace EasySwoole\Validate\tests;
- class BetweenTest extends BaseTestCase
- {
-
- public function testValidCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('number')->between(5, 10);
- $validateResult = $this->validate->validate(['number' => 6]);
- $this->assertTrue($validateResult);
-
- $this->freeValidate();
- $this->validate->addColumn('number')->between(5, 10);
- $validateResult = $this->validate->validate(['number' => 6.33333]);
- $this->assertTrue($validateResult);
-
- $this->freeValidate();
- $this->validate->addColumn('number')->between(5, 10);
- $validateResult = $this->validate->validate(['number' => '6']);
- $this->assertTrue($validateResult);
-
- $this->freeValidate();
- $this->validate->addColumn('number')->between(5, 10);
- $validateResult = $this->validate->validate(['number' => 5]);
- $this->assertTrue($validateResult);
-
- $this->freeValidate();
- $this->validate->addColumn('number')->between(5, 10);
- $validateResult = $this->validate->validate(['number' => 10]);
- $this->assertTrue($validateResult);
- }
-
- public function testDefaultErrorMsgCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('number')->between(5, 10);
- $validateResult = $this->validate->validate(['number' => 20]);
- $this->assertFalse($validateResult);
- $this->assertEquals('number只能在 5 - 10 之间', $this->validate->getError()->__toString());
-
- $this->freeValidate();
- $this->validate->addColumn('number', '年龄')->between(5, 10);
- $validateResult = $this->validate->validate(['number' => 'aaa']);
- $this->assertFalse($validateResult);
- $this->assertEquals('年龄只能在 5 - 10 之间', $this->validate->getError()->__toString());
- }
-
- public function testCustomErrorMsgCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('number')->between(5, 10, '您输入的年龄不符');
- $validateResult = $this->validate->validate(['number' => '!']);
- $this->assertFalse($validateResult);
- $this->assertEquals('您输入的年龄不符', $this->validate->getError()->__toString());
- }
- }
|