-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[11.x] Add Prompts
textarea
fallback for tests and add assertion te…
…sts (#51055) * add textarea fallback * add text and textarea assertion tests * add input tests * add tests * add multiselect test * add select test * update composer.json * styles * Use multiline fallback * Formatting --------- Co-authored-by: Jess Archer <[email protected]>
- Loading branch information
1 parent
21d7ad9
commit 61716c9
Showing
4 changed files
with
182 additions
and
3 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
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,165 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Contracts\Console\Kernel; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
use function Laravel\Prompts\confirm; | ||
use function Laravel\Prompts\multiselect; | ||
use function Laravel\Prompts\password; | ||
use function Laravel\Prompts\select; | ||
use function Laravel\Prompts\text; | ||
use function Laravel\Prompts\textarea; | ||
|
||
class PromptsAssertionTest extends TestCase | ||
{ | ||
public function testAssertionForTextPrompt() | ||
{ | ||
$this->app[Kernel::class]->registerCommand( | ||
new class extends Command | ||
{ | ||
protected $signature = 'test:text'; | ||
|
||
public function handle() | ||
{ | ||
$name = text('What is your name?', 'John'); | ||
|
||
$this->line($name); | ||
} | ||
} | ||
); | ||
|
||
$this | ||
->artisan('test:text') | ||
->expectsQuestion('What is your name?', 'Jane') | ||
->expectsOutput('Jane'); | ||
} | ||
|
||
public function testAssertionForTextareaPrompt() | ||
{ | ||
$this->app[Kernel::class]->registerCommand( | ||
new class extends Command | ||
{ | ||
protected $signature = 'test:textarea'; | ||
|
||
public function handle() | ||
{ | ||
$name = textarea('What is your name?', 'John'); | ||
|
||
$this->line($name); | ||
} | ||
} | ||
); | ||
|
||
$this | ||
->artisan('test:textarea') | ||
->expectsQuestion('What is your name?', 'Jane') | ||
->expectsOutput('Jane'); | ||
} | ||
|
||
public function testAssertionForPasswordPrompt() | ||
{ | ||
$this->app[Kernel::class]->registerCommand( | ||
new class extends Command | ||
{ | ||
protected $signature = 'test:password'; | ||
|
||
public function handle() | ||
{ | ||
$name = password('What is your password?'); | ||
|
||
$this->line($name); | ||
} | ||
} | ||
); | ||
|
||
$this | ||
->artisan('test:password') | ||
->expectsQuestion('What is your password?', 'secret') | ||
->expectsOutput('secret'); | ||
} | ||
|
||
public function testAssertionForConfirmPrompt() | ||
{ | ||
$this->app[Kernel::class]->registerCommand( | ||
new class extends Command | ||
{ | ||
protected $signature = 'test:confirm'; | ||
|
||
public function handle() | ||
{ | ||
$confirmed = confirm('Is your name John?'); | ||
|
||
if ($confirmed) { | ||
$this->line('Your name is John.'); | ||
} else { | ||
$this->line('Your name is not John.'); | ||
} | ||
} | ||
} | ||
); | ||
|
||
$this | ||
->artisan('test:confirm') | ||
->expectsConfirmation('Is your name John?', 'no') | ||
->expectsOutput('Your name is not John.'); | ||
|
||
$this | ||
->artisan('test:confirm') | ||
->expectsConfirmation('Is your name John?', 'yes') | ||
->expectsOutput('Your name is John.'); | ||
} | ||
|
||
public function testAssertionForSelectPrompt() | ||
{ | ||
$this->app[Kernel::class]->registerCommand( | ||
new class extends Command | ||
{ | ||
protected $signature = 'test:select'; | ||
|
||
public function handle() | ||
{ | ||
$name = select( | ||
label: 'What is your name?', | ||
options: ['John', 'Jane'] | ||
); | ||
|
||
$this->line("Your name is $name."); | ||
} | ||
} | ||
); | ||
|
||
$this | ||
->artisan('test:select') | ||
->expectsChoice('What is your name?', 'Jane', ['John', 'Jane']) | ||
->expectsOutput('Your name is Jane.'); | ||
} | ||
|
||
public function testAssertionForRequiredMultiselectPrompt() | ||
{ | ||
$this->app[Kernel::class]->registerCommand( | ||
new class extends Command | ||
{ | ||
protected $signature = 'test:multiselect'; | ||
|
||
public function handle() | ||
{ | ||
$names = multiselect( | ||
label: 'Which names do you like?', | ||
options: ['John', 'Jane', 'Sally', 'Jack'], | ||
required: true | ||
); | ||
|
||
$this->line(sprintf('You like %s.', implode(', ', $names))); | ||
} | ||
} | ||
); | ||
|
||
$this | ||
->artisan('test:multiselect') | ||
->expectsChoice('Which names do you like?', ['John', 'Jane'], ['John', 'Jane', 'Sally', 'Jack']) | ||
->expectsOutput('You like John, Jane.'); | ||
} | ||
} |