diff --git a/src/Validator/ArrayList.php b/src/Validator/ArrayList.php index 2c1ed1e1..2468aed0 100644 --- a/src/Validator/ArrayList.php +++ b/src/Validator/ArrayList.php @@ -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(); } /** diff --git a/tests/Validator/ArrayListTest.php b/tests/Validator/ArrayListTest.php index ceab7932..3f079152 100755 --- a/tests/Validator/ArrayListTest.php +++ b/tests/Validator/ArrayListTest.php @@ -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));