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\Testing\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
|
|
|
$moduleName = $this->argument('moduleName'); |
45
|
|
|
$this->info("Creating testing setup for '{$moduleName}'."); |
46
|
|
|
|
47
|
|
|
$setup = new Setup($moduleName); |
|
|
|
|
48
|
|
|
$generator = new SetupGenerator($setup); |
49
|
|
|
|
50
|
|
|
// TODO: Get default suites from Laravel config |
51
|
|
|
$defaultSuites = ['Unit', 'Integration', 'GraphQL', 'Acceptance']; |
52
|
|
|
|
53
|
|
|
$suites = $this->getOption('suites', $defaultSuites); |
54
|
|
|
|
55
|
|
|
$suiteCount = count($suites); |
56
|
|
|
$suiteText = Str::plural('suite', $suiteCount); |
57
|
|
|
|
58
|
|
|
$this->info("Generating {$suiteCount} {$suiteText}: '" . implode("', '", $suites) . "'"); |
59
|
|
|
$generator->generate($suites); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$this->info("Done! Go create some tests!"); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return CommandArguments |
66
|
|
|
*/ |
67
|
|
|
protected function provideArguments() : CommandArguments |
68
|
|
|
{ |
69
|
|
|
return new CommandArguments([ |
70
|
|
|
new CommandArgument('moduleName', InputArgumentType::required(), 'The name of the module.'), |
71
|
|
|
new CommandArgument('suites', InputArgumentType::optionalArray(), 'The suites to generate.'), |
72
|
|
|
]); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.