IMPORTANT: after calling this method, clients MUST call:
$dispatcher = $container->get('eventDispatcher');
$app->setDispatcher($dispatcher);
Any modification to the container should be done prior to fetching
objects from it.
It is recommended to use \Robo::createDefaultContainer()
instead, which does all required setup for the caller, but has
the limitation that the container it creates can only be
extended, not modified.
public static configureContainer ( League\Container\ContainerInterface $container, |
||
$container | League\Container\ContainerInterface | |
$app | ||
$config | robo\Config | |
$input | null | Symfony\Component\Console\Input\InputInterface | |
$output | null | Symfony\Component\Console\Output\OutputInterface |
public function initSeeInOutputTrait($container, $input = null) { $this->capturedOutput = ''; $this->testPrinter = new BufferedOutput(OutputInterface::VERBOSITY_DEBUG); $app = Robo::createDefaultApplication(); $config = new \Robo\Config(); \Robo\Robo::configureContainer($container, $app, $config, $input, $this->testPrinter); // Set the application dispatcher $app->setDispatcher($container->get('eventDispatcher')); $this->logger = $container->get('logger'); }
public function initSeeInOutputTrait($container, $input = null) { $this->capturedOutput = ''; $this->testPrinter = new BufferedOutput(OutputInterface::VERBOSITY_DEBUG); $this->logger = new \Robo\Log\RoboLogger($this->testPrinter); $progressBar = new \Symfony\Component\Console\Helper\ProgressBar($this->testPrinter); \Robo\Robo::configureContainer($container, $input, $this->testPrinter); $container->add('output', $this->testPrinter); $container->add('progressBar', $progressBar); $container->add('progressIndicator', new \Robo\Common\ProgressIndicator($progressBar, $this->testPrinter)); }
protected function _before() { $container = new Container(); \Robo\Robo::configureContainer($container); \Robo\Robo::setContainer($container); $this->app = $container->get('application'); $this->commandFactory = $container->get('commandFactory'); $this->roboCommandFileInstance = new TestedRoboFile(); $builder = $container->get('collectionBuilder', [$this->roboCommandFileInstance]); $this->roboCommandFileInstance->setBuilder($builder); $commandList = $this->commandFactory->createCommandsFromClass($this->roboCommandFileInstance); foreach ($commandList as $command) { $this->app->add($command); } }
<?php // Here you can initialize variables that will for your tests use Robo\Robo; use Robo\Runner; use League\Container\Container; use Symfony\Component\Console\Input\StringInput; $container = new Container(); $input = new StringInput(''); Robo::configureContainer($container, $input); Robo::setContainer($container);