1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace EasySwoole\Validate\tests;
- class InArrayTest extends BaseTestCase
- {
-
- public function testValidCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('number')->inArray([1, 2, 3, 4, 5]);
- $validateResult = $this->validate->validate(['number' => 5]);
- $this->assertTrue($validateResult);
- }
-
- public function testDefaultErrorMsgCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('number')->inArray([1, 2, 3, 4, 5]);
- $validateResult = $this->validate->validate(['number' => 6]);
- $this->assertFalse($validateResult);
- $this->assertEquals('number必须在 [1,2,3,4,5] 范围内', $this->validate->getError()->__toString());
- }
-
- public function testCustomErrorMsgCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('number')->inArray([1, 2, 3, 4, 5], true, '您选择的选项不合法');
- $validateResult = $this->validate->validate(['number' => '1']);
- $this->assertFalse($validateResult);
- $this->assertEquals('您选择的选项不合法', $this->validate->getError()->__toString());
- }
- }
|