【发布时间】:2017-06-15 14:29:33
【问题描述】:
制作控制台命令:
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);
}
第二个断言不起作用。看不到资料。我做错了什么?
附言
$output->writeln($consultation->getId(), OutputInterface::VERBOSITY_VERBOSE); 没有--verbose 标志,此行不显示此信息
【问题讨论】:
标签: php symfony console phpunit