diff --git a/src/Commands/PreflightCheckCommand.php b/src/Commands/PreflightCheckCommand.php index a212aff..af48df2 100644 --- a/src/Commands/PreflightCheckCommand.php +++ b/src/Commands/PreflightCheckCommand.php @@ -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')); } } diff --git a/tests/Checks/Fixtures/OptionsCheck.php b/tests/Checks/Fixtures/OptionsCheck.php new file mode 100644 index 0000000..aa387e9 --- /dev/null +++ b/tests/Checks/Fixtures/OptionsCheck.php @@ -0,0 +1,14 @@ +options['pass'] ? $result->pass() : $result->fail(); + } +} diff --git a/tests/Commands/PreflightCheckCommandTest.php b/tests/Commands/PreflightCheckCommandTest.php index 937535f..e98ea4c 100644 --- a/tests/Commands/PreflightCheckCommandTest.php +++ b/tests/Commands/PreflightCheckCommandTest.php @@ -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; @@ -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, + ], ]; }