Reputation: 51
I am using phpspec to test our application. Now we need to develop some commands and therefore I want to spec these as well.
I am a bit stuck here, because the docs (http://symfony.com/doc/master/cookbook/console/console_command.html#testing-commands) only tell me how to test the commands using phpunit.
Even if I would use a similar approach (creating the kernel somehow, and instantiating the command in question) in the specs I think that this would not follow the idea of describing behaviour. I would only spec, whether the output is correct or not, but not if the command is calling the right methods and so on.
Has anyone used phpspec to successfully describe Symfony2 commands? What would be a feasible approach of doing this?
Thanks
Upvotes: 3
Views: 964
Reputation: 18848
You can use PhpSpec to test Command in a unit testable way - it's not too bad but you end up with a lot of mocking of input/output.
It's better to keep your Commands nice and small, with them delegating to other services that are unit tested - then you can cover with Behat and get your confidence that they're working.
It's a very similar problem to testing Controllers, just that Commands have more dependencies to mock if you try the unit testing approach.
Upvotes: 3