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

Skip to content

Migrate commands to use AsCommand attribute #6850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Codeception/Command/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Codeception\Command;

use Codeception\Template\Bootstrap as BootstrapTemplate;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -24,11 +25,15 @@
* * `codecept bootstrap path/to/the/project` - provide different path to a project, where tests should be placed
*
*/
#[AsCommand(
name: 'bootstrap',
description: 'Creates default test suites and generates all required files'
)]
class Bootstrap extends Command
{
protected function configure(): void
{
$this->setDescription('Creates default test suites and generates all required files')
$this
->addArgument('path', InputArgument::OPTIONAL, 'custom installation dir')
->addOption('namespace', 's', InputOption::VALUE_OPTIONAL, 'Namespace to add for actor classes and helpers')
->addOption('actor', 'a', InputOption::VALUE_OPTIONAL, 'Custom actor instead of Tester')
Expand Down
10 changes: 5 additions & 5 deletions src/Codeception/Command/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Codeception\Configuration;
use Codeception\Lib\Generator\Actions as ActionsGenerator;
use Codeception\Lib\Generator\Actor as ActorGenerator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface as SymfonyOutputInterface;
Expand All @@ -21,6 +22,10 @@
* * `codecept build path/to/project`
*
*/
#[AsCommand(
name: 'build',
description: 'Generates base classes for all suites'
)]
class Build extends Command
{
use Shared\ConfigTrait;
Expand All @@ -30,11 +35,6 @@ class Build extends Command

protected ?SymfonyOutputInterface $output = null;

public function getDescription(): string
{
return 'Generates base classes for all suites';
}

protected function execute(InputInterface $input, SymfonyOutputInterface $output): int
{
$this->output = $output;
Expand Down
12 changes: 6 additions & 6 deletions src/Codeception/Command/Clean.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Codeception\Configuration;
use Codeception\Util\FileSystem;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -16,19 +17,18 @@
* * `codecept clean`
*
*/
#[AsCommand(
name: 'clean',
description: 'Recursively cleans log and generated code'
)]
class Clean extends Command
{
use Shared\ConfigTrait;

protected function configure(): void
{
$this->setDescription('Recursively cleans log and generated code');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->cleanProjectsRecursively($output, Configuration::projectDir());
$output->writeln("Done");
$output->writeln('Done');
return Command::SUCCESS;
}

Expand Down
16 changes: 7 additions & 9 deletions src/Codeception/Command/CompletionFallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@

namespace Codeception\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: '_completion',
description: 'BASH completion hook.',
hidden: true
)]
class CompletionFallback extends Command
{
public function __construct()
{
parent::__construct('_completion');
}

protected function configure(): void
{
$this
->setDescription('BASH completion hook.')
->setHidden(true) // Hide from listing
->setHelp(<<<END
$this->setHelp(<<<END
To enable BASH completion, install optional stecman/symfony-console-completion first:

<comment>composer require stecman/symfony-console-completion</comment>
Expand Down
10 changes: 6 additions & 4 deletions src/Codeception/Command/ConfigValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Codeception\Command;

use Codeception\Configuration;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -14,9 +15,6 @@
use function codecept_data_dir;
use function codecept_output_dir;
use function codecept_root_dir;
use function implode;
use function preg_replace;
use function print_r;

/**
* Validates and prints Codeception config.
Expand All @@ -39,14 +37,18 @@
* * `codecept config:validate -o "reporters: report: \Custom\Reporter" --report`: use custom reporter
*
*/
#[AsCommand(
name: 'config:validate',
description: 'Validates and prints Codeception config'
)]
class ConfigValidate extends Command
{
use Shared\ConfigTrait;
use Shared\StyleTrait;

protected function configure(): void
{
$this->setDescription('Validates and prints config to screen')
$this
->addArgument('suite', InputArgument::OPTIONAL, 'To show suite configuration')
->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Use custom path for config')
->addOption('override', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Override config values');
Expand Down
11 changes: 8 additions & 3 deletions src/Codeception/Command/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Codeception\SuiteManager;
use Codeception\Test\Cept;
use Codeception\Util\Debug;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -32,6 +33,10 @@
*
* * `codecept console acceptance` - starts acceptance suite environment. If you use WebDriver you can manipulate browser with Codeception commands.
*/
#[AsCommand(
name: 'console',
description: 'Launches interactive test console'
)]
class Console extends Command
{
protected ?Cept $test = null;
Expand All @@ -49,9 +54,9 @@ class Console extends Command

protected function configure(): void
{
$this->setDescription('Launches interactive test console')
$this
->addArgument('suite', InputArgument::REQUIRED, 'suite to be executed')
->addOption('colors', '', InputOption::VALUE_NONE, 'Use colors in output');
->addOption('colors', null, InputOption::VALUE_NONE, 'Use colors in output');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down Expand Up @@ -84,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->test = new Cept('', '');
$this->test->getMetadata()->setServices([
'dispatcher' => $eventDispatcher,
'modules' => $moduleContainer
'modules' => $moduleContainer,
]);

$scenario = new Scenario($this->test);
Expand Down
15 changes: 9 additions & 6 deletions src/Codeception/Command/DryRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use ReflectionMethod;
use ReflectionNamedType;
use ReflectionUnionType;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -42,19 +43,21 @@
* * `codecept dry-run tests/acceptance/MyCest.php`
*
*/
#[AsCommand(
name: 'dry-run',
description: 'Prints step-by-step scenario-driven test or a feature'
)]
class DryRun extends Command
{
use Shared\ConfigTrait;
use Shared\StyleTrait;

protected function configure(): void
{
$this->setDefinition(
[
new InputArgument('suite', InputArgument::REQUIRED, 'suite to scan for feature files'),
new InputArgument('test', InputArgument::OPTIONAL, 'tests to be loaded'),
]
);
$this->setDefinition([
new InputArgument('suite', InputArgument::REQUIRED, 'suite to scan for feature files'),
new InputArgument('test', InputArgument::OPTIONAL, 'tests to be loaded'),
]);
parent::configure();
}

Expand Down
7 changes: 6 additions & 1 deletion src/Codeception/Command/GenerateCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Codeception\Command;

use Codeception\Lib\Generator\Cest as CestGenerator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -21,14 +22,18 @@
* * `codecept g:cest "App\Login"`
*
*/
#[AsCommand(
name: 'generate:cest',
description: 'Generates empty Cest file in suite'
)]
class GenerateCest extends Command
{
use Shared\FileSystemTrait;
use Shared\ConfigTrait;

protected function configure(): void
{
$this->setDescription('Generates empty Cest file in suite')
$this
->addArgument('suite', InputArgument::REQUIRED, 'suite where tests will be put')
->addArgument('class', InputArgument::REQUIRED, 'test name');
}
Expand Down
8 changes: 6 additions & 2 deletions src/Codeception/Command/GenerateEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Codeception\Configuration;
use Codeception\Exception\ConfigurationException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -18,15 +19,18 @@
*
* Required to have `envs` path to be specified in `codeception.yml`
*/
#[AsCommand(
name: 'generate:environment',
description: 'Generates empty environment config'
)]
class GenerateEnvironment extends Command
{
use Shared\FileSystemTrait;
use Shared\ConfigTrait;

protected function configure(): void
{
$this->setDescription('Generates empty environment config')
->addArgument('env', InputArgument::REQUIRED, 'Environment name');
$this->addArgument('env', InputArgument::REQUIRED, 'Environment name');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
7 changes: 6 additions & 1 deletion src/Codeception/Command/GenerateFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Codeception\Command;

use Codeception\Lib\Generator\Feature;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -23,14 +24,18 @@
* * `codecept g:feature suite login.feature -c path/to/project`
*
*/
#[AsCommand(
name: 'generate:feature',
description: 'Generates empty feature file in suite'
)]
class GenerateFeature extends Command
{
use Shared\FileSystemTrait;
use Shared\ConfigTrait;

protected function configure(): void
{
$this->setDescription('Generates empty feature file in suite')
$this
->addArgument('suite', InputArgument::REQUIRED, 'suite to be tested')
->addArgument('feature', InputArgument::REQUIRED, 'feature to be generated')
->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Use custom path for config');
Expand Down
8 changes: 6 additions & 2 deletions src/Codeception/Command/GenerateGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Codeception\Configuration;
use Codeception\Lib\Generator\Group as GroupGenerator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -18,15 +19,18 @@
*
* * `codecept g:group Admin`
*/
#[AsCommand(
name: 'generate:groupobject',
description: 'Generates Group subscriber'
)]
class GenerateGroup extends Command
{
use Shared\FileSystemTrait;
use Shared\ConfigTrait;

protected function configure(): void
{
$this->setDescription('Generates Group subscriber')
->addArgument('group', InputArgument::REQUIRED, 'Group class name');
$this->addArgument('group', InputArgument::REQUIRED, 'Group class name');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
9 changes: 6 additions & 3 deletions src/Codeception/Command/GenerateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Codeception\Configuration;
use Codeception\Lib\Generator\Helper;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -18,17 +19,19 @@
*
* * `codecept g:helper MyHelper`
* * `codecept g:helper "My\Helper"`
*
*/
#[AsCommand(
name: 'generate:helper',
description: 'Generates a new helper'
)]
class GenerateHelper extends Command
{
use Shared\FileSystemTrait;
use Shared\ConfigTrait;

protected function configure(): void
{
$this->setDescription('Generates a new helper')
->addArgument('name', InputArgument::REQUIRED, 'Helper name');
$this->addArgument('name', InputArgument::REQUIRED, 'Helper name');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
Loading