Skip to content

Commit

Permalink
Fine tune the laravel prompts support.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperTey committed Nov 18, 2024
1 parent 5c89d4c commit 691268a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"php": "^8.1|^8.2|^8.3",
"illuminate/contracts": "^10.25|^11.0",
"laravel/pint": "^1.18",
"laravel/prompts": "^0.1.16|^0.3.1",
"laravel/prompts": "^0.1.16|^0.2|^0.3.1",
"lorisleiva/lody": "^0.5.0",
"spatie/laravel-package-tools": "^1.13.0",
"symfony/var-exporter": "^6|^7.1"
Expand Down
8 changes: 7 additions & 1 deletion src/Commands/ConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,15 @@ protected function layers()
return self::SUCCESS;
}

public static function hasRequiredVersionOfLaravelPrompts(): bool
{
return function_exists('\Laravel\Prompts\form')
&& method_exists(\Laravel\Prompts\FormBuilder::class, 'addIf');
}

protected function wizard(): int
{
if (! function_exists('\Laravel\Prompts\form')) {
if (! static::hasRequiredVersionOfLaravelPrompts()) {
$this->error('This command is not supported with your currently installed version of Laravel Prompts.');

return self::FAILURE;
Expand Down
7 changes: 4 additions & 3 deletions tests/Command/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Illuminate\Database\Migrations\MigrationCreator;
use Lunarstorm\LaravelDDD\Commands\ConfigCommand;
use Lunarstorm\LaravelDDD\Facades\DDD;
use Lunarstorm\LaravelDDD\Tests\BootsTestApplication;

Expand Down Expand Up @@ -66,15 +67,15 @@
$this->artisan('config:clear')->assertSuccessful()->execute();

unlink($configPath);
})->skip(fn () => ! function_exists('\Laravel\Prompts\form'));
})->skip(fn () => ! ConfigCommand::hasRequiredVersionOfLaravelPrompts());

it('requires \Laravel\Prompts\form to run the wizard', function () {
it('requires supported version of Laravel Prompts to run the wizard', function () {
$this->artisan('ddd:config')
->expectsQuestion('Laravel-DDD Config Utility', 'wizard')
->expectsOutput('This command is not supported with your currently installed version of Laravel Prompts.')
->assertFailed()
->execute();
})->skip(fn () => function_exists('\Laravel\Prompts\form'));
})->skip(fn () => ConfigCommand::hasRequiredVersionOfLaravelPrompts());

it('can update and merge ddd.php with latest package version', function () {
$configPath = config_path('ddd.php');
Expand Down

0 comments on commit 691268a

Please sign in to comment.