Example 8-16. Calling Artisan commands from a test
public function test_empty_log_command_empties_logs_table() {
DB::table('logs')->insert(['message' => 'Did something']);
$this->assertCount(1, DB::table('logs')->get());
$this->artisan('logs:empty'); // Same as Artisan::call('logs:empty');
$this->assertCount(0, DB::table('logs')->get());
}
Example 8-17. Making assertions against the input and output of Artisan commands
public function testItCreatesANewUser() {
$this->artisan('myapp:create-user')
->expectsQuestion("What's the name of the new user?", "Wilbur Powery")
->expectsQuestion("What's the email of the new user?", "wilbur@thisbook.co")
->expectsQuestion("What's the password of the new user?", "secret")
->expectsOutput("User Wilbur Powery created!");
$this->assertDatabaseHas('users', [
'email' => 'wilbur@thisbook.co'
]);
}