Skip to content

Commit

Permalink
Use AsCommand attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
grizzm0 committed Sep 10, 2024
1 parent b011bfd commit 0ff9815
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"psr/http-message-implementation": "^1.0 || ^2.0",
"psr/http-server-handler": "^1.0.2",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/console": "^5.0 || ^6.0.19 || ^7.0",
"symfony/console": "^5.3 || ^6.0.19 || ^7.0",
"webmozart/assert": "^1.11"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions src/Command/ReloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Mezzio\Swoole\Command;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -19,6 +20,7 @@

use const SWOOLE_PROCESS;

#[AsCommand('mezzio:swoole:reload')]
class ReloadCommand extends Command
{
/**
Expand All @@ -33,9 +35,6 @@ class ReloadCommand extends Command
configuration value is set to SWOOLE_PROCESS.
EOH;

/** @var null|string Cannot be defined explicitly due to parent class */
public static $defaultName = 'mezzio:swoole:reload';

public function __construct(private int $serverMode)
{
parent::__construct();
Expand Down Expand Up @@ -73,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @var Application $application */
$application = $this->getApplication();

$stop = $application->find(StopCommand::$defaultName);
$stop = $application->find(StopCommand::getDefaultName());
$result = $stop->run(new ArrayInput([
'command' => 'stop',
]), $output);
Expand All @@ -92,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('<info>[DONE]</info>');
$output->writeln('<info>Starting server</info>');

$start = $application->find(StartCommand::$defaultName);
$start = $application->find(StartCommand::getDefaultName());

$inputArguments = [
'command' => 'start',
Expand Down
5 changes: 2 additions & 3 deletions src/Command/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
use Mezzio\Swoole\PidManager;
use Psr\Container\ContainerInterface;
use Swoole\Http\Server as SwooleHttpServer;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function file_exists;

#[AsCommand('mezzio:swoole:start')]
class StartCommand extends Command
{
use IsRunningTrait;
Expand Down Expand Up @@ -51,9 +53,6 @@ class StartCommand extends Command
'config/routes.php',
];

/** @var null|string Cannot be defined explicitly due to parent class */
public static $defaultName = 'mezzio:swoole:start';

public function __construct(private ContainerInterface $container)
{
parent::__construct();
Expand Down
5 changes: 2 additions & 3 deletions src/Command/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
namespace Mezzio\Swoole\Command;

use Mezzio\Swoole\PidManager;
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('mezzio:swoole:status')]
class StatusCommand extends Command
{
use IsRunningTrait;
Expand All @@ -27,9 +29,6 @@ class StatusCommand extends Command
--daemonize option.
EOH;

/** @var null|string Cannot be defined explicitly due to parent class */
public static $defaultName = 'mezzio:swoole:status';

public function __construct(private PidManager $pidManager)
{
parent::__construct();
Expand Down
5 changes: 2 additions & 3 deletions src/Command/StopCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
use Closure;
use Mezzio\Swoole\PidManager;
use Swoole\Process as SwooleProcess;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use function time;
use function usleep;

#[AsCommand('mezzio:swoole:stop')]
class StopCommand extends Command
{
use IsRunningTrait;
Expand All @@ -32,9 +34,6 @@ class StopCommand extends Command
--daemonize option.
EOH;

/** @var null|string Cannot be defined explicitly due to parent class */
public static $defaultName = 'mezzio:swoole:stop';

/**
* @internal
*
Expand Down
10 changes: 5 additions & 5 deletions test/Command/ReloadCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function testExecuteEndsWithErrorWhenStopCommandFails(): void
->willReturn(1);

$application = $this->mockApplication();
$application->method('find')->with(StopCommand::$defaultName)->willReturn($stopCommand);
$application->method('find')->with(StopCommand::getDefaultName())->willReturn($stopCommand);

$command->setApplication($application);

Expand Down Expand Up @@ -200,8 +200,8 @@ public function testExecuteEndsWithErrorWhenStartCommandFails(): void
->expects($this->exactly(2))
->method('find')
->willReturnMap([
[StopCommand::$defaultName, $stopCommand],
[StartCommand::$defaultName, $startCommand],
[StopCommand::getDefaultName(), $stopCommand],
[StartCommand::getDefaultName(), $startCommand],
]);

$command->setApplication($application);
Expand Down Expand Up @@ -270,8 +270,8 @@ public function testExecuteEndsWithSuccessWhenBothStopAndStartCommandsSucceed():
->expects($this->exactly(2))
->method('find')
->willReturnMap([
[StopCommand::$defaultName, $stopCommand],
[StartCommand::$defaultName, $startCommand],
[StopCommand::getDefaultName(), $stopCommand],
[StartCommand::getDefaultName(), $startCommand],
]);

$this->output
Expand Down

0 comments on commit 0ff9815

Please sign in to comment.