createDefaultContainer() public static method

Create a container and initiailze it. If you wish to *change* anything defined in the container, then you should call \Robo::configureContainer() instead of this function.
public static createDefaultContainer ( null | Symfony\Component\Console\Input\InputInterface $input = null, null | Symfony\Component\Console\Output\OutputInterface $output = null, null | Robo\Application $app = null, null | Robo\Config $config = null ) : League\Container\Container | League\Container\ContainerInterface
$input null | Symfony\Component\Console\Input\InputInterface
$output null | Symfony\Component\Console\Output\OutputInterface
$app null | Robo\Application
$config null | Robo\Config
return League\Container\Container | League\Container\ContainerInterface
示例#1
0
 protected function _before()
 {
     $container = Robo::createDefaultContainer();
     $this->app = $container->get('application');
     $config = $container->get('config');
     $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);
     }
 }
示例#2
0
 public function init($input, $output, $appName = null, $appVersion = null)
 {
     // If we were not provided a container, then create one
     if (!Robo::hasContainer()) {
         Robo::createDefaultContainer($input, $output, $appName, $appVersion);
         // Automatically register a shutdown function and
         // an error handler when we provide the container.
         $this->installRoboHandlers();
     }
     $app = Robo::application();
     $this->registerRoboFileCommands($app);
     return $app;
 }
示例#3
0
 public function testRunNativeAndExtraReporterConflict()
 {
     $container = \Robo\Robo::createDefaultContainer();
     \Robo\Robo::setContainer($container);
     $options = ['format' => 'stylish', 'lintReporters' => ['aKey' => new VerboseReporter()]];
     /** @var Task $task */
     $task = Stub::construct(Task::class, [$options, []], ['container' => $container]);
     $task->setLogger($container->get('logger'));
     $assetJar = new \Cheppers\AssetJar\AssetJar();
     $task->setAssetJar($assetJar);
     $result = $task->run();
     $this->assertEquals(3, $result->getExitCode());
     $this->assertEquals('Extra lint reporters can be used only if the output format is "json".', $result->getMessage());
 }
 /**
  * @param array $expected
  * @param array $options
  * @param array $properties
  *
  * @dataProvider casesRun
  */
 public function testRun(array $expected, array $options, array $files, array $properties = [])
 {
     $container = \Robo\Robo::createDefaultContainer();
     \Robo\Robo::setContainer($container);
     $mainStdOutput = new \Helper\Dummy\Output();
     $properties += ['processClass' => \Helper\Dummy\Process::class];
     /** @var \Cheppers\Robo\Phpcs\Task\PhpcsLintInput $task */
     $task = Stub::construct(PhpcsLintInput::class, [$options, []], $properties);
     $processIndex = count(\Helper\Dummy\Process::$instances);
     foreach ($files as $file) {
         \Helper\Dummy\Process::$prophecy[$processIndex] = ['exitCode' => $file['lintExitCode'], 'stdOutput' => $file['lintStdOutput']];
         $processIndex++;
     }
     $task->setLogger($container->get('logger'));
     $task->setOutput($mainStdOutput);
     $result = $task->run();
     $this->tester->assertEquals($expected['exitCode'], $result->getExitCode());
     /** @var \Cheppers\LintReport\ReportWrapperInterface $reportWrapper */
     $reportWrapper = $result['report'];
     $this->tester->assertEquals($expected['report'], $reportWrapper->getReport());
 }
 /**
  * @param int $exitCode
  * @param array $options
  * @param bool $withJar
  * @param string $expectedStdOutput
  *
  * @dataProvider casesRun
  */
 public function testRun($exitCode, $options, $withJar, $expectedStdOutput)
 {
     $container = \Robo\Robo::createDefaultContainer();
     \Robo\Robo::setContainer($container);
     $mainStdOutput = new \Helper\Dummy\Output();
     $options += ['workingDirectory' => '.', 'assetJarMapping' => ['report' => ['phpcsLintRun', 'report']], 'reports' => ['json' => null]];
     /** @var \Cheppers\Robo\Phpcs\Task\PhpcsLintFiles $task */
     $task = Stub::construct(PhpcsLintFiles::class, [$options, []], ['processClass' => \Helper\Dummy\Process::class, 'phpCodeSnifferCliClass' => \Helper\Dummy\PHP_CodeSniffer_CLI::class]);
     $processIndex = count(\Helper\Dummy\Process::$instances);
     \Helper\Dummy\Process::$prophecy[$processIndex] = ['exitCode' => $exitCode, 'stdOutput' => $expectedStdOutput];
     \Helper\Dummy\PHP_CodeSniffer_CLI::$numOfErrors = $exitCode ? 42 : 0;
     \Helper\Dummy\PHP_CodeSniffer_CLI::$stdOutput = $expectedStdOutput;
     $task->setLogger($container->get('logger'));
     $task->setOutput($mainStdOutput);
     $assetJar = null;
     if ($withJar) {
         $assetJar = new AssetJar();
         $task->setAssetJar($assetJar);
     }
     $result = $task->run();
     $this->tester->assertEquals($exitCode, $result->getExitCode(), 'Exit code is different than the expected.');
     $this->tester->assertEquals($options['workingDirectory'], \Helper\Dummy\Process::$instances[$processIndex]->getWorkingDirectory());
     if ($withJar) {
         /** @var \Cheppers\LintReport\ReportWrapperInterface $reportWrapper */
         $reportWrapper = $assetJar->getValue(['phpcsLintRun', 'report']);
         $this->tester->assertEquals(json_decode($expectedStdOutput, true), $reportWrapper->getReport(), 'Output equals');
     } else {
         $this->tester->assertContains($expectedStdOutput, $mainStdOutput->output, 'Output contains');
     }
 }
