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\CestGenerator; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Command for generating a Codeception cest for a Module. |
16
|
|
|
* |
17
|
|
|
* @package SmartWeb\ModuleTesting\Console |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
class GenerateCest extends BaseCommand |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The console command name. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $name = 'make-cest'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The console command description. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $description = 'Generate a Codeception Cest for the given module and suite'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Execute the console command. |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
* |
41
|
|
|
* @throws Exception |
42
|
|
|
*/ |
43
|
|
|
public function handle() |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* @var string $moduleName |
47
|
|
|
* @var string $suite |
48
|
|
|
* @var string $name |
49
|
|
|
*/ |
50
|
|
|
$moduleName = $this->argument('moduleName'); |
51
|
|
|
$suite = $this->argument('suite'); |
52
|
|
|
$name = $this->argument('name'); |
53
|
|
|
|
54
|
|
|
$this->info("Creating '{$name}' for module '{$moduleName}' in suite '{$suite}'."); |
55
|
|
|
|
56
|
|
|
$setup = new Setup($moduleName); |
57
|
|
|
|
58
|
|
|
try { |
59
|
|
|
$generator = new CestGenerator($setup, $suite, $name); |
|
|
|
|
60
|
|
|
$generator->generate(); |
61
|
|
|
$this->info("Created test!"); |
62
|
|
|
} catch (Exception $e) { |
63
|
|
|
$this->error("Failed to create test!"); |
64
|
|
|
throw $e; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return CommandArguments |
70
|
|
|
*/ |
71
|
|
|
protected function provideArguments() : CommandArguments |
72
|
|
|
{ |
73
|
|
|
return new CommandArguments([ |
74
|
|
|
new CommandArgument('moduleName', InputArgumentType::required(), 'The name of the module.'), |
75
|
|
|
new CommandArgument('suite', InputArgumentType::required(), 'The suite to generate test in.'), |
76
|
|
|
new CommandArgument('name', InputArgumentType::required(), 'The name of the test.'), |
77
|
|
|
]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.