Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Validator/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ public function __construct(Validator $validator, int $length = 0)
*/
public function getDescription(): string
{
return 'Value must a valid array and '.$this->validator->getDescription();
$msg = 'Value must a valid array';

if($this->length > 0) {
$msg .= ' no longer than ' . $this->length . ' items';
}

return $msg . ' and ' . $this->validator->getDescription();
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/Validator/ArrayListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

class ArrayListTest extends TestCase
{
public function testDescription(): void
{
$arrayList = new ArrayList(new Integer());
$this->assertFalse($arrayList->isValid(['text']));
$this->assertEquals('Value must a valid array and Value must be a valid integer', $arrayList->getDescription());

$arrayList = new ArrayList(new Integer(), 3);
$this->assertFalse($arrayList->isValid(['a', 'b', 'c', 'd']));
$this->assertEquals('Value must a valid array no longer than 3 items and Value must be a valid integer', $arrayList->getDescription());
}

public function testCanValidateTextValues(): void
{
$arrayList = new ArrayList(new Text(100));
Expand Down