From 85beb84c7f85162d7c252035a12891f80602e315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20HOUZ=C3=89?= Date: Fri, 1 Dec 2017 11:53:39 +0100 Subject: [PATCH] :cop: [Healthcheck] Protect ChainHealthcheck invariants --- ChainHealthcheck.php | 3 +++ tests/Units/ChainHealthcheck.php | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/ChainHealthcheck.php b/ChainHealthcheck.php index c238b48..1ff9ca5 100644 --- a/ChainHealthcheck.php +++ b/ChainHealthcheck.php @@ -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); } diff --git a/tests/Units/ChainHealthcheck.php b/tests/Units/ChainHealthcheck.php index 473a95f..6c1656a 100644 --- a/tests/Units/ChainHealthcheck.php +++ b/tests/Units/ChainHealthcheck.php @@ -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