Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the new reversable prompt form builder and fix CreateSearchConfigCommand Tests #45

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
41 changes: 21 additions & 20 deletions src/Commands/CreateSearchConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/Commands/CreateSearchConfigCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand All @@ -18,4 +18,4 @@
'index_base_name' => 'test-index',
'enabled' => 1,
]);
})->todo('Fix this tests when Laravel Prompts are testable');
});
Loading