MyCommand example


        $this->expectDeprecation('Since symfony/console 6.1: Relying on the static property "$defaultDescription" for setting a command description is deprecated. Add the "Symfony\Component\Console\Attribute\AsCommand" attribute to the "Symfony\Component\Console\Tests\Command\MyCommand" class instead.');

        $this->assertSame('This is a command I wrote all by myself', MyCommand::getDefaultDescription());
    }

    /** * @group legacy */
    public function testStaticDefaultProperties()
    {
        $command = new MyCommand();

        $this->assertSame('my:command', $command->getName());
        $this->assertSame('This is a command I wrote all by myself', $command->getDescription());
    }

    public function testAttributeOverridesProperty()
    {
        $this->assertSame('my:command', MyAnnotatedCommand::getDefaultName());
        $this->assertSame('This is a command I wrote all by myself', MyAnnotatedCommand::getDefaultDescription());

        $command = new MyAnnotatedCommand();

        
public function handleSignal(int $signal, int|false $previousExitCode = 0): int|false
    {
        echo "Received signal!";

        return 0;
    }
}

$app = new Application();
$app->setDispatcher(new \Symfony\Component\EventDispatcher\EventDispatcher());
$app->add(new MyCommand('foo'));

$app
    ->setDefaultCommand('foo', true)
    ->run()
;
--EXPECT--
Received signal!
Home | Imprint | This part of the site doesn't use cookies.