Laravel Artisan command in controller ignores additional options

Viewed 287

I'm trying to run an Artisan command from a controller with options to either run parallel or test a single test class:

$this->call('test', [
    '--parallel',
    '--filter' => 'FooTest',
]);

But it just ignores any options. If I run php artisan test --filter=FooTest or php artisan test --parallel in the command line this works just fine.

I've tried using Artisan::call( ... ), put the array in a variable, use array() instead of [] but nothing seems to work.

But when I run a seeder with options it works just fine

$this->call('db:seed', ['--class' => 'EssentialDatabaseSeeder']);
1 Answers

If you're attempting to pass a boolean value to the Artisan command, you need to do the following:

$this->call('test', [
    '--parallel' => true, // Add true here
    '--filter' => 'FooTest',
]);

From the documentation:

Passing Boolean Values
If you need to specify the value of an option that does not accept string values, such as the --force flag on the migrate:refresh command, you should pass true or false as the value of the option:

Related