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] Added a 'expectedOutputNever' method for console command testing #35160

Merged

Conversation

ash-jc-allen
Copy link
Contributor

Hi!

This pull request adds a new ->expectsOutputNever() method can be used for testing console commands. I think that this could be quite useful for helping to make the console tests a bit stricter.

This might not be the best example to show where it could be used, but it should hopefully give you a bit of an idea:

Command:

public function handle()
{
    if ($this->something()) {
        $this->info('Something is truthy!');
    }

    // Continue the rest of the command...

    return 0;
}

Test:

public function test_the_command_when_something_is_falsey()
{
    $this->artisan('signature')
        ->expectsOutputNever('Something is truthy!')
        ->assertExitCode(0);
}

public function test_the_command_when_something_is_truthy()
{
    $this->artisan('signature')
        ->expectsOutput('Something is truthy!')
        ->assertExitCode(0);
}

I'm hoping that you all think it could be valuable and would help with writing console tests. If I've targeted this to the wrong branch or if it needs any changes if you want to pull it in, please let me know and I'll update it straight away. 😄

@GrahamCampbell GrahamCampbell changed the title Added a 'expectedOutputNever' method for console command testing [8.x] Added a 'expectedOutputNever' method for console command testing Nov 9, 2020
@taylorotwell
Copy link
Member

Does not work with two Artisan commands in one test.

image

image

@ash-jc-allen
Copy link
Contributor Author

Ah okay, I completely forgot to try with more than 1 command in a test. I'll take another look and update it

@taylorotwell
Copy link
Member

I'll fix it.

@taylorotwell taylorotwell merged commit 091509b into laravel:8.x Nov 11, 2020
@taylorotwell
Copy link
Member

Renamed to doesntExpectOutput.

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