diff --git a/test/ArrayInputTest.php b/test/ArrayInputTest.php index 96aa8e67..5ce72d95 100644 --- a/test/ArrayInputTest.php +++ b/test/ArrayInputTest.php @@ -27,18 +27,33 @@ public function testDefaultGetValue() $this->assertCount(0, $this->input->getValue()); } - public function testRequiredWithoutFallbackAndValueIsEmptyArrayThenFail() + public function testArrayInputMarkedRequiredWithoutAFallbackFailsValidationForEmptyArrays() { $input = $this->input; $input->setRequired(true); $input->setValue([]); - $this->assertFalse( - $input->isValid(), - 'isValid() should be return always false when no fallback value, is required, and value is empty array.' - ); + + $this->assertFalse($input->isValid()); $this->assertRequiredValidationErrorMessage($input); } + public function testArrayInputMarkedRequiredWithoutAFallbackUsesProvidedErrorMessageOnFailureDueToEmptyArray() + { + $expected = 'error message'; + + $input = $this->input; + $input->setRequired(true); + $input->setErrorMessage($expected); + $input->setValue([]); + + $this->assertFalse($input->isValid()); + + $messages = $input->getMessages(); + $this->assertCount(1, $messages); + $message = array_pop($messages); + $this->assertEquals($expected, $message); + } + public function testSetValueWithInvalidInputTypeThrowsInvalidArgumentException() { $this->expectException(InvalidArgumentException::class);