制作控制台命令:
protected function execute(InputInterface $input, OutputInterface $output)
{
$consultations = $this->getContainer()->get('consultation.service')->setConsultationsCompleted();
if ($consultations) {
$output->writeln("=== Consultations has been completed ===");
} else {
$output->writeln("=== There are no overdue consulations ===");
}
foreach ($consultations as $consultation) {
$output->writeln($consultation->getId(), OutputInterface::VERBOSITY_VERBOSE);
}
}
并测试:
public function testExecute()
{
$this->application->add(new CompleteConsultationsCommand());
$consultations = $this->em->getRepository('ODConsultationBundle:Consultation')->findPastConsultations();
$command = $this->application->find('consultations:complete');
$commandTester = new CommandTester($command);
$commandTester->execute([
'command' => $command->getName(),
'--verbose' => true
]);
$output = $commandTester->getDisplay();
$this->assertContains('Consultations has been completed', $output);
$this->assertContains($consultations[0]->getId(), $output);
}
第二个断言不起作用。看不到这些信息。我做错了什么?
PS
$output->writeln($consultation->getId(), OutputInterface::VERBOSITY_VERBOSE);
如果没有--verbose
标记
答案 0 :(得分:2)
相反:
$commandTester->execute([
'command' => $command->getName(),
'--verbose' => true
]);
有必要使用:
$commandTester->execute([
'command' => $command->getName()
], [
'verbosity' => OutputInterface::VERBOSITY_VERBOSE
]);