Skip to content

Commit

Permalink
Form // fix handling of isValid when the Form has errors. Add missing…
Browse files Browse the repository at this point in the history
… method mock in FormTest::testIsValid().
  • Loading branch information
Chrico committed Jun 28, 2023
1 parent 699c974 commit 6bd447a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Element/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ public function isValid(): bool

// Either on "submit" we have erroneous Elements, or the
// Form itself has errors assigned through Form::withErrors().
return $this->hasErrors() || $this->isValid;
if ($this->hasErrors()) {
return false;
}

return $this->isValid;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/Unit/Element/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function testIsValid(): void
->andReturn($expected_value);
$element->allows('withErrors')
->with($expected_error);
$element->allows('hasErrors')
->andReturnTrue();
$element->allows('validate')
->andReturnFalse();

Expand Down

0 comments on commit 6bd447a

Please sign in to comment.