1 <?php
2
3 namespace Skimia\Foundation\Testing\Traits;
4
5 use Skimia\Foundation\Testing\CommandOutput;
6 use Skimia\Foundation\Testing\TestablePromptCommandInterface;
7 use Symfony\Component\Console\Input\ArrayInput;
8 use Illuminate\Console\Command;
9
10 trait CommandTrait
11 {
12 13 14
15 protected $commandOutput = null;
16
17 18 19
20 public function getCommandOutput()
21 {
22 if (! isset($this->commandOutput)) {
23 $this->commandOutput = new CommandOutput;
24 }
25
26 return $this->commandOutput;
27 }
28
29 30 31 32 33
34 public function invokeCommand(Command $mockedCommandObject, $arguments = [])
35 {
36 $mockedCommandObject->setLaravel(app());
37
38 return $mockedCommandObject->run(new ArrayInput($arguments),
39 $this->getCommandOutput());
40 }
41
42 43 44 45 46
47 public function invokeCommandWithPrompt(TestablePromptCommandInterface $commandObject, $arguments = [])
48 {
49 $commandObject->setCommandOutput($this->getCommandOutput());
50
51 return $this->invokeCommand($commandObject, $arguments);
52 }
53
54 public function cleanOutputAndInvokeCommand(\Illuminate\Console\Command $commandObject, $arguments = [])
55 {
56 $this->commandOutput = null;
57
58 return $this->invokeCommand($commandObject, $arguments);
59 }
60 }
61