/** * Check command execute. */ public function testExecute() { // Parameter was not set, so it has no value. $this->commandTester->execute(['command' => $this->command->getName(), 'parameter' => 'test1']); $this->assertContains('Parameter `test1`: has no value.', $this->commandTester->getDisplay()); $this->assertContains('If you want to write new value, use --set="<new value>" option.', $this->commandTester->getDisplay()); // Set some value, and test if it was set and returned. $value = '2014-01-01 01:01:01'; $this->commandTester->execute(['command' => $this->command->getName(), 'parameter' => 'test1', '--set' => $value]); $this->assertContains('New value written:', $this->commandTester->getDisplay()); /** @var Repository $repo */ $repo = $this->manager->getRepository('ONGRConnectionsBundle:Pair'); $parameter = $repo->find('test1'); $this->assertEquals($value, $parameter->getValue()); }
/** * @param ContainerAwareCommand $command A ContainerAwareCommand instance to test * @param ContainerInterface $container The container to be injected in the command to test */ public function __construct(ContainerAwareCommand $command, ContainerInterface $container) { $application = new Application('Paraunit Command Test: ' . $command->getName()); $application->add($command); $this->container = $container; $command->setContainer($container); parent::__construct($command); }