Skip to content

Commit

Permalink
Add options for full array syntax (allows duplicate checks)
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodahero committed Feb 23, 2021
1 parent d3d282e commit 4046100
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Commands/PreflightCheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ protected function bootChecks()
$options = [];
}

if (is_array($options) && array_key_exists('check', $options)) {
$class = $options['check'];
$options = $options['options'] ?? [];
}

$this->preflightSteps[] = App::makeWith($class, compact('options'));
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Checks/Fixtures/OptionsCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Kirschbaum\PreflightChecks\Tests\Checks\Fixtures;

use Kirschbaum\PreflightChecks\Checks\PreflightCheck;
use Kirschbaum\PreflightChecks\Checks\Result;

class OptionsCheck extends PreflightCheck
{
public function check(Result $result): Result
{
return $this->options['pass'] ? $result->pass() : $result->fail();
}
}
38 changes: 38 additions & 0 deletions tests/Commands/PreflightCheckCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Kirschbaum\PreflightChecks\Checks\Exceptions\NoPreflightChecksDefinedException;
use Kirschbaum\PreflightChecks\PreflightChecksServiceProvider;
use Kirschbaum\PreflightChecks\Tests\Checks\Fixtures\FailedCheck;
use Kirschbaum\PreflightChecks\Tests\Checks\Fixtures\OptionsCheck;
use Kirschbaum\PreflightChecks\Tests\Checks\Fixtures\PassedCheck;
use Kirschbaum\PreflightChecks\Tests\Checks\Fixtures\SkippedCheck;
use Kirschbaum\PreflightChecks\Tests\Checks\Fixtures\SkippedFailedCheck;
Expand Down Expand Up @@ -58,6 +59,43 @@ public function providesCommandScenarios()
'Passes with mix of failed skipped' => [
[PassedCheck::class, SkippedFailedCheck::class], 0,
],
'Provides options and passes' => [
[
OptionsCheck::class => ['pass' => true],
], 0,
],
'Provides options and fails' => [
[
OptionsCheck::class => ['pass' => false],
], 1,
],
'Can pass full config without options' => [
[
[
'check' => PassedCheck::class,
],
], 0,
],
'Can fail full config with options' => [
[
[
'check' => OptionsCheck::class,
'options' => ['pass' => false],
],
], 1,
],
'Full config allows duplicates' => [
[
[
'check' => OptionsCheck::class,
'options' => ['pass' => false],
],
[
'check' => OptionsCheck::class,
'options' => ['pass' => true],
],
], 1,
],
];
}

Expand Down

0 comments on commit 4046100

Please sign in to comment.