Jun 21, 2017
0
Level 4
How do I mock a Command object? Or test a service with dependences on ->info() Outputter
Object: Illuminate\Console\Command
I'm building an artisan cli for importing a file into mysql. Within my command, handle() I'm passing in $this to my service for access to the info() output interface, e.g.:
public function handle()
{
$service = resolve('MyService');
$service->setCommand($this);
}
Within MyService, I make several calls to info() for the purpose of a running CLI output:
$this->cmd->info('Say something', OutputInterface::VERBOSITY_NORMAL);
$this->cmd->info('Say something', OutputInterface::VERBOSITY_VERBOSE);
[... etc]
However, I'm getting blocked on unit testing. I can't figure out how I can mock or create a validate output interface Command so I can properly unit test.
How can I mock up a Command object to properly handle this situation? Or am I going about this entirely wrong? I can't be the only one needing progressive output throughout an Artisan CLI.
Thanks in advanced,
Please or to participate in this conversation.