55use Inhere \Validate \FieldValidation ;
66use Inhere \ValidateTest \Sample \FieldSample ;
77use PHPUnit \Framework \TestCase ;
8+ use Throwable ;
89
10+ /**
11+ * Class FieldValidationTest
12+ * @package Inhere\ValidateTest
13+ */
914class FieldValidationTest extends TestCase
1015{
1116 public $ data = [
@@ -26,6 +31,27 @@ class FieldValidationTest extends TestCase
2631 ],
2732 ];
2833
34+ public function testRuleCollectError (): void
35+ {
36+ $ rv = FieldValidation::make (['name ' => 'inhere ' ], [
37+ []
38+ ]);
39+ try {
40+ $ rv ->validate ();
41+ } catch (Throwable $ e ) {
42+ $ this ->assertSame ('Please setting the field(string) to wait validate! position: rule[0] ' , $ e ->getMessage ());
43+ }
44+
45+ $ rv = FieldValidation::make (['name ' => 'inhere ' ], [
46+ ['name ' ]
47+ ]);
48+ try {
49+ $ rv ->validate ();
50+ } catch (Throwable $ e ) {
51+ $ this ->assertSame ('The field validators must be is a validator name(s) string! position: rule[1] ' , $ e ->getMessage ());
52+ }
53+ }
54+
2955 public function testValidateField (): void
3056 {
3157 $ rules = [
@@ -79,6 +105,24 @@ public function testValidateField(): void
79105 );
80106 }
81107
108+ public function testOnScene (): void
109+ {
110+ $ data = [
111+ 'user ' => 'inhere ' ,
112+ 'pwd ' => '123456 ' ,
113+ 'code ' => '1234 ' ,
114+ ];
115+
116+ $ v = FieldValidation::make ($ data , [
117+ ['user ' , 'required|string ' , 'on ' => 's1 ' ],
118+ ['code ' , 'required|int ' , 'filter ' => 'int ' , 'on ' => 's2 ' ],
119+ ]);
120+
121+ $ v ->atScene ('s1 ' )->validate ();
122+
123+ $ this ->assertCount (1 , $ v ->getUsedRules ());
124+ }
125+
82126 public function testScenarios (): void
83127 {
84128 $ data = [
0 commit comments