Skip to content

Commit beaf869

Browse files
committed
add unit tests for issues/22
1 parent 6eb2675 commit beaf869

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

src/FV.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Inhere\Validate;
4+
5+
/**
6+
* Class FV - the short name of the field validation
7+
* @package Inhere\Validate
8+
*/
9+
final class FV extends FieldValidation
10+
{
11+
12+
}

src/RV.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Inhere\Validate;
4+
5+
/**
6+
* Class RV - the short name of the rule validation
7+
* @package Inhere\Validate
8+
*/
9+
final class RV extends Validation
10+
{
11+
12+
}

test/FieldValidationTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Inhere\ValidateTest;
44

55
use Inhere\Validate\FieldValidation;
6+
use Inhere\Validate\FV;
67
use Inhere\ValidateTest\Sample\FieldSample;
78
use PHPUnit\Framework\TestCase;
89
use Throwable;
@@ -154,4 +155,56 @@ public function testScenarios(): void
154155
$this->assertTrue($v->isOk());
155156
$this->assertEmpty($v->getErrors());
156157
}
158+
159+
/**
160+
* @link https://github.com/inhere/php-validate/issues/22
161+
*/
162+
public function testIssues22(): void
163+
{
164+
$rs = [
165+
['id', 'required'],
166+
['name', 'required|string:5,10', 'msg' => '5~10位的字符串'],
167+
['sex', 'required|enum:0,1'],
168+
['age', 'requiredIf:sex,0|int']
169+
];
170+
171+
$v = FV::check([
172+
'id' => 1,
173+
'name' => '12345',
174+
'sex' => 0,
175+
'age' => 25,
176+
], $rs);
177+
178+
$this->assertTrue($v->isOk());
179+
180+
$v = FV::check([
181+
'id' => 1,
182+
'name' => '12345',
183+
'sex' => 1,
184+
// 'age' => 25,
185+
], $rs);
186+
187+
$this->assertTrue($v->isOk());
188+
189+
$v = FV::check([
190+
'id' => 1,
191+
'name' => '12345',
192+
'sex' => 0,
193+
// 'age' => 25,
194+
// 'age' => 'string',
195+
], $rs);
196+
197+
$this->assertFalse($v->isOk());
198+
$this->assertSame('parameter age is required!', $v->firstError());
199+
200+
$v = FV::check([
201+
'id' => 1,
202+
'name' => '12345',
203+
'sex' => 0,
204+
'age' => 'string',
205+
], $rs);
206+
207+
$this->assertFalse($v->isOk());
208+
$this->assertSame('age must be an integer!', $v->firstError());
209+
}
157210
}

0 commit comments

Comments
 (0)