Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 testing "Command"s?

I've tried testing my commands in Laravel 4, as they are significant part of my system, but it seems like the documentation coverage is so poor, that they only explain basic testing of controllers and some models.

In Commands, you can pass arguments via command line to the class and it's received via $this->input property, something I don't know how to emulate.

Whenever I try to run the test for my command, when it expects an argument in "fire" method, I get this error:

Fatal error: Call to a member function getArgument() on a non-object in /var/www/html/project/vendor/laravel/framework/src/Illuminate/Console/Command.php on line 153

Which is logical, there's no argument passed. Is there a way to test this functionality?...

Thanks

like image 221
deb0rian Avatar asked Jan 08 '14 08:01

deb0rian


People also ask

How do you test the artisan command?

$this->artisan('artisan:command')->assertExitCode(0) is to assert that the command ends without error. So this is one simple way to test your custom artisan commands — but of course you can further details how to test your artisan commands. For me, this is good enough to make sure things run smoothly. Thanks!

Which command is used to run Laravel?

The Laravel PHP artisan serve command helps running applications on the PHP development server. As a developer, you can use Laravel artisan serve to develop and test various functions within the application.

Is there any CLI for Laravel?

Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application.


1 Answers

Most of it can be done using Symfony Command Tester (since Command is based on Symfony Console), example: http://alexandre-salome.fr/blog/Test-your-commands-in-Symfony2. However this would start to fail if you have to call another artisan command such as $this->call('db:seed'); or etc because this is actually Illuminate\Console\Application specific syntax.

I'm all open if there anyone that have a solution for above scenario.

like image 157
crynobone Avatar answered Oct 20 '22 06:10

crynobone