Skip to content

Commit

Permalink
AnyOf() must not be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 21, 2021
1 parent 9cb38ba commit 89c661d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Schema/Elements/AnyOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ final class AnyOf implements Schema
*/
public function __construct(...$set)
{
if (!$set) {
throw new Nette\InvalidStateException('The enumeration must not be empty.');
}
$this->set = $set;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Schema/Expect.anyOf.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ test('First is default', function () {
});


test('Empty set', function () {
Assert::exception(function () {
Expect::anyOf();
}, Nette\InvalidStateException::class, 'The enumeration must not be empty.');
});


test('normalization', function () {
$schema = Expect::anyOf(
Expect::string()->before(function ($v) { return (string) $v; })
Expand Down

0 comments on commit 89c661d

Please sign in to comment.