Laravel 4 testing "Command" s?

I tried to test my commands in Laravel 4, because they are a significant part of my system, but it seems that the documentation coverage is so low that they explain only basic testing of controllers and some models.

In commands, you can pass arguments through the command line to the class and receive through the $ this-> input property, which I don’t know how to emulate.

Whenever I try to run a test for my team, when it expects an argument in the 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, the argument is not passed. Is there any way to test this functionality? ...

thanks

+7
php unit-testing laravel-4
source share
2 answers

Most of them can be done using the Symfony Command Tester (since the command is based on the Symfony Console), for example: http://alexandre-salome.fr/blog/Test-your-commands-in-Symfony2 . However, this can lead to a crash if you need to call another artisan command, such as $this->call('db:seed'); or etc., because this is the actual syntax of Illuminate\Console\Application .

I am all open if there is anyone who has a solution for the above scenario.

+3
source share

I recently posted a post on Testing Laravel Commands .

If you have a specific piece of code that you want to use in several commands, you need to move this piece of code somewhere where both commands can use it (event handler, trait, another class ...), and then in your command refer to this code instead of using $this->call('db:seed');

-one
source share

All Articles