Skip to content

Commit

Permalink
👮 [Healthcheck] Protect ChainHealthcheck invariants
Browse files Browse the repository at this point in the history
  • Loading branch information
shouze committed Dec 1, 2017
1 parent 94533cd commit 85beb84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ChainHealthcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ final class ChainHealthcheck implements Healthcheck

public function __construct(array $healthchecks = [])
{
if (count($healthchecks) === 0) {
throw new \InvalidArgumentException('ChainHealthcheck requires healthchecks collection to be non empty.');
}
array_map([$this, 'add'], $healthchecks);
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Units/ChainHealthcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@

class ChainHealthcheck extends atoum
{
public function test healthchecks should be non empty()
{
$this
->exception(function () {
$this->newTestedInstance([]);
})
->hasMessage('ChainHealthcheck requires healthchecks collection to be non empty.')
;
}

public function test first failure should stop chain()
{
$this
Expand Down

0 comments on commit 85beb84

Please # to comment.