1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace EasySwoole\Validate\tests;
- class IntegerTest extends BaseTestCase
- {
-
- public function testValidCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('integer')->integer();
- $validateResult = $this->validate->validate(['integer' => 1]);
- $this->assertTrue($validateResult);
-
- $this->freeValidate();
- $this->validate->addColumn('integer')->integer();
- $validateResult = $this->validate->validate(['integer' => '100']);
- $this->assertTrue($validateResult);
- }
-
- public function testDefaultErrorMsgCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('integer')->integer();
- $validateResult = $this->validate->validate(['integer' => 'xxx']);
- $this->assertFalse($validateResult);
- $this->assertEquals('integer只能是整数', $this->validate->getError()->__toString());
-
- $this->freeValidate();
- $this->validate->addColumn('integer', '个数')->integer();
- $validateResult = $this->validate->validate(['integer' => 0.001]);
- $this->assertFalse($validateResult);
- $this->assertEquals('个数只能是整数', $this->validate->getError()->__toString());
- }
-
- public function testCustomErrorMsgCase()
- {
- $this->freeValidate();
- $this->validate->addColumn('integer')->integer('请输入正确的数量');
- $validateResult = $this->validate->validate(['integer' => 0.001]);
- $this->assertFalse($validateResult);
- $this->assertEquals('请输入正确的数量', $this->validate->getError()->__toString());
- }
- }
|