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
$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!
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With