From 2a2a8b541254202dd8a9acd38cb92c75659a3a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Visti=20Kl=C3=B8ft?= Date: Tue, 14 Feb 2017 01:14:06 +0530 Subject: [PATCH] output check in console as a table --- src/Checks/HealthCheck.php | 2 +- src/Commands/HealthCommand.php | 14 ++++---------- src/HealthChecker.php | 14 ++++++++++---- tests/CommandTest.php | 22 +++++++++++++++++++++- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/Checks/HealthCheck.php b/src/Checks/HealthCheck.php index 9fb60cc..d47eaab 100644 --- a/src/Checks/HealthCheck.php +++ b/src/Checks/HealthCheck.php @@ -4,7 +4,7 @@ abstract class HealthCheck { - private $error; + private $error = ''; private $log = []; abstract public function run(): bool; diff --git a/src/Commands/HealthCommand.php b/src/Commands/HealthCommand.php index db5498a..471e047 100644 --- a/src/Commands/HealthCommand.php +++ b/src/Commands/HealthCommand.php @@ -4,10 +4,6 @@ use Illuminate\Console\Command; use Illuminate\Foundation\Bus\DispatchesJobs; -use Timekit\Account; -use Timekit\Filter; -use Timekit\Jobs\DeleteUser as DeleteUserJob; -use Timekit\User; use Vistik\HealthChecker; use Vistik\Utils\CheckList; @@ -39,13 +35,11 @@ public function handle() $output = $checker->prettyPrint(); - foreach ($output as $name => $passed) { - if ($passed) { - $this->info($name); - continue; - } - $this->error($name); + $rows = []; + foreach ($output as $o) { + $rows[] = [$o['check'], $o['passed'], $o['log'], $o['error']]; } + $this->table(['check', 'status', 'log', 'error'], $rows); $checker->run(); } diff --git a/src/HealthChecker.php b/src/HealthChecker.php index b4d93e4..ecb79de 100644 --- a/src/HealthChecker.php +++ b/src/HealthChecker.php @@ -40,11 +40,17 @@ public function prettyPrint() $output = []; /** @var HealthCheck $check */ foreach ($this->list as $check) { - if (!$check->run()) { - $output[get_class($check) . ' failed!'] = false; - continue; + $passed = false; + if ($check->run()) { + $passed = true; } - $output[get_class($check) . ' ok!'] = true; + + $output[] = [ + 'passed' => $passed, + 'check' => get_class($check), + 'log' => implode("\n", $check->getLog()), + 'error' => $check->getError() + ]; } return $output; diff --git a/tests/CommandTest.php b/tests/CommandTest.php index b7329f1..d800a1d 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -1,7 +1,9 @@ app['config']->set('app.debug', true); @@ -29,4 +31,22 @@ public function can_run_health_check_from_command_line() // Then } + + /** + * @test + * @group cli + */ + public function can_run_health_check_from_command_line() + { + // Given + $this->app['config']->set('app.debug', false); + $this->app['config']->set('health.checks', [new DebugModeOff()]); + + // When + $this->artisan('health:check'); + + // Then + $this->assertTrue(true); + + } } \ No newline at end of file