Skip to content

Commit a14cf1c

Browse files
committed
update: Added list rule helper
1 parent c47288a commit a14cf1c

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/Rule.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,14 @@ public static function json(): string
631631
return 'json';
632632
}
633633

634+
/**
635+
* The field under validation must be a list style array.
636+
*/
637+
public static function list(): string
638+
{
639+
return 'list';
640+
}
641+
634642
/**
635643
* The field under validation must be lowercase.
636644
*

src/RuleSet.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,14 @@ public function json(): self
715715
return $this->rule(Rule::json());
716716
}
717717

718+
/**
719+
* The field under validation must be a list style array.
720+
*/
721+
public function list(): self
722+
{
723+
return $this->rule(Rule::list());
724+
}
725+
718726
/**
719727
* The field under validation must be lowercase.
720728
*

tests/Unit/RuleTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,21 @@ public static function ruleDataProvider(): array
12261226
'rules' => fn() => RuleSet::create()->json(),
12271227
'fails' => true,
12281228
],
1229+
'list valid' => [
1230+
'data' => ['a', 'b', 'c'],
1231+
'rules' => fn() => RuleSet::create()->list(),
1232+
'fails' => false,
1233+
],
1234+
'list invalid array' => [
1235+
'data' => ['field' => ['a' => 'A', 'b' => 'B', 'c' => 'C']],
1236+
'rules' => fn() => ['field' => RuleSet::create()->list()],
1237+
'fails' => true,
1238+
],
1239+
'list invalid string' => [
1240+
'data' => 'a,b,c',
1241+
'rules' => fn() => RuleSet::create()->list(),
1242+
'fails' => true,
1243+
],
12291244
'lowercase valid' => [
12301245
'data' => 'lowercase',
12311246
'rules' => fn() => RuleSet::create()->lowercase(),

0 commit comments

Comments
 (0)