12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace EasySwoole\Validate\tests;
- class FloatTest extends BaseTestCase
- {
-
- public function testValidCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('float')->float();
- $validateResult = $this->validate->validate(['float' => 0.001]);
- $this->assertTrue($validateResult);
-
- $this->freeValidate();
- $this->validate->addColumn('float')->float();
- $validateResult = $this->validate->validate(['float' => '0.001']);
- $this->assertTrue($validateResult);
-
- $this->freeValidate();
- $this->validate->addColumn('float')->float();
- $validateResult = $this->validate->validate(['float' => 2]);
- $this->assertTrue($validateResult);
- }
-
- public function testDefaultErrorMsgCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('float')->float();
- $validateResult = $this->validate->validate(['float' => 'aaa']);
- $this->assertFalse($validateResult);
- $this->assertEquals('float只能是浮点数', $this->validate->getError()->__toString());
- }
-
- public function testCustomErrorMsgCase()
- {
- $this->freeValidate();
- $this->validate->addColumn('float')->float('请输入一个浮点数');
- $validateResult = $this->validate->validate(['float' => 'a']);
- $this->assertFalse($validateResult);
- $this->assertEquals('请输入一个浮点数', $this->validate->getError()->__toString());
- }
- }
|