Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6ddcb0

Browse files
authored
Migrate commands to use AsCommand attribute (#6850)
1 parent 55d7418 commit e6ddcb0

23 files changed

+171
-87
lines changed

src/Codeception/Command/Bootstrap.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Codeception\Command;
66

77
use Codeception\Template\Bootstrap as BootstrapTemplate;
8+
use Symfony\Component\Console\Attribute\AsCommand;
89
use Symfony\Component\Console\Command\Command;
910
use Symfony\Component\Console\Input\InputArgument;
1011
use Symfony\Component\Console\Input\InputInterface;
@@ -24,11 +25,15 @@
2425
* * `codecept bootstrap path/to/the/project` - provide different path to a project, where tests should be placed
2526
*
2627
*/
28+
#[AsCommand(
29+
name: 'bootstrap',
30+
description: 'Creates default test suites and generates all required files'
31+
)]
2732
class Bootstrap extends Command
2833
{
2934
protected function configure(): void
3035
{
31-
$this->setDescription('Creates default test suites and generates all required files')
36+
$this
3237
->addArgument('path', InputArgument::OPTIONAL, 'custom installation dir')
3338
->addOption('namespace', 's', InputOption::VALUE_OPTIONAL, 'Namespace to add for actor classes and helpers')
3439
->addOption('actor', 'a', InputOption::VALUE_OPTIONAL, 'Custom actor instead of Tester')

src/Codeception/Command/Build.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Codeception\Configuration;
88
use Codeception\Lib\Generator\Actions as ActionsGenerator;
99
use Codeception\Lib\Generator\Actor as ActorGenerator;
10+
use Symfony\Component\Console\Attribute\AsCommand;
1011
use Symfony\Component\Console\Command\Command;
1112
use Symfony\Component\Console\Input\InputInterface;
1213
use Symfony\Component\Console\Output\OutputInterface as SymfonyOutputInterface;
@@ -21,6 +22,10 @@
2122
* * `codecept build path/to/project`
2223
*
2324
*/
25+
#[AsCommand(
26+
name: 'build',
27+
description: 'Generates base classes for all suites'
28+
)]
2429
class Build extends Command
2530
{
2631
use Shared\ConfigTrait;
@@ -30,11 +35,6 @@ class Build extends Command
3035

3136
protected ?SymfonyOutputInterface $output = null;
3237

33-
public function getDescription(): string
34-
{
35-
return 'Generates base classes for all suites';
36-
}
37-
3838
protected function execute(InputInterface $input, SymfonyOutputInterface $output): int
3939
{
4040
$this->output = $output;

src/Codeception/Command/Clean.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Codeception\Configuration;
88
use Codeception\Util\FileSystem;
9+
use Symfony\Component\Console\Attribute\AsCommand;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\InputInterface;
1112
use Symfony\Component\Console\Output\OutputInterface;
@@ -16,19 +17,18 @@
1617
* * `codecept clean`
1718
*
1819
*/
20+
#[AsCommand(
21+
name: 'clean',
22+
description: 'Recursively cleans log and generated code'
23+
)]
1924
class Clean extends Command
2025
{
2126
use Shared\ConfigTrait;
2227

23-
protected function configure(): void
24-
{
25-
$this->setDescription('Recursively cleans log and generated code');
26-
}
27-
2828
protected function execute(InputInterface $input, OutputInterface $output): int
2929
{
3030
$this->cleanProjectsRecursively($output, Configuration::projectDir());
31-
$output->writeln("Done");
31+
$output->writeln('Done');
3232
return Command::SUCCESS;
3333
}
3434

src/Codeception/Command/CompletionFallback.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@
44

55
namespace Codeception\Command;
66

7+
use Symfony\Component\Console\Attribute\AsCommand;
78
use Symfony\Component\Console\Command\Command;
89
use Symfony\Component\Console\Input\InputInterface;
910
use Symfony\Component\Console\Output\OutputInterface;
1011

12+
#[AsCommand(
13+
name: '_completion',
14+
description: 'BASH completion hook.',
15+
hidden: true
16+
)]
1117
class CompletionFallback extends Command
1218
{
13-
public function __construct()
14-
{
15-
parent::__construct('_completion');
16-
}
17-
1819
protected function configure(): void
1920
{
20-
$this
21-
->setDescription('BASH completion hook.')
22-
->setHidden(true) // Hide from listing
23-
->setHelp(<<<END
21+
$this->setHelp(<<<END
2422
To enable BASH completion, install optional stecman/symfony-console-completion first:
2523
2624
<comment>composer require stecman/symfony-console-completion</comment>

src/Codeception/Command/ConfigValidate.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Codeception\Command;
66

77
use Codeception\Configuration;
8+
use Symfony\Component\Console\Attribute\AsCommand;
89
use Symfony\Component\Console\Command\Command;
910
use Symfony\Component\Console\Input\InputArgument;
1011
use Symfony\Component\Console\Input\InputInterface;
@@ -14,9 +15,6 @@
1415
use function codecept_data_dir;
1516
use function codecept_output_dir;
1617
use function codecept_root_dir;
17-
use function implode;
18-
use function preg_replace;
19-
use function print_r;
2018

2119
/**
2220
* Validates and prints Codeception config.
@@ -39,14 +37,18 @@
3937
* * `codecept config:validate -o "reporters: report: \Custom\Reporter" --report`: use custom reporter
4038
*
4139
*/
40+
#[AsCommand(
41+
name: 'config:validate',
42+
description: 'Validates and prints Codeception config'
43+
)]
4244
class ConfigValidate extends Command
4345
{
4446
use Shared\ConfigTrait;
4547
use Shared\StyleTrait;
4648

4749
protected function configure(): void
4850
{
49-
$this->setDescription('Validates and prints config to screen')
51+
$this
5052
->addArgument('suite', InputArgument::OPTIONAL, 'To show suite configuration')
5153
->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Use custom path for config')
5254
->addOption('override', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Override config values');

src/Codeception/Command/Console.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Codeception\SuiteManager;
1717
use Codeception\Test\Cept;
1818
use Codeception\Util\Debug;
19+
use Symfony\Component\Console\Attribute\AsCommand;
1920
use Symfony\Component\Console\Command\Command;
2021
use Symfony\Component\Console\Input\InputArgument;
2122
use Symfony\Component\Console\Input\InputInterface;
@@ -32,6 +33,10 @@
3233
*
3334
* * `codecept console acceptance` - starts acceptance suite environment. If you use WebDriver you can manipulate browser with Codeception commands.
3435
*/
36+
#[AsCommand(
37+
name: 'console',
38+
description: 'Launches interactive test console'
39+
)]
3540
class Console extends Command
3641
{
3742
protected ?Cept $test = null;
@@ -49,9 +54,9 @@ class Console extends Command
4954

5055
protected function configure(): void
5156
{
52-
$this->setDescription('Launches interactive test console')
57+
$this
5358
->addArgument('suite', InputArgument::REQUIRED, 'suite to be executed')
54-
->addOption('colors', '', InputOption::VALUE_NONE, 'Use colors in output');
59+
->addOption('colors', null, InputOption::VALUE_NONE, 'Use colors in output');
5560
}
5661

5762
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -84,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8489
$this->test = new Cept('', '');
8590
$this->test->getMetadata()->setServices([
8691
'dispatcher' => $eventDispatcher,
87-
'modules' => $moduleContainer
92+
'modules' => $moduleContainer,
8893
]);
8994

9095
$scenario = new Scenario($this->test);

src/Codeception/Command/DryRun.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use ReflectionMethod;
2424
use ReflectionNamedType;
2525
use ReflectionUnionType;
26+
use Symfony\Component\Console\Attribute\AsCommand;
2627
use Symfony\Component\Console\Command\Command;
2728
use Symfony\Component\Console\Input\InputArgument;
2829
use Symfony\Component\Console\Input\InputInterface;
@@ -42,19 +43,21 @@
4243
* * `codecept dry-run tests/acceptance/MyCest.php`
4344
*
4445
*/
46+
#[AsCommand(
47+
name: 'dry-run',
48+
description: 'Prints step-by-step scenario-driven test or a feature'
49+
)]
4550
class DryRun extends Command
4651
{
4752
use Shared\ConfigTrait;
4853
use Shared\StyleTrait;
4954

5055
protected function configure(): void
5156
{
52-
$this->setDefinition(
53-
[
54-
new InputArgument('suite', InputArgument::REQUIRED, 'suite to scan for feature files'),
55-
new InputArgument('test', InputArgument::OPTIONAL, 'tests to be loaded'),
56-
]
57-
);
57+
$this->setDefinition([
58+
new InputArgument('suite', InputArgument::REQUIRED, 'suite to scan for feature files'),
59+
new InputArgument('test', InputArgument::OPTIONAL, 'tests to be loaded'),
60+
]);
5861
parent::configure();
5962
}
6063

src/Codeception/Command/GenerateCest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Codeception\Command;
66

77
use Codeception\Lib\Generator\Cest as CestGenerator;
8+
use Symfony\Component\Console\Attribute\AsCommand;
89
use Symfony\Component\Console\Command\Command;
910
use Symfony\Component\Console\Input\InputArgument;
1011
use Symfony\Component\Console\Input\InputInterface;
@@ -21,14 +22,18 @@
2122
* * `codecept g:cest "App\Login"`
2223
*
2324
*/
25+
#[AsCommand(
26+
name: 'generate:cest',
27+
description: 'Generates empty Cest file in suite'
28+
)]
2429
class GenerateCest extends Command
2530
{
2631
use Shared\FileSystemTrait;
2732
use Shared\ConfigTrait;
2833

2934
protected function configure(): void
3035
{
31-
$this->setDescription('Generates empty Cest file in suite')
36+
$this
3237
->addArgument('suite', InputArgument::REQUIRED, 'suite where tests will be put')
3338
->addArgument('class', InputArgument::REQUIRED, 'test name');
3439
}

src/Codeception/Command/GenerateEnvironment.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Codeception\Configuration;
88
use Codeception\Exception\ConfigurationException;
9+
use Symfony\Component\Console\Attribute\AsCommand;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\InputArgument;
1112
use Symfony\Component\Console\Input\InputInterface;
@@ -18,15 +19,18 @@
1819
*
1920
* Required to have `envs` path to be specified in `codeception.yml`
2021
*/
22+
#[AsCommand(
23+
name: 'generate:environment',
24+
description: 'Generates empty environment config'
25+
)]
2126
class GenerateEnvironment extends Command
2227
{
2328
use Shared\FileSystemTrait;
2429
use Shared\ConfigTrait;
2530

2631
protected function configure(): void
2732
{
28-
$this->setDescription('Generates empty environment config')
29-
->addArgument('env', InputArgument::REQUIRED, 'Environment name');
33+
$this->addArgument('env', InputArgument::REQUIRED, 'Environment name');
3034
}
3135

3236
protected function execute(InputInterface $input, OutputInterface $output): int

src/Codeception/Command/GenerateFeature.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Codeception\Command;
66

77
use Codeception\Lib\Generator\Feature;
8+
use Symfony\Component\Console\Attribute\AsCommand;
89
use Symfony\Component\Console\Command\Command;
910
use Symfony\Component\Console\Input\InputArgument;
1011
use Symfony\Component\Console\Input\InputInterface;
@@ -23,14 +24,18 @@
2324
* * `codecept g:feature suite login.feature -c path/to/project`
2425
*
2526
*/
27+
#[AsCommand(
28+
name: 'generate:feature',
29+
description: 'Generates empty feature file in suite'
30+
)]
2631
class GenerateFeature extends Command
2732
{
2833
use Shared\FileSystemTrait;
2934
use Shared\ConfigTrait;
3035

3136
protected function configure(): void
3237
{
33-
$this->setDescription('Generates empty feature file in suite')
38+
$this
3439
->addArgument('suite', InputArgument::REQUIRED, 'suite to be tested')
3540
->addArgument('feature', InputArgument::REQUIRED, 'feature to be generated')
3641
->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Use custom path for config');

src/Codeception/Command/GenerateGroup.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Codeception\Configuration;
88
use Codeception\Lib\Generator\Group as GroupGenerator;
9+
use Symfony\Component\Console\Attribute\AsCommand;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\InputArgument;
1112
use Symfony\Component\Console\Input\InputInterface;
@@ -18,15 +19,18 @@
1819
*
1920
* * `codecept g:group Admin`
2021
*/
22+
#[AsCommand(
23+
name: 'generate:groupobject',
24+
description: 'Generates Group subscriber'
25+
)]
2126
class GenerateGroup extends Command
2227
{
2328
use Shared\FileSystemTrait;
2429
use Shared\ConfigTrait;
2530

2631
protected function configure(): void
2732
{
28-
$this->setDescription('Generates Group subscriber')
29-
->addArgument('group', InputArgument::REQUIRED, 'Group class name');
33+
$this->addArgument('group', InputArgument::REQUIRED, 'Group class name');
3034
}
3135

3236
protected function execute(InputInterface $input, OutputInterface $output): int

src/Codeception/Command/GenerateHelper.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Codeception\Configuration;
88
use Codeception\Lib\Generator\Helper;
9+
use Symfony\Component\Console\Attribute\AsCommand;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\InputArgument;
1112
use Symfony\Component\Console\Input\InputInterface;
@@ -18,17 +19,19 @@
1819
*
1920
* * `codecept g:helper MyHelper`
2021
* * `codecept g:helper "My\Helper"`
21-
*
2222
*/
23+
#[AsCommand(
24+
name: 'generate:helper',
25+
description: 'Generates a new helper'
26+
)]
2327
class GenerateHelper extends Command
2428
{
2529
use Shared\FileSystemTrait;
2630
use Shared\ConfigTrait;
2731

2832
protected function configure(): void
2933
{
30-
$this->setDescription('Generates a new helper')
31-
->addArgument('name', InputArgument::REQUIRED, 'Helper name');
34+
$this->addArgument('name', InputArgument::REQUIRED, 'Helper name');
3235
}
3336

3437
protected function execute(InputInterface $input, OutputInterface $output): int

0 commit comments

Comments
 (0)