-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[10.x] Allow testing prompts validation (#49447)
* [10.x] Allow testing prompts validation * [10.x] Move test * [10.x] Throw exception when testing prompt validation * Update ConfiguresPrompts.php --------- Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
90ed27d
commit a77d6b6
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Illuminate\Console; | ||
|
||
use RuntimeException; | ||
|
||
class PromptValidationException extends RuntimeException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Contracts\Console\Kernel; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
use function Laravel\Prompts\text; | ||
|
||
class PromptsValidationTest extends TestCase | ||
{ | ||
protected function defineEnvironment($app) | ||
{ | ||
$app[Kernel::class]->registerCommand(new DummyPromptsValidationCommand()); | ||
} | ||
|
||
public function testValidationForPrompts() | ||
{ | ||
$this | ||
->artisan(DummyPromptsValidationCommand::class) | ||
->expectsQuestion('Test', 'bar') | ||
->expectsOutputToContain('error!'); | ||
} | ||
} | ||
|
||
class DummyPromptsValidationCommand extends Command | ||
{ | ||
protected $signature = 'prompts-validation-test'; | ||
|
||
public function handle() | ||
{ | ||
text('Test', validate: fn ($value) => $value == 'foo' ? '' : 'error!'); | ||
} | ||
} |