-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathInteractsWithConsole.php
More file actions
44 lines (38 loc) · 1.1 KB
/
InteractsWithConsole.php
File metadata and controls
44 lines (38 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
declare(strict_types=1);
namespace Codeception\Module\Laravel;
use Illuminate\Contracts\Console\Kernel as ConsoleKernel;
use Symfony\Component\Console\Output\OutputInterface;
trait InteractsWithConsole
{
/**
* Call an Artisan command.
*
* ```php
* <?php
* $I->callArtisan('command:name');
* $I->callArtisan('command:name', ['parameter' => 'value']);
* ```
* Use 3rd parameter to pass in custom `OutputInterface`
*
* @return string|void
*/
public function callArtisan(string $command, array $parameters = [], ?OutputInterface $output = null)
{
$console = $this->getConsoleKernel();
if (!$output) {
$console->call($command, $parameters);
$output = trim($console->output());
$this->debug($output);
return $output;
}
$console->call($command, $parameters, $output);
}
/**
* @return \Illuminate\Foundation\Console\Kernel
*/
protected function getConsoleKernel(): ?ConsoleKernel
{
return $this->app[ConsoleKernel::class] ?? null;
}
}