여기에 설명 된대로 CommandTester
을 사용하여 심포니 명령을 테스트하고 싶습니다. http://symfony.com/doc/2.3/components/console/introduction.html#testing-commands.symfony 명령 테스트가 작동하지 않습니다.
테스트하려는 명령은 decision
이 true로 설정된 레코드를 제거합니다. (아래의 코드에서 자세히) 검사가 실패하더라도
public function testMyCommand()
{
// .....
// Updating the database
$res = $this->client->getContainer()->get('doctrine.orm.entity_manager')->createQueryBuilder()
->update('MyBundle:MyEntity', 'me')
->set('me.decision', true)
->where('me.id = :id')
->setParameter('id', 4);
// The command is meant to seek for all entities having *decision* set to true and delete them
$application = new Application($this->client->getKernel());
$application->add(new CronQuotidienCommand());
$command = $application->find('myproject:mycmd');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));
$this->assertEmpty($this->client->getContainer()->get('doctrine')->getRepository('MyBundle:MyEntity')->findBy(array('decision' => true));
}
은 $commandTester->execute(array('command' => $command->getName()));
어떤 MyEntity
와을 찾지 못했음을 의미 true
에 열 decision
세트와, 그 ID 4에 해당 한 MyEntity
, 거기 decision
을 true
(referesh matter?)으로 설정하십시오. 내가
shell_exec('php ' . $this->container->get('kernel')->getRootDir() . '/console myproject:mycmd');
이 작업을 수행하여
$application = new Application($this->client->getKernel());
$application->add(new CronQuotidienCommand());
$command = $application->find('myproject:mycmd');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));
를 교체 할 때
놀라운
입니다.아이디어가 있으십니까? 당신은 시도 들으
1)'$ 입술 = ....-> setParameter를 ('아이디', 4)',하지만 어디 thats 쿼리 실행입니까? 2) 당신은 $ em-> ur 명령에 변경이있을 때 호출되는 플러시입니까? 3) 이러한 기능 테스트는 시간 낭비이며, 단위 테스트를 선호한다. 4) shell_exec은 거의 항상 나쁜 생각이다. – Ziumin