From ca65e73c4196aff2061feedc9448752de72c6a3c Mon Sep 17 00:00:00 2001 From: Fermin Date: Sat, 15 Jun 2024 16:56:55 -0400 Subject: [PATCH 1/2] Use the new laravel prompt form builder and added test to creater search config command --- src/Commands/CreateSearchConfigCommand.php | 41 ++++++++++--------- .../CreateSearchConfigCommandTest.php | 4 +- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/Commands/CreateSearchConfigCommand.php b/src/Commands/CreateSearchConfigCommand.php index 533b6b6..86eb6a6 100644 --- a/src/Commands/CreateSearchConfigCommand.php +++ b/src/Commands/CreateSearchConfigCommand.php @@ -5,6 +5,8 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\Validator; +use Laravel\Prompts\FormBuilder; +use function Laravel\Prompts\form; use function Laravel\Prompts\intro; use function Laravel\Prompts\outro; use function Laravel\Prompts\text; @@ -17,26 +19,25 @@ class CreateSearchConfigCommand extends Command public function handle() { - intro("Let's create your index!"); - - $name = text( - label: 'What should your index be named?', - placeholder: 'E.g. my-index', - required: 'An index name is required.' - ); - - $url = text( - label: 'Which url should be crawled to fill this index?', - placeholder: 'E.g. https://example.com', - required: 'A URL is required.', - validate: function (string $value) { - $passes = Validator::make(['url' => $value], [ - 'url' => 'url', - ])->passes(); - - return $passes ? null : 'You must enter a valid URL'; - } - ); + [, $name, $url] = form()->intro("Let's create your index!") + ->text( + label: 'What should your index be named?', + placeholder: 'E.g. my-index', + required: 'An index name is required.' + ) + ->text( + label: 'Which url should be crawled to fill this index?', + placeholder: 'E.g. https://example.com', + required: 'A URL is required.', + validate: function (string $value) { + $passes = Validator::make(['url' => $value], [ + 'url' => 'url', + ])->passes(); + + return $passes ? null : 'You must enter a valid URL'; + } + ) + ->submit(); SiteSearchConfig::create([ 'name' => $name, diff --git a/tests/Commands/CreateSearchConfigCommandTest.php b/tests/Commands/CreateSearchConfigCommandTest.php index ea8b5a0..738ad2c 100644 --- a/tests/Commands/CreateSearchConfigCommandTest.php +++ b/tests/Commands/CreateSearchConfigCommandTest.php @@ -9,7 +9,7 @@ it('has a command to create a site search config', function () { artisan(CreateSearchConfigCommand::class) ->expectsQuestion('What should your index be named?', 'test-index') - ->expectsQuestion('Great! Which url should be crawled to fill this index?', 'https://example.com') + ->expectsQuestion('Which url should be crawled to fill this index?', 'https://example.com') ->assertExitCode(Command::SUCCESS); $this->assertDatabaseHas('site_search_configs', [ @@ -18,4 +18,4 @@ 'index_base_name' => 'test-index', 'enabled' => 1, ]); -})->todo('Fix this tests when Laravel Prompts are testable'); +}); From f5ce2956436ef696e93631595ae79e116bb25d0d Mon Sep 17 00:00:00 2001 From: Fermin Date: Sat, 15 Jun 2024 17:54:30 -0400 Subject: [PATCH 2/2] Updated laravel prompt composer dependency --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8a58b5b..eaa9776 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "guzzlehttp/psr7": "^2.5", "illuminate/contracts": "^10.0|^11.0", "illuminate/http": "^10.0|^11.0", - "laravel/prompts": "^0.1.1", + "laravel/prompts": "^0.1.23", "spatie/crawler": "^8.0", "spatie/laravel-package-tools": "^1.15" },