Skip to content

Commit f1f0df1

Browse files
authored
Merge pull request #119 from utopia-php/feat-sync-master
Feat: Sync latest release to main
2 parents 7613c13 + 8d3d828 commit f1f0df1

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Http/Validator/ArrayList.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ public function __construct(Validator $validator, int $length = 0)
4444
*/
4545
public function getDescription(): string
4646
{
47-
return 'Value must a valid array and '.$this->validator->getDescription();
47+
$msg = 'Value must a valid array';
48+
49+
if($this->length > 0) {
50+
$msg .= ' no longer than ' . $this->length . ' items';
51+
}
52+
53+
return $msg . ' and ' . $this->validator->getDescription();
4854
}
4955

5056
/**

tests/Validator/ArrayListTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66

77
class ArrayListTest extends TestCase
88
{
9+
public function testDescription(): void
10+
{
11+
$arrayList = new ArrayList(new Integer());
12+
$this->assertFalse($arrayList->isValid(['text']));
13+
$this->assertEquals('Value must a valid array and Value must be a valid integer', $arrayList->getDescription());
14+
15+
$arrayList = new ArrayList(new Integer(), 3);
16+
$this->assertFalse($arrayList->isValid(['a', 'b', 'c', 'd']));
17+
$this->assertEquals('Value must a valid array no longer than 3 items and Value must be a valid integer', $arrayList->getDescription());
18+
}
19+
920
public function testCanValidateTextValues(): void
1021
{
1122
$arrayList = new ArrayList(new Text(100));

0 commit comments

Comments
 (0)