12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace EasySwoole\Validate\tests;
- class NotInArrayTest extends BaseTestCase
- {
-
- public function testValidCase()
- {
-
- $this->freeValidate();
- $this->validate->addColumn('fruit')->notInArray(['apple', 'grape', 'orange'], true);
- $bool = $this->validate->validate(['fruit' => 'Apple']);
- $this->assertTrue($bool);
-
- $this->freeValidate();
- $this->validate->addColumn('fruit')->notInArray(['apple', 'grape', 'orange'], true);
- $bool = $this->validate->validate(['fruit' => 'banana']);
- $this->assertTrue($bool);
- }
-
- public function testDefaultErrorMsgCase()
- {
- $this->freeValidate();
- $this->validate->addColumn('fruit')->notInArray(['apple', 'grape', 'orange']);
- $bool = $this->validate->validate(['fruit' => 'apple']);
- $this->assertFalse($bool);
- $this->assertEquals('fruit不能在 [apple,grape,orange] 范围内', $this->validate->getError()->__toString());
- }
-
- public function testCustomErrorMsgCase()
- {
- $this->freeValidate();
- $this->validate->addColumn('fruit')->notInArray(['apple', 'grape', 'orange'], false, '水果不能是苹果、葡萄以及橘子');
- $bool = $this->validate->validate(['fruit' => 'apple']);
- $this->assertFalse($bool);
- $this->assertEquals('水果不能是苹果、葡萄以及橘子', $this->validate->getError()->__toString());
- }
- }
|