Testing Artisan Commands in Laravel 5.7

Testing Artisan Commands in Laravel 5.7

Laravel 5.7 is going to improve how you write Artisan console commands, with a new API contributed by Laravel employee Mohamed Said:

You can learn more about the new console testing API is available in the Laravel 5.7 Console Tests Documentation:

<?php

/**
 * Test a console command.
 *
 * @return void
 */
public function test_console_command()
{
    $this->artisan('laracon')
         ->expectsQuestion('What is your name?', 'Taylor Otwell')
         ->expectsQuestion('Which language do you program in?', 'PHP')
         ->expectsOutput('Your name is Taylor Otwell and you program in PHP.')
         ->assertExitCode(0);
}

Mohamed Said contributed the new testing API in laravel/framework#25270 if you are interested in the implementation details. He also introduced the new style of Testing Artisan Commands in Laravel 5.7+ on his blog, where you can find more information and an example.

Nice work Mohamed!


Filed in: Laravel 5.7 / Artisan / Testing


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Software Engineer Lead (PHP)
Remote
CivicPlus, LLC
Full-time Senior Web Developer
Detroit, MI
Wayne State University
Senior Software Engineer
Sydney, Australia
FoodByUs
Full Stack Engineer
Remote or Medford, Oregon
Empire Medical
Laravel Developer (fulltime - Dutch only)
Netherlands
Qbixx | Webservices
Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
Senior Quality Assurance Engineer
Remote
Bisnow Media