assertAssertions($assertions); $this->assertions = $assertions; } /** * Executes assertions based on all contained assertions. * * @param string $path * @param string $command * @return bool * @throws Exception */ public function assert($path, $command) { if ($this->invokeAssertions($path, $command)) { return true; } throw new Exception( sprintf( 'Assertion failed in "%s"', $path ), 1539625084 ); } /** * @param Assertable[] $assertions */ private function assertAssertions(array $assertions) { foreach ($assertions as $assertion) { if (!$assertion instanceof Assertable) { throw new \InvalidArgumentException( sprintf( 'Instance %s must implement Assertable', get_class($assertion) ), 1539624719 ); } } } /** * @param string $path * @param string $command * @return bool */ private function invokeAssertions($path, $command) { try { foreach ($this->assertions as $assertion) { if (!$assertion->assert($path, $command)) { return false; } } } catch (Exception $exception) { return false; } return true; } }