-
Notifications
You must be signed in to change notification settings - Fork 94
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
Prompt::fake()
incompatible with PendingCommand
created by $this->artisan()
?
#158
Comments
A coworker and I found the issue, which in hindsight I guess makes sense given that stack trace.... When As a hacky workaround, we were able to use late static binding to reset the I'm open to creating a PR for laravel/prompts here, but not sure the best approach... For example, we could create a Curious on your thoughts? |
Hey @driesvints! Re: that You can see the actual PR where we're trying to use Happy to help with a PR, just curious on @jessarcher's thoughts before I dig any further (this is NOT a rush by any means though!) ❤️ |
Hey @jesseleite!
From a consuming app's POV, I don't know how useful it is to queue up fake keypresses and assert against rendered output. Generally, you just want to test the logic of your own command when a user chooses a specific response without worrying about which keys they pressed to get there. At the moment, the recommended way to test a command that uses Prompts is to use Laravel's built-in test helpers. E.g. // TestCommand.php
public function handle()
{
$result = text('Enter some text');
$this->info($result);
} // TestCommandTest.php
$this->artisan('statamic:test-command')
->expectsQuestion('Enter some text', 'Test command successful!')
->expectsOutput('Test command successful!')
->assertExitCode(0); I have wanted to build some better userland test helpers into Prompts for a while, but probably following a similar API to the above where you're really just testing that your command prompted the user and that it handles the response. I'm open to ideas, though! And if you still feel like |
Yeah @jessarcher, I think you are absolutely right... Maybe I should be worrying about the expected questions/answers, rather than the exact keys they've pressed via |
Laravel Prompts Version
0.1.24
Laravel Version
11.19.0
PHP Version
8.3.7
Operating System & Version
macOS 14.2
Terminal Application
WezTerm
Description
Working on some tests for Statamic... I did a code dive and found your
Prompt::fake()
helper, which is genious! 🔥However, I've noticed an issue where tests containing
Prompt::fake()
pass when run in isolation...But they fail when the whole test case and/or suite is ran...
We're hoping to use
Prompt::fake()
in our Statamic core test suite, but I can't get it to play nicely with other tests where we use$this->artisan()
.It seems that
PendingCommand
is leaking mock expectations into other tests which usePrompt::fake()
. I'm not sure how to solve, or if there's a way to improvePrompt::fake()
for packages who wish to use it? 🤔I've created a repo with an example test case to make it easier to reproduce, if that helps!
Any thoughts? 🙏
Steps To Reproduce
composer install
phpunit
Prompt::fake()
will failThe text was updated successfully, but these errors were encountered: