Ejemplo n.º 1
0
 protected function _before()
 {
     $progressBar = test::double('Symfony\\Component\\Console\\Helper\\ProgressBar');
     $nullOutput = new \Symfony\Component\Console\Output\NullOutput();
     $progressIndicator = new \Robo\Common\ProgressIndicator($progressBar, $nullOutput);
     $this->svn = test::double('Robo\\Task\\Vcs\\SvnStack', ['executeCommand' => new \AspectMock\Proxy\Anything(), 'output' => $nullOutput, 'logger' => new \Psr\Log\NullLogger(), 'logger' => Robo::logger(), 'getConfig' => Robo::config(), 'progressIndicator' => $progressIndicator]);
 }
Ejemplo n.º 2
0
 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');
 }
Ejemplo n.º 3
0
 /**
  * Sets static configuration, then runs task without working dir, with working dir and again without.
  */
 public function testWorkingDirectoryStaticConfiguration()
 {
     \Robo\Task\Remote\Ssh::configure('remoteDir', '/some-dir');
     verify((new \Robo\Task\Remote\Ssh('remote.example.com', 'user'))->setConfig(Robo::config())->exec('echo test')->getCommand())->equals("ssh user@remote.example.com 'cd \"/some-dir\" && echo test'");
     verify((new \Robo\Task\Remote\Ssh('remote.example.com', 'user'))->remoteDir('/other-dir')->exec('echo test')->getCommand())->equals("ssh user@remote.example.com 'cd \"/other-dir\" && echo test'");
     verify((new \Robo\Task\Remote\Ssh('remote.example.com', 'user'))->setConfig(Robo::config())->exec('echo test')->getCommand())->equals("ssh user@remote.example.com 'cd \"/some-dir\" && echo test'");
     \Robo\Task\Remote\Ssh::configure('remoteDir', null);
     verify((new \Robo\Task\Remote\Ssh('remote.example.com', 'user'))->exec('echo test')->getCommand())->equals("ssh user@remote.example.com 'echo test'");
 }
Ejemplo n.º 4
0
 /**
  * Provides direct access to the collection of temporaries, if necessary.
  */
 public static function getCollection()
 {
     if (!static::$collection) {
         static::$collection = \Robo\Robo::getContainer()->get('collection');
         register_shutdown_function(function () {
             static::complete();
         });
     }
     return static::$collection;
 }
Ejemplo n.º 5
0
 public function testDifferentTasksCanHaveSameConfigKeys()
 {
     ConfigurationTestTaskA::configure('key', 'value-a');
     ConfigurationTestTaskB::configure('key', 'value-b');
     $taskA = new ConfigurationTestTaskA();
     $taskA->setConfig(Robo::config());
     verify($taskA->run())->equals('value-a');
     $taskB = new ConfigurationTestTaskB();
     $taskB->setConfig(Robo::config());
     verify($taskB->run())->equals('value-b');
 }
Ejemplo n.º 6
0
 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');
 }
Ejemplo n.º 7
0
 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));
 }
Ejemplo n.º 8
0
 /**
  * @param string $roboFile
  * @param string $roboClass
  */
 public function addInitRoboFileCommand($roboFile, $roboClass)
 {
     $createRoboFile = new Command('init');
     $createRoboFile->setDescription("Intitalizes basic RoboFile in current dir");
     $createRoboFile->setCode(function () use($roboClass, $roboFile) {
         $output = Robo::output();
         $output->writeln("<comment>  ~~~ Welcome to Robo! ~~~~ </comment>");
         $output->writeln("<comment>  " . basename($roboFile) . " will be created in the current directory </comment>");
         file_put_contents($roboFile, '<?php' . "\n/**" . "\n * This is project's console commands configuration for Robo task runner." . "\n *" . "\n * @see http://robo.li/" . "\n */" . "\nclass " . $roboClass . " extends \\Robo\\Tasks\n{\n    // define public methods as commands\n}");
         $output->writeln("<comment>  Edit this file to add your commands! </comment>");
     });
     $this->add($createRoboFile);
 }
Ejemplo n.º 9
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);
     }
 }
Ejemplo n.º 10
0
Archivo: TaskIO.php Proyecto: jjok/Robo
 /**
  * @return mixed|null|\Psr\Log\LoggerInterface
  */
 public function logger()
 {
     // $this->logger should always be set in Robo core tasks.
     if ($this->logger) {
         return $this->logger;
     }
     // TODO: Remove call to Robo::logger() once maintaining backwards
     // compatibility with legacy external Robo tasks is no longer desired.
     if (!Robo::logger()) {
         return null;
     }
     static $gaveDeprecationWarning = false;
     if (!$gaveDeprecationWarning) {
         trigger_error('No logger set for ' . get_class($this) . '. Use $this->task(Foo::class) rather than new Foo() in loadTasks to ensure the builder can initialize task the task, or use $this->collectionBuilder()->taskFoo() if creating one task from within another.', E_USER_DEPRECATED);
         $gaveDeprecationWarning = true;
     }
     return Robo::logger();
 }
Ejemplo n.º 11
0
 /**
  * @deprecated
  */
 public static function configure($key, $value)
 {
     Robo::config()->set(static::getClassKey($key), $value);
 }
Ejemplo n.º 12
0
Archivo: Result.php Proyecto: jjok/Robo
 /**
  * @return $this
  */
 public function stopOnFail()
 {
     if (!$this->wasSuccessful()) {
         $resultPrinter = Robo::resultPrinter();
         if ($resultPrinter) {
             $resultPrinter->printStopOnFail($this);
         }
         $this->exitEarly($this->getExitCode());
     }
     return $this;
 }
Ejemplo n.º 13
0
 protected function _before()
 {
     $this->apigen = test::double('Robo\\Task\\ApiGen\\ApiGen', ['executeCommand' => null, 'output' => new \Symfony\Component\Console\Output\NullOutput(), 'logger' => new \Psr\Log\NullLogger()]);
     $this->container = Robo::getContainer();
 }
Ejemplo n.º 14
0
 protected function _before()
 {
     $this->dialog = new Symfony\Component\Console\Helper\QuestionHelper();
     $this->setOutput(Robo::service('output'));
 }
Ejemplo n.º 15
0
Archivo: Runner.php Proyecto: jjok/Robo
 /**
  * @param string|BuilderAwareInterface|ContainerAwareInterface  $commandClass
  *
  * @return null|object
  */
 protected function instantiateCommandClass($commandClass)
 {
     $container = Robo::getContainer();
     // Register the RoboFile with the container and then immediately
     // fetch it; this ensures that all of the inflectors will run.
     // If the command class is already an instantiated object, then
     // just use it exactly as it was provided to us.
     if (is_string($commandClass)) {
         $reflectionClass = new \ReflectionClass($commandClass);
         if ($reflectionClass->isAbstract()) {
             return;
         }
         $commandFileName = "{$commandClass}Commands";
         $container->share($commandFileName, $commandClass);
         $commandClass = $container->get($commandFileName);
     }
     // If the command class is a Builder Aware Interface, then
     // ensure that it has a builder.  Every command class needs
     // its own collection builder, as they have references to each other.
     if ($commandClass instanceof BuilderAwareInterface) {
         $builder = $container->get('collectionBuilder', [$commandClass]);
         $commandClass->setBuilder($builder);
     }
     if ($commandClass instanceof ContainerAwareInterface) {
         $commandClass->setContainer($container);
     }
     return $commandClass;
 }
Ejemplo n.º 16
0
 /**
  * Description
  * @param $options
  * @option delay Miliseconds delay
  * @return type
  */
 public function tryProgress($options = ['delay' => 500])
 {
     $delay = $options['delay'];
     $delayUntilProgressStart = \Robo\Robo::config()->get(\Robo\Config::PROGRESS_BAR_AUTO_DISPLAY_INTERVAL);
     $this->say("Progress bar will display after {$delayUntilProgressStart} seconds of activity.");
     $processList = range(1, 10);
     return $this->collectionBuilder()->taskForEach($processList)->iterationMessage('Processing {value}')->call(function ($value) use($delay) {
         // TaskForEach::call should only be used to do
         // non-Robo operations. To use Robo tasks in an
         // iterator, @see TaskForEach::withBuilder.
         usleep($delay * 1000);
         // delay units: msec, usleep units: usec
     })->run();
 }
Ejemplo n.º 17
0
 public function _before(\Codeception\TestCase $test)
 {
     static::$container = new \League\Container\Container();
     Robo::setContainer(static::$container);
     $this->initSeeInOutputTrait(static::$container);
 }
Ejemplo n.º 18
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());
 }
Ejemplo n.º 19
0
 /**
  * @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());
 }
Ejemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->printTaskInfo('Running command {command}', ['command' => $this->command->getName()]);
     return new Result($this, $this->command->run(new ArrayInput($this->input), Robo::output()));
 }
Ejemplo n.º 21
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);
Ejemplo n.º 22
0
 public function testTasksStopOnFail()
 {
     $argv = ['placeholder', 'test:stop-on-fail'];
     $result = $this->runner->execute($argv, Robo::output());
     $this->guy->seeInOutput('[');
     $this->assertTrue($result > 0);
 }
Ejemplo n.º 23
0
 public function testInitCommand()
 {
     $container = \Robo\Robo::getContainer();
     $app = $container->get('application');
     $app->addInitRoboFileCommand(getcwd() . '/testRoboFile.php', 'RoboTestClass');
     $argv = ['placeholder', 'init'];
     $status = $this->runner->run($argv, $this->guy->capturedOutputStream(), $app);
     $this->guy->seeInOutput('testRoboFile.php will be created in the current directory');
     $this->assertEquals(0, $status);
     $this->assertTrue(file_exists('testRoboFile.php'));
     $commandContents = file_get_contents('testRoboFile.php');
     unlink('testRoboFile.php');
     $this->assertContains('class RoboTestClass', $commandContents);
 }
Ejemplo n.º 24
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 = Robo::createDefaultContainer();
Ejemplo n.º 25
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'));
 }
Ejemplo n.º 26
0
 protected function instantiateCommandClass($commandClass)
 {
     $container = Robo::getContainer();
     // Register the RoboFile with the container and then immediately
     // fetch it; this ensures that all of the inflectors will run.
     $commandFileName = "{$commandClass}Commands";
     $container->share($commandFileName, $commandClass);
     $roboCommandFileInstance = $container->get($commandFileName);
     if ($roboCommandFileInstance instanceof BuilderAwareInterface) {
         $builder = $container->get('collectionBuilder', [$roboCommandFileInstance]);
         $roboCommandFileInstance->setBuilder($builder);
     }
     return $roboCommandFileInstance;
 }
Ejemplo n.º 27
0
 /**
  * @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');
     }
 }