示例#6
0
文件: _bootstrap.php 项目: jjok/Robo
<?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 = Robo::createDefaultContainer();
示例#7
0
 /**
  * Object constructor
  *
  * @param \Pantheon\Terminus\Config $config
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 public function __construct(Config $config, InputInterface $input = null, OutputInterface $output = null)
 {
     $this->config = $config;
     $application = new Application('Terminus', $config->get('version'));
     $container = Robo::createDefaultContainer($input, $output, $application, $config);
     $this->configureContainer($container);
     $this->runner = new RoboRunner();
     $this->runner->setContainer($container);
     date_default_timezone_set($config->get('time_zone'));
 }
示例#8
0
文件: Runner.php 项目: jjok/Robo
 /**
  * @param null|\Symfony\Component\Console\Input\InputInterface $input
  * @param null|\Symfony\Component\Console\Output\OutputInterface $output
  * @param null|\Robo\Application $app
  * @param array[] $commandFiles
  *
  * @return int
  */
 public function run($input = null, $output = null, $app = null, $commandFiles = [])
 {
     // Create default input and output objects if they were not provided
     if (!$input) {
         $input = new StringInput('');
     }
     if (is_array($input)) {
         $input = new ArgvInput($input);
     }
     if (!$output) {
         $output = new \Symfony\Component\Console\Output\ConsoleOutput();
     }
     $this->setInput($input);
     $this->setOutput($output);
     // If we were not provided a container, then create one
     if (!$this->getContainer()) {
         $container = Robo::createDefaultContainer($input, $output, $app);
         $this->setContainer($container);
         // Automatically register a shutdown function and
         // an error handler when we provide the container.
         $this->installRoboHandlers();
     }
     if (!$app) {
         $app = Robo::application();
     }
     if (!isset($commandFiles)) {
         $this->yell("Robo is not initialized here. Please run `robo init` to create a new RoboFile", 40, 'yellow');
         $app->addInitRoboFileCommand($this->roboFile, $this->roboClass);
         $commandFiles = [];
     }
     $this->registerCommandClasses($app, $commandFiles);
     try {
         $statusCode = $app->run($input, $output);
     } catch (TaskExitException $e) {
         $statusCode = $e->getCode() ?: 1;
     }
     return $statusCode;
 }