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

[5.8] Fix expectsQuestion and expectsOutput assertions of PendingCommand fail when called twice with same text #29413

Closed
wants to merge 1 commit into from
Closed

[5.8] Fix expectsQuestion and expectsOutput assertions of PendingCommand fail when called twice with same text #29413

wants to merge 1 commit into from

Conversation

nuzkito
Copy link

@nuzkito nuzkito commented Aug 4, 2019

In Laravel 5.8.30, when you have a console command calling ask twice or more with the same question

$this->ask('Asking something');
$this->ask('Asking something');

and you try to test it

$command = $this->artisan('console-command');
$command->expectsQuestion('Asking something', 'answer');
$command->expectsQuestion('Asking something', 'another answer');
$command->assertExitCode(0);
$command->run();

the test fails with an error like that

Question "Asking something" was not asked.

If you have another question between

$this->ask('Asking something');
$this->ask('Put a number');
$this->ask('Asking something');

and test

$command = $this->artisan('create-song');
$command->expectsQuestion('Asking something', 'answer');
$command->expectsQuestion('Put a number', '7');
$command->expectsQuestion('Asking something', 'another answer');
$command->assertExitCode(0);
$command->run();

the error is more cryptic

Mockery\Exception\InvalidOrderException: Method Mockery_1_Illuminate_Console_OutputStyle::askQuestion(<Closure===true>)() called out of order: expected order 1, was 2

Also, the same happens with expectsOutput method.

This PR adds the call to once() method when creating the mock in PendingCommand, to avoid compare with the wrong mock when the question/output of multiples mocks are the same.

The once() method was deleted in #29267 , so maybe is necessary consider it.

@taylorotwell
Copy link
Member

What if you need to test the same question and same answer twice in one test?

@nuzkito
Copy link
Author

nuzkito commented Aug 5, 2019

You mean to have two ask in code and only one expectsQuestion in test? If so, you will need to replicate the expectsQuestion call in test.

Or if you mean to have both expectsQuestion with the same answer, it is also failing in 5.8.30, the fix solves it.

@taylorotwell taylorotwell requested a review from themsaid August 6, 2019 14:59
@taylorotwell
Copy link
Member

Why would we add back in something that was already causing problems?

/cc @themsaid need your input on how to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants