123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace EasySwoole\Validate\tests;
- class BoolTest extends BaseTestCase
- {
-
- public function testValidCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('boolean')->bool();
- $validateResult = $this->validate->validate(['boolean' => true]);
- $this->assertTrue($validateResult);
-
- $this->freeValidate();
- $this->validate->addColumn('boolean')->bool();
- $validateResult = $this->validate->validate(['boolean' => 1]);
- $this->assertTrue($validateResult);
-
- $this->freeValidate();
- $this->validate->addColumn('boolean')->bool();
- $validateResult = $this->validate->validate(['boolean' => false]);
- $this->assertTrue($validateResult);
-
- $this->freeValidate();
- $this->validate->addColumn('boolean')->bool();
- $validateResult = $this->validate->validate(['boolean' => 0]);
- $this->assertTrue($validateResult);
- }
-
- public function testDefaultErrorMsgCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('boolean')->bool();
- $validateResult = $this->validate->validate(['boolean' => 'true']);
- $this->assertFalse($validateResult);
- $this->assertEquals('boolean只能是布尔值', $this->validate->getError()->__toString());
-
- $this->freeValidate();
- $this->validate->addColumn('boolean', '状态')->bool();
- $validateResult = $this->validate->validate(['boolean' => '1']);
- $this->assertFalse($validateResult);
- $this->assertEquals('状态只能是布尔值', $this->validate->getError()->__toString());
- }
-
- public function testCustomErrorMsgCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('boolean')->bool('状态只能是开启或关闭');
- $validateResult = $this->validate->validate(['boolean' => null]);
- $this->assertFalse($validateResult);
- $this->assertEquals('状态只能是开启或关闭', $this->validate->getError()->__toString());
- }
- }
|