Anyone :<?
How to test commands as the domain layer
Hello.
I really like using Behat with ubiquitous language as I can then run the features against a DomainContext and a UserInterfaceContext. However, I find it quite hard to test my commands.
If I'm not using a command and just for example a repository I would do something like this in my test step:
protected $repo;
// maybe there is a way to do it more elegantly?
public function __construct() {
$this->repo = app('FooRepository');
}
// in my step
$this->repo->bar($args);
However, when it comes down to commands, how should I test it? My command itself will take advantage of the repository so I need to somehow trigger my command or my underlying code?
If my command's handle method is:
public function handle(FooRepository $repo)
{
$repo->bar($this->args);
}
How would I approach it in my test?
protected $dispatcher;
public function __constrcut()
{
$this->dispatcher = app('Illuminate\Contracts\Bus\Dispatcher');
}
// in my step
$this->dispatcher->dispatchFrom(FooCommand::class, $args)
I really feel that there is a much better way to do this but I'm missing it.
Please share with me how should I test that.
P.S. In my first example w/o commands I resolved a repository from the IoC Container, do you think there is a more elegant way to do it? Or for each repository my context may need I will have to resolve it out of the IoC container which can very quickly become cluttered :/
Please or to participate in this conversation.