setContainer() public static method

Sets a new global container.
public static setContainer ( League\Container\ContainerInterface $container )
$container League\Container\ContainerInterface A new container instance to replace the current.
示例#1
0
文件: CliHelper.php 项目: jjok/Robo
 public function _before(\Codeception\TestCase $test)
 {
     $container = new \League\Container\Container();
     $this->initSeeInOutputTrait($container);
     Robo::setContainer($container);
     $this->setContainer($container);
     $this->getModule('Filesystem')->copyDir(codecept_data_dir() . 'claypit', codecept_data_dir() . 'sandbox');
 }
示例#2
0
 /**
  * Class Constructor
  * @param null $roboClass
  * @param null $roboFile
  */
 public function __construct($roboClass = null, $roboFile = null, $container = null)
 {
     // set the const as class properties to allow overwriting in child classes
     $this->roboClass = $roboClass ? $roboClass : self::ROBOCLASS;
     $this->roboFile = $roboFile ? $roboFile : self::ROBOFILE;
     $this->dir = getcwd();
     // Store the container in our config object if it was provided.
     if ($container != null) {
         Robo::setContainer($container);
     }
 }
示例#3
0
 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);
     }
 }
示例#4
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());
 }
示例#5
0
文件: CodeHelper.php 项目: jjok/Robo
 public function _before(\Codeception\TestCase $test)
 {
     static::$container = new \League\Container\Container();
     Robo::setContainer(static::$container);
     $this->initSeeInOutputTrait(static::$container);
 }
 /**
  * @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');
     }
 }
示例#8
0
<?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);