addOption(new InputOption('verbose', 'v', InputOption::VALUE_NONE, 'Verbose option')); $input = new ArrayInput(['--verbose' => true], $inputDefinition); $output = new BufferedOutput(); $application = $this->createMock(Application::class); $application->expects(self::once()) ->method('doRun') ->willReturnCallback(static function (ArrayInput $newInput, OutputInterface $output) { self::assertSame('foo --verbose=1', (string) $newInput); $output->writeln('command output here'); return 0; }); $command = $this->createMock(Command::class); $command->method('getApplication')->willReturn($application); $invoker = new InvokeSubCommand($output); self::assertSame(0, ($invoker)($command, ['command' => 'foo'], $input)); self::assertSame('command output here', trim($output->fetch())); } public function testInvokeWithPrefixOutputFormatterRunsSubCommand(): void { $inputDefinition = new InputDefinition(); $inputDefinition->addOption(new InputOption('verbose', 'v', InputOption::VALUE_NONE, 'Verbose option')); $input = new ArrayInput(['--verbose' => true], $inputDefinition); $output = new BufferedOutput(); $application = $this->createMock(Application::class); $application->expects(self::once()) ->method('doRun') ->willReturnCallback(static function (ArrayInput $newInput, OutputInterface $output) { self::assertSame('foo --verbose=1', (string) $newInput); $output->writeln('command output here'); return 0; }); $command = $this->createMock(Command::class); $command->method('getApplication')->willReturn($application); $invoker = new InvokeSubCommand($output); self::assertSame(0, ($invoker)($command, ['command' => 'foo'], $input, new OutputFormatterWithPrefix('prefix> '))); self::assertSame('prefix> command output here', trim($output->fetch())); } }