Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge 0812223 into 4901fc6
Browse files Browse the repository at this point in the history
  • Loading branch information
eweso committed Jul 12, 2018
2 parents 4901fc6 + 0812223 commit 89de915
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ArrayInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ public function isValid($context = null)
$validator = $this->getValidatorChain();
$values = $this->getValue();
$result = true;

if ($required && empty($values)) {
if ($this->errorMessage === null) {
$this->errorMessage = $this->prepareRequiredValidationFailureMessage();
}
return false;
}

foreach ($values as $value) {
$empty = ($value === null || $value === '' || $value === []);
if ($empty && ! $this->isRequired() && ! $this->continueIfEmpty()) {
Expand Down
12 changes: 12 additions & 0 deletions test/ArrayInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ public function testDefaultGetValue()
$this->assertCount(0, $this->input->getValue());
}

public function testRequiredWithoutFallbackAndValueIsEmptyArrayThenFail()
{
$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->assertRequiredValidationErrorMessage($input);
}

public function testSetValueWithInvalidInputTypeThrowsInvalidArgumentException()
{
$this->expectException(InvalidArgumentException::class);
Expand Down

0 comments on commit 89de915

Please sign in to comment.