|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace SmartWeb\ModuleTesting\Console\Command; |
|
5
|
|
|
|
|
6
|
|
|
use Exception; |
|
7
|
|
|
use SmartWeb\ModuleTesting\Codeception\SmartWeb\Setup; |
|
8
|
|
|
use SmartWeb\ModuleTesting\Console\CommandArgument; |
|
9
|
|
|
use SmartWeb\ModuleTesting\Console\CommandArguments; |
|
10
|
|
|
use SmartWeb\ModuleTesting\Console\InputArgumentType; |
|
11
|
|
|
use SmartWeb\ModuleTesting\Generator\Test\CestGenerator; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Command for generating a Codeception cest for a Module. |
|
15
|
|
|
* |
|
16
|
|
|
* @package SmartWeb\ModuleTesting\Console |
|
17
|
|
|
*/ |
|
18
|
|
|
class GenerateCest extends BaseCommand |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @inheritDoc |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct() |
|
25
|
|
|
{ |
|
26
|
|
|
parent::__construct('make-cest', 'Generate a Codeception Cest for the given module and suite'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Execute the console command. |
|
31
|
|
|
* |
|
32
|
|
|
* @return void |
|
33
|
|
|
* |
|
34
|
|
|
* @throws Exception |
|
35
|
|
|
*/ |
|
36
|
|
|
public function handle() |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* @var string $moduleName |
|
40
|
|
|
* @var string $suite |
|
41
|
|
|
* @var string $name |
|
42
|
|
|
*/ |
|
43
|
|
|
$moduleName = $this->argument('moduleName'); |
|
44
|
|
|
$suite = $this->argument('suite'); |
|
45
|
|
|
$name = $this->argument('name'); |
|
46
|
|
|
|
|
47
|
|
|
$this->info("Creating '{$name}' for module '{$moduleName}' in suite '{$suite}'."); |
|
48
|
|
|
|
|
49
|
|
|
$setup = new Setup($moduleName); |
|
50
|
|
|
|
|
51
|
|
|
try { |
|
52
|
|
|
$generator = new CestGenerator($setup, $suite, $name); |
|
|
|
|
|
|
53
|
|
|
$generator->generate(); |
|
54
|
|
|
$this->info("Created test!"); |
|
55
|
|
|
} catch (Exception $e) { |
|
56
|
|
|
$this->error("Failed to create test!"); |
|
57
|
|
|
throw $e; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return CommandArguments |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function provideArguments() : CommandArguments |
|
65
|
|
|
{ |
|
66
|
|
|
return new CommandArguments([ |
|
67
|
|
|
new CommandArgument('moduleName', InputArgumentType::required(), 'The name of the module.'), |
|
68
|
|
|
new CommandArgument('suite', InputArgumentType::required(), 'The suite to generate test in.'), |
|
69
|
|
|
new CommandArgument('name', InputArgumentType::required(), 'The name of the test.'), |
|
70
|
|
|
]); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
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.