|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace SmartWeb\ModuleTesting\Console\Command; |
|
5
|
|
|
|
|
6
|
|
|
use Illuminate\Support\Str; |
|
7
|
|
|
use SmartWeb\ModuleTesting\Codeception\SmartWeb\Setup; |
|
8
|
|
|
use SmartWeb\ModuleTesting\Codeception\SmartWeb\SetupGenerator; |
|
9
|
|
|
use SmartWeb\ModuleTesting\Console\CommandArgument; |
|
10
|
|
|
use SmartWeb\ModuleTesting\Console\CommandArguments; |
|
11
|
|
|
use SmartWeb\ModuleTesting\Console\InputArgumentType; |
|
12
|
|
|
use function implode; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Command for generating a complete Codeception setup for a Module. |
|
17
|
|
|
* |
|
18
|
|
|
* @package SmartWeb\ModuleTesting\Console |
|
19
|
|
|
*/ |
|
20
|
|
|
class GenerateSetup extends BaseCommand |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The console command name. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $name = 'setup'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The console command description. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $description = 'Setting up Codeception testing for the first time'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Execute the console command. |
|
39
|
|
|
* |
|
40
|
|
|
* @return void |
|
41
|
|
|
*/ |
|
42
|
|
|
public function fire() |
|
43
|
|
|
{ |
|
44
|
|
|
/** |
|
45
|
|
|
* @var string $moduleName |
|
46
|
|
|
*/ |
|
47
|
|
|
$moduleName = $this->argument('moduleName'); |
|
48
|
|
|
$this->info("Creating testing setup for '{$moduleName}'."); |
|
49
|
|
|
|
|
50
|
|
|
$setup = new Setup($moduleName); |
|
51
|
|
|
$generator = new SetupGenerator($setup); |
|
52
|
|
|
|
|
53
|
|
|
// TODO: Get default suites from Laravel config |
|
54
|
|
|
$defaultSuites = ['Unit', 'Integration', 'GraphQL', 'Acceptance']; |
|
55
|
|
|
|
|
56
|
|
|
$suites = $this->getOption('suites', $defaultSuites); |
|
57
|
|
|
|
|
58
|
|
|
$suiteCount = count($suites); |
|
59
|
|
|
$suiteText = Str::plural('suite', $suiteCount); |
|
60
|
|
|
|
|
61
|
|
|
$this->info("Generating {$suiteCount} {$suiteText}: '" . implode("', '", $suites) . "'"); |
|
62
|
|
|
$generator->generate($suites); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
$this->info("Done! Go create some tests!"); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return CommandArguments |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function provideArguments() : CommandArguments |
|
71
|
|
|
{ |
|
72
|
|
|
return new CommandArguments([ |
|
73
|
|
|
new CommandArgument('moduleName', InputArgumentType::required(), 'The name of the module.'), |
|
74
|
|
|
new CommandArgument('suites', InputArgumentType::optionalArray(), 'The suites to generate.'), |
|
75
|
|
|
]); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: