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

Merged
merged 3 commits into from Aug 24, 2018

Conversation

@themsaid
Copy link
Member

@themsaid 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
Copy link
Contributor

@deleugpn deleugpn commented Aug 20, 2018

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

themsaid added 2 commits Aug 20, 2018
@themsaid
Copy link
Member Author

@themsaid themsaid commented Aug 20, 2018

@deleugpn yup :)

@taylorotwell taylorotwell merged commit c0a5d9c into laravel:5.7 Aug 24, 2018
2 checks passed
2 checks passed
continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@neyosoft
Copy link

@neyosoft neyosoft commented Nov 22, 2018

Not sure the test is working correctly with confirm() method. I'll confirm that and submit test for that

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

Successfully merging this pull request may close these issues.

None yet

4 participants