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

[8.x] Fix Artisan test method PendingCommand::doesntExpectOutput() always causing a failed test #36806

Merged

Conversation

derekmd
Copy link
Contributor

@derekmd derekmd commented Mar 29, 2021

It seems #35160 added in v8.15.0 (2020-11-17) has never worked for the successful test case. e.g.,

$this->artisan('dusk:firefox-driver')
    ->doesntExpectOutput('Geckodriver binary installation failed for Linux.');

When that string isn't output by the command, this test should pass. Instead this exception is thrown and the test fails:

Mockery\Exception\InvalidCountException: Method doWrite('Geckodriver binary installation failed for Linux.', <Any>)
from Mockery_0_Symfony_Component_Console_Output_BufferedOutput should be called
exactly 1 times but called 0 times.

Mockery::close() in tearDown() throws this exception because ->once() was called when setting up the doesntExpectOutput() mock. But that isn't needed. During a successful test run, that should be called zero times. It looks like that code snippet was copy and pasted from the opposite expectedOutput case a few lines up.

So I've added some InteractsWithConsole::artisan() test coverage on assertion methods assertExitCode(), doesntExpectOutput(), and expectsOutput() (this one requires some Mockery once() exception suppression).

@derekmd derekmd force-pushed the fix-test-method-artisan-doesnt-expect-output branch from 9c86b98 to f36b4ab Compare March 29, 2021 20:28
@derekmd derekmd changed the title [8.x] Fix Artisan test method PendingCommand::doesntExpectOutput() always throwing an exception [8.x] Fix Artisan test method PendingCommand::doesntExpectOutput() always causing a failed test Mar 29, 2021
@derekmd derekmd force-pushed the fix-test-method-artisan-doesnt-expect-output branch from f36b4ab to 0fa24c6 Compare March 29, 2021 21:09
On what should be a passing test when the doesntExpectOutput()
arg hasn't been output, PHPUnit's tearDown() call to
Mockery::close() will throw any exception.

Mockery\Exception\InvalidCountException: Method doWrite($output, <Any>)
from Mockery_0_Symfony_Component_Console_Output_BufferedOutput should be
called exactly 1 times but called 0 times.

During a successful test run, it _should_ be called 0 times.
Remove once() to allow the `andReturnUsing()` callback to be
invoked one or many times.

And add integration test coverage to PendingCommand.
@derekmd derekmd force-pushed the fix-test-method-artisan-doesnt-expect-output branch from 0fa24c6 to 1405012 Compare March 30, 2021 09:08
@taylorotwell taylorotwell merged commit 7c4b97f into laravel:8.x Mar 30, 2021
@derekmd derekmd deleted the fix-test-method-artisan-doesnt-expect-output branch March 30, 2021 20:44
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.

None yet

2 participants