Skip to content

Commit 430608a

Browse files
committed
Split console methods
1 parent d68ee8d commit 430608a

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

src/Codeception/Module/Laravel.php

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
use Codeception\Lib\Interfaces\PartedModule;
1414
use Codeception\Lib\ModuleContainer;
1515
use Codeception\Module\Laravel\InteractsWithAuthentication;
16+
use Codeception\Module\Laravel\InteractsWithConsole;
1617
use Codeception\Subscriber\ErrorHandler;
1718
use Codeception\TestInterface;
1819
use Codeception\Util\ReflectionHelper;
1920
use Exception;
20-
use Illuminate\Contracts\Console\Kernel;
2121
use Illuminate\Contracts\Routing\UrlGenerator;
2222
use Illuminate\Contracts\Session\Session;
2323
use Illuminate\Contracts\View\Factory as ViewContract;
@@ -35,7 +35,6 @@
3535
use ReflectionClass;
3636
use ReflectionException;
3737
use RuntimeException;
38-
use Symfony\Component\Console\Output\OutputInterface;
3938
use function is_array;
4039

4140
/**
@@ -131,6 +130,7 @@
131130
class Laravel extends Framework implements ActiveRecord, PartedModule
132131
{
133132
use InteractsWithAuthentication;
133+
use InteractsWithConsole;
134134

135135
/**
136136
* @var Application
@@ -426,34 +426,6 @@ public function dontSeeEventTriggered($expected): void
426426
}
427427
}
428428

429-
/**
430-
* Call an Artisan command.
431-
*
432-
* ``` php
433-
* <?php
434-
* $I->callArtisan('command:name');
435-
* $I->callArtisan('command:name', ['parameter' => 'value']);
436-
* ```
437-
* Use 3rd parameter to pass in custom `OutputInterface`
438-
*
439-
* @param string $command
440-
* @param array $parameters
441-
* @param OutputInterface|null $output
442-
* @return string|void
443-
*/
444-
public function callArtisan(string $command, $parameters = [], OutputInterface $output = null)
445-
{
446-
$console = $this->app->make(Kernel::class);
447-
if (!$output) {
448-
$console->call($command, $parameters);
449-
$output = trim($console->output());
450-
$this->debug($output);
451-
return $output;
452-
}
453-
454-
$console->call($command, $parameters, $output);
455-
}
456-
457429
/**
458430
* Opens web page using route name and parameters.
459431
*
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Codeception\Module\Laravel;
6+
7+
use Illuminate\Contracts\Console\Kernel;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
10+
trait InteractsWithConsole
11+
{
12+
/**
13+
* Call an Artisan command.
14+
*
15+
* ``` php
16+
* <?php
17+
* $I->callArtisan('command:name');
18+
* $I->callArtisan('command:name', ['parameter' => 'value']);
19+
* ```
20+
* Use 3rd parameter to pass in custom `OutputInterface`
21+
*
22+
* @param string $command
23+
* @param array $parameters
24+
* @param OutputInterface|null $output
25+
* @return string|void
26+
*/
27+
public function callArtisan(string $command, $parameters = [], OutputInterface $output = null)
28+
{
29+
$console = $this->app->make(Kernel::class);
30+
if (!$output) {
31+
$console->call($command, $parameters);
32+
$output = trim($console->output());
33+
$this->debug($output);
34+
return $output;
35+
}
36+
37+
$console->call($command, $parameters, $output);
38+
}
39+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy