-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
expectsOutput breaks next test on fail #29246
Comments
I honestly don't understand what your problem is, can you please share simple steps to reproduce the issue? The |
No problem, it actually took me a while to expose and understand this bug. Steps to reproduceThe simplest way to reproduce it is to add this test into a brand new laravel application
Paste this inside of the <?php
namespace Tests\Feature;
use Illuminate\Support\Facades\Artisan;
use Tests\TestCase;
class ExposeBugCommandTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
Artisan::command('hello', function () {
$this->info('hello world');
});
}
public function test_hello_says_hola_mundo()
{
$this->artisan('hello')
->expectsOutput('hola mundo');
}
public function test_hello_says_hello_world()
{
$this->artisan('hello')
->expectsOutput('hello world');
}
}
ExplanationsBy simply looking at this test you can see that the first test method should fail and the second one pass. But if you run Now if you run What I have discovered is that Inside of the On subsequent tests NotificationsIf there are other test traits using PRsWe've been discussing the fix with @GrahamCampbell and @crynobone inside of these pr:
Hope it helps 😃 if it's still not clear do not hesitate I'll do my best to give extra details. |
The issue is now getting fixed in #29267 |
Resolved in #29267 closing. |
Description:
When using
expectsOutput
in two consecutive tests if the first one fails the second one will also fail.Steps To Reproduce:
Edited: Better steps to reproduce given a few comments later
What it may be?
After looking a bit in the source code I think I may have an idea of what is causing this bug.
Under the hood the
expectsOutput
function reports errors in itsbeforeApplicationDestroyed
callback using the$this->fail()
method.The fail method actually throws an exception preventing subsequent
beforeApplicationDestroyed
callback from being called thus leaving the test suite in an unexpected state.I've first found out about this bug at work where I am using the DatabaseTransaction trait. If I get a failed
expectsOutput
assertion my whole test suite breaks because the transaction is not rolled back and subsequent tests cannot communicate with the db because of the transaction's lock.How could it be fixed?
We could add a new
afterApplicationDestroyed
callback system and use it in theInteractsWithConsole
trait.These callbacks would get called at the end of the tearDown function.
If fixing this bug is not too much of a hurry for you and you are ok with the addition of the
afterApplicationDestroyed
callback system - I will do it :)The text was updated successfully, but these errors were encountered: