Skip to content

Commit

Permalink
output check in console as a table
Browse files Browse the repository at this point in the history
  • Loading branch information
vistik committed Feb 13, 2017
1 parent 84dad98 commit 2a2a8b5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Checks/HealthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

abstract class HealthCheck
{
private $error;
private $error = '';
private $log = [];

abstract public function run(): bool;
Expand Down
14 changes: 4 additions & 10 deletions src/Commands/HealthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down
14 changes: 10 additions & 4 deletions src/HealthChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion tests/CommandTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

use Illuminate\Support\Facades\App;
use Orchestra\Testbench\TestCase;
use Vistik\Checks\DebugModeOff;
use Vistik\Commands\HealthCommand;
use Vistik\ServiceProvider\HealthCheckServiceProvider;

class CommandTest extends TestCase
Expand All @@ -17,7 +19,7 @@ protected function getPackageProviders($app)
* @expectedException Vistik\Exceptions\FailedHealthCheckException
* @expectedExceptionMessage Failed health check: Vistik\Checks\DebugModeOff
*/
public function can_run_health_check_from_command_line()
public function running_health_check_from_command_line_will_throw_exception()
{
// Given
$this->app['config']->set('app.debug', true);
Expand All @@ -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);

}
}

0 comments on commit 2a2a8b5

Please sign in to comment.