-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[11.x] Add expectsSearch()
assertion for testing prompts that use search()
and multisearch()
functions
#51669
Conversation
Thanks for submitting a PR! Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
From what I gathered: framework/src/Illuminate/Testing/PendingCommand.php Lines 398 to 404 in 3672fbe
is definitely the culprit as the $argument question does not always match the $question[0] but is always overridden and should be more in line with: if ($argument->getQuestion() === $question[0] && isset($this->test->expectedChoices[$question[0]])) {
$this->test->expectedChoices[$question[0]]['actual'] = $argument->getAutocompleterValues();
return true;
}
return false; but then you get mockery exception of
and I have no idea where that expectation is set up as it seems to come from orchestra. |
@donnysim thanks for the input, yes, I also saw that message when testing, but I was unable to figure out why |
Don't want to be a pest, but have you got any thoughts on this @jessarcher 🙏 Thanks |
Hey @JayBizzle, The test assertion story for the We rely on the Symfony fallback when running tests so that the existing console test assertions can be used. For example, the There is no equivalent Symfony component for the This means you'd need to use the I have updated your test accordingly and added standalone tests for the This could likely be improved by adding a new The reason you needed |
I've added an I'd still like to build test assertions directly into |
Really appreciate the input here @jessarcher I'll give these changes a test against my code base and report back 👍 Thanks |
@JayBizzle did you figure that one out? |
Just on a different project at the moment, but hoping to get a chance to check this potential fix next week. Will update when I know more Thanks |
Hey @jessarcher Sorry it has taken me so long to check out the changes you made. I have finally just got around to testing this out. Looking good so far. Just one thing im not sure why is happening.... I have the following test.. // snip
->expectsSearch(
'Search for the tables you would like to import',
'backups/2020-10-08/11:00/fake_table.sql.gz',
'fake',
[
// 'None',
'backups/2020-10-08/11:00/fake_table.sql.gz',
]
) When the 1) Tests\App\Console\Commands\MysqlImporterTest::test_we_can_successfully_import_specific_backup_files
Question "Search for the tables you would like to import" has different options.
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
- 0 => 'backups/2020-10-08/11:00/Y8ejb.sql.gz'
+ 0 => 'None'
+ 1 => 'backups/2020-10-08/11:00/Y8ejb.sql.gz'
) I am really not sure where that The code i am testing looks pretty much similar to what your tests look like... $files = collect(multisearch(
label: 'Search for the tables you would like to import',
options: fn (string $value) => strlen($value) > 0
? $files->filter(fn ($file) => str_contains($file, $value))->values()->toArray()
: [],
hint: 'Use the arrow keys and spacebar to select the tables you would like to import.'
)); |
Hey @JayBizzle, Laravel inserts the "None" option because Symfony's choice component requires the user to select an option, while Laravel Prompts allows the user not to select anything when the However, when running tests, the "None" option should not get inserted: framework/src/Illuminate/Console/Concerns/ConfiguresPrompts.php Lines 255 to 263 in f0de069
Is it possible that your |
@jessarcher Thanks for the reply. You are correct, further up the test I was doing something like this (as these commands we have should only be run in production)...
Ive refactored my tests to get around this, so this now all works as expected 👍 Thanks again |
expectsChoice
issue when testing a multisearch
prompt followed by a select
promptexpectsSearch()
assertion for testing prompts that use search()
and multisearch()
functions
This is just a failing test, hoping for some help to figure out a fixI have been trying to test a command that first prompts with a basic
select
then immediately after prompts with amultisearch
.Im not quite sure what is going on, but it seems the assertions get polluted which each others options, which causes the assertion to fail.
As a side note, to even get to this point, I had to add the following line in
ConfiguresPrompts
...framework/src/Illuminate/Console/Concerns/ConfiguresPrompts.php
Line 273 in 2f33b4a
otherwise,
array_filter
errors here....framework/src/Illuminate/Console/Concerns/ConfiguresPrompts.php
Line 275 in 2f33b4a
@jessarcher I was hoping you may be able to shed some light on all of this as I think I have traced this as far as I can for now and its all getting a bit over my head 😕
Here is the PHPUnit output when running this test, why is the
What is you name?
assertion seeing the option ofDr
as that is an option from the next prompt?