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]); }
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'); }
/** * 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'"); }
/** * 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; }
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'); }
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)); }
/** * @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); }
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); } }
/** * @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(); }
/** * @deprecated */ public static function configure($key, $value) { Robo::config()->set(static::getClassKey($key), $value); }
/** * @return $this */ public function stopOnFail() { if (!$this->wasSuccessful()) { $resultPrinter = Robo::resultPrinter(); if ($resultPrinter) { $resultPrinter->printStopOnFail($this); } $this->exitEarly($this->getExitCode()); } return $this; }
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(); }
protected function _before() { $this->dialog = new Symfony\Component\Console\Helper\QuestionHelper(); $this->setOutput(Robo::service('output')); }
/** * @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; }
/** * 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(); }
public function _before(\Codeception\TestCase $test) { static::$container = new \League\Container\Container(); Robo::setContainer(static::$container); $this->initSeeInOutputTrait(static::$container); }
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()); }
/** * {@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())); }
<?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);
public function testTasksStopOnFail() { $argv = ['placeholder', 'test:stop-on-fail']; $result = $this->runner->execute($argv, Robo::output()); $this->guy->seeInOutput('['); $this->assertTrue($result > 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); }
<?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();
/** * 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')); }
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; }
/** * @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'); } }