Laravel 4.1 - Testing the Artisan Team with Phpunit and Mockery

I am writing my first Artisan team in Laravel 4.1 and wanted some ideas on how to test it. My team is doing one thing (for now). It basically deletes table entries (notes) from the database, which is a given number of days.


Command example:

OneTimeNote:delete --days=25

The team works with flying flowers. But I wrote the team first for training purposes, and now I want to follow it with the test. I am using PHPUnit and Mockery.


Command Code: http://pastebin.com/index/dZrxpt8x

As you can see, I introduce my implementation of Notes (for abstraction), and then I execute one of its methods "deleteNotesOlderThan (int $ days)". As I said, all this works great and dandy. My problem starts when I try to verify this.


Team Test : http://pastebin.com/6UwxGvcN

If you look at the code, you will see where I am stuck. How can I build my Note method and generate a command test? Also, what things should I test with this particular command?

Thank you in advance

+3
source share
1 answer

My suggestion would be to follow the examples provided for you in Laravel.

, , Symfony 'CommandTester', .

https://github.com/laravel/framework/blob/master/tests/Foundation/FoundationConfigPublishCommandTest.php: ( )

public function testCommandCallsPublisherWithProperPackageName()
{
    $command = new Illuminate\Foundation\Console\ConfigPublishCommand($pub = m::mock('Illuminate\Foundation\ConfigPublisher'));
    $pub->shouldReceive('publishPackage')->once()->with('foo');
    $command->run(new Symfony\Component\Console\Input\ArrayInput(array('package' => 'foo')), new Symfony\Component\Console\Output\NullOutput);
}

, , , , run , "" .

+6

All Articles