12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace EasySwoole\Validate\tests;
- class EqualTest extends BaseTestCase
- {
-
- public function testValidCase()
- {
- $this->freeValidate();
- $this->validate->addColumn('equal')->equal('true');
- $validateResult = $this->validate->validate(['equal' => 'true']);
- $this->assertTrue($validateResult);
- $this->freeValidate();
- $this->validate->addColumn('age')->equal('12');
- $validateResult = $this->validate->validate(['age' => 12]);
- $this->assertTrue($validateResult);
- }
-
- public function testDefaultErrorMsgCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('equal')->equal('true');
- $validateResult = $this->validate->validate(['equal' => 'false']);
- $this->assertFalse($validateResult);
- $this->assertEquals('equal必须等于true', $this->validate->getError()->__toString());
-
- $this->freeValidate();
- $this->validate->addColumn('age')->equal(12, true);
- $validateResult = $this->validate->validate(['age' => '12']);
- $this->assertFalse($validateResult);
- $this->assertEquals('age必须等于12', $this->validate->getError()->__toString());
- }
-
- public function testCustomErrorMsgCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('equal', '参数')->equal('0', true);
- $validateResult = $this->validate->validate(['equal' => 0]);
- $this->assertFalse($validateResult);
- $this->assertEquals('参数必须等于0', $this->validate->getError()->__toString());
- }
- }
|