Repository: symfony/symfony
File: src/Symfony/Component/Console/Tests/ApplicationTest.php (PHP)

Code before:
                TestCase::assertSame($this->exitCode, $event->getExitCode());

                parent::onAlarm($event);
            }
        };

        $dispatcher = new EventDispatcher();
        $dispatcher->addSubscriber($subscriber1);
        $dispatcher->addSubscriber($subscriber2);

        $application = $this->createSignalableApplication($command, $dispatcher);

        $this->assertSame(1, $application->run(new ArrayInput(['signal'])));
        $this->assertSame([SignalEventSubscriber::class, AlarmEventSubscriber::class], $command->signalHandlers);
    }

    private function createSignalableApplication(Command $command, ?EventDispatcherInterface $dispatcher): Application
    {
        $application = new Application();
        $application->setAutoExit(false);
        if ($dispatcher) {
            $application->setDispatcher($dispatcher);
        }
        /** @var AsCommand $attribute */
        $attribute = (new \ReflectionClass($command))->getAttributes(AsCommand::class)[0]->newInstance();
        $application->add(new LazyCommand($attribute->name, [], '', false, fn () => $command, true));

        return $application;
    }
}

class CustomApplication extends Application
{
    /**
     * Overwrites the default input definition.
     */
    protected function getDefaultInputDefinition(): InputDefinition
    {
        return new InputDefinition([new InputOption('--custom', '-c', InputOption::VALUE_NONE, 'Set the custom input definition.')]);
    }

    /**
     * Gets the default helper set with the helpers that should always be available.
     */
    protected function getDefaultHelperSet(): HelperSet
    {
        return new HelperSet([new FormatterHelper()]);
    }
}

class CustomDefaultCommandApplication extends Application

Review comment (suggestion):
The command instance is already initialized, it can be used directly.
```suggestion
        $application->add(new LazyCommand($command->getName(), [], '', false, fn () => $command, true));
```

Code after:
                TestCase::assertSame($this->exitCode, $event->getExitCode());

                parent::onAlarm($event);
            }
        };

        $dispatcher = new EventDispatcher();
        $dispatcher->addSubscriber($subscriber1);
        $dispatcher->addSubscriber($subscriber2);

        $application = $this->createSignalableApplication($command, $dispatcher);

        $this->assertSame(1, $application->run(new ArrayInput(['signal'])));
        $this->assertSame([SignalEventSubscriber::class, AlarmEventSubscriber::class], $command->signalHandlers);
    }

    private function createSignalableApplication(Command $command, ?EventDispatcherInterface $dispatcher): Application
    {
        $application = new Application();
        $application->setAutoExit(false);
        if ($dispatcher) {
            $application->setDispatcher($dispatcher);
        }
        $application->add(new LazyCommand($command->getName(), [], '', false, fn () => $command, true));

        return $application;
    }
}

class CustomApplication extends Application
{
    /**
     * Overwrites the default input definition.
     */
    protected function getDefaultInputDefinition(): InputDefinition
    {
        return new InputDefinition([new InputOption('--custom', '-c', InputOption::VALUE_NONE, 'Set the custom input definition.')]);
    }

    /**
     * Gets the default helper set with the helpers that should always be available.
     */
    protected function getDefaultHelperSet(): HelperSet
    {
        return new HelperSet([new FormatterHelper()]);
    }
}

class CustomDefaultCommandApplication extends Application
{
    public function __construct()