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.7] Mock console output while testing to help making assertions #25270

Merged
merged 3 commits into from Aug 24, 2018

Conversation

Projects
None yet
3 participants
@themsaid
Member

themsaid commented Aug 20, 2018

This makes it easier to test interactive artisan commands and also do assertions on the console output.

public function testBasicTest()
{

    $this->artisan('package:install')
        ->expectsQuestion('Please provide a token', 'tokenSecret')
        ->expectsOutput('Token is valid')
        ->expectsQuestion('Please select a release', 'v2.0')
        ->expectsQuestion('Are you sure you want to install v2.0?', 'yes')
        ->expectsOutput('Installing...')
        ->assertStatus(0);
}

For a console command like this:

public function handle()
{
    $token = $this->secret('Please provide a token');

    if(...){
        $this->info('Token is valid');
    }

    $release = $this->choice('Please select a release', ['v1.0', 'v2.0']);

    if ($this->confirm('Are you sure you want to install '.release.'?')) {
        $this->info('Installing...');
    }
}
@deleugpn

This comment has been minimized.

Show comment
Hide comment
@deleugpn

deleugpn Aug 20, 2018

Contributor

Is this the result of one of the items in the Twitter list? Cool stuff!

Contributor

deleugpn commented Aug 20, 2018

Is this the result of one of the items in the Twitter list? Cool stuff!

themsaid added some commits Aug 20, 2018

@themsaid

This comment has been minimized.

Show comment
Hide comment
@themsaid
Member

themsaid commented Aug 20, 2018

@deleugpn yup :)

@taylorotwell taylorotwell merged commit c0a5d9c into laravel:5.7 Aug 24, 2018

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment