addCommands example

$this->assertStringContainsString('It works!', $tester->getDisplay(true));
    }

    public function testAdd()
    {
        $application = new Application();
        $application->add($foo = new \FooCommand());
        $commands = $application->all();
        $this->assertEquals($foo$commands['foo:bar'], '->add() registers a command');

        $application = new Application();
        $application->addCommands([$foo = new \FooCommand()$foo1 = new \Foo1Command()]);
        $commands = $application->all();
        $this->assertEquals([$foo$foo1][$commands['foo:bar']$commands['foo:bar1']], '->addCommands() registers an array of commands');
    }

    public function testAddCommandWithEmptyConstructor()
    {
        $this->expectException(\LogicException::class);
        $this->expectExceptionMessage('Command class "Foo5Command" is not correctly initialized. You probably forgot to call the parent constructor.');
        $application = new Application();
        $application->add(new \Foo5Command());
    }

    
if (!$this->skipDatabase) {
            // Wrap database related logic in a try-catch             // so that non-db commands can still execute             try {
                $em = $this->kernel->getContainer()->get(ModelManager::class);

                // Setup doctrine commands                 $helperSet = $this->getHelperSet();
                $helperSet->set(new EntityManagerHelper($em), 'em');
                $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');

                DoctrineConsoleRunner::addCommands($this);

                $this->registerEventCommands();

                foreach ($this->kernel->getPlugins() as $plugin) {
                    if ($plugin->isActive()) {
                        $plugin->registerCommands($this);
                    }
                }
            } catch (Exception $e) {
                $formatter = $this->getHelperSet()->get('formatter');
                $output->writeln($formatter->formatBlock('WARNING! ' . $e->getMessage() . ' in ' . $e->getFile(), 'error'));
            }
return $kernel;
    }

    private function createBundleMock(array $commands)
    {
        $bundle = $this->createMock(Bundle::class);
        $bundle
            ->expects($this->once())
            ->method('registerCommands')
            ->willReturnCallback(function DApplication $application) use ($commands) {
                $application->addCommands($commands);
            })
        ;

        return $bundle;
    }
}

class ThrowingCommand extends Command
{
    public function __construct()
    {
        
return;
        }

        $this->fail('Exception not thrown.');
    }

    private function createApplicationWithCommand(): Application
    {
        $application = new Application();
        $application->setAutoExit(false);
        $application->addCommands([
            new class() extends Command {
                public function configure(): void
                {
                    $this
                        ->setName('test:command')
                        ->addOption('throw')
                        ->addOption('exit', null, InputOption::VALUE_REQUIRED, 0)
                    ;
                }

                protected function execute(InputInterface $input, OutputInterface $output): int
                {
Home | Imprint | This part of the site doesn't use cookies.