Skip to content

Commit 669e4d7

Browse files
committed
update, add more test
1 parent a9d6e3f commit 669e4d7

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

src/ValidationTrait.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ trait ValidationTrait
2323
use DataFiltersTrait, ErrorMessageTrait, UserAndContextValidatorsTrait;
2424

2525
/**
26-
* the rules is by setRules()
27-
* @var array
26+
* @var array The rules is by setRules()
2827
*/
2928
private $_rules = [];
3029

3130
/**
32-
* Through the validation of the data
33-
* @var array
31+
* @var array Through the validation of the data
3432
*/
3533
private $_safeData = [];
3634

@@ -55,7 +53,9 @@ trait ValidationTrait
5553
*/
5654
protected $scene = '';
5755

58-
/** @var array used rules at current scene */
56+
/**
57+
* @var array Used rules at current scene
58+
*/
5959
protected $_usedRules = [];
6060

6161
/**
@@ -152,7 +152,7 @@ public function afterValidate()
152152
* @throws \InvalidArgumentException
153153
* @throws \RuntimeException
154154
*/
155-
public function validate(array $onlyChecked = null, $stopOnError = null)
155+
public function validate(array $onlyChecked = null, bool $stopOnError = null)
156156
{
157157
if (!property_exists($this, 'data')) {
158158
throw new \InvalidArgumentException('Must be defined property "data"(array) in the sub-class used.');

test/RuleValidationTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,27 @@ public function testValidateFailed()
262262
$this->assertEquals($v->getSafe('tagId'), null);
263263
}
264264

265+
public function testValidateRegex()
266+
{
267+
$v = RuleValidation::check([
268+
'text1' => 'hello-world',
269+
'text2' => 'hello world中文',
270+
],[
271+
['text1, text2', 'string'],
272+
['text1', 'regex', '/^[\w-]+$/'],
273+
['text2', 'regex', '/[\x{4e00}-\x{9fa5}]+/u'],
274+
]);
275+
276+
$this->assertTrue($v->isOk());
277+
$this->assertFalse($v->isFail());
278+
279+
$errors = $v->getErrors();
280+
$this->assertEmpty($errors);
281+
282+
$safeData = $v->getSafeData();
283+
$this->assertArrayHasKey('text2', $safeData);
284+
}
285+
265286
public function testValidateString()
266287
{
267288
$val = '123482';

test/ValidatorsTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public function testRegexp()
176176
$this->assertFalse(Validators::regexp('test', '/^\d+$/'));
177177
$this->assertFalse(Validators::regexp('test-dd', '/^\w+$/'));
178178

179+
$this->assertTrue(Validators::regexp('compose启动服务', '/[\x{4e00}-\x{9fa5}]+/u'));
179180
$this->assertTrue(Validators::regexp('test56', '/^\w+$/'));
180181
}
181182

0 commit comments

Comments
 (0)