diff --git a/.travis.yml b/.travis.yml index f62a31285..1372eb855 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.4 - 5.5 - 5.6 - 7.0 diff --git a/RoboFile.php b/RoboFile.php index 65ad92974..5c5835ec7 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -346,4 +346,44 @@ public function trySuccess() { $result = $this->taskExec('pwd')->run(); } + + public function tryDeprecated() + { + $result = (new \Robo\Task\Base\Exec('pwd'))->run(); + } + + public function tryTmpDir() + { + // Set up a collection to add tasks to + $collection = $this->collection(); + + // Get a temporary directory to work in. Note that we get a + // name back, but the directory is not created until the task + // runs. This technically is not thread-safe, but we create + // a random name, so it is unlikely to conflict. + $tmpPath = $this->taskTmpDir() + ->addToCollection($collection) + ->getPath(); + + // We can create the temporary directory early by running + // 'runWithoutCompletion()'. n.b. if we called 'run()' at + // this point, the collection's 'complete()' method would be + // called, and the temporary directory would be deleted. + $mktmpResult = $collection->runWithoutCompletion(); + + if (is_dir($tmpPath)) { + $this->say("Created a temporary directory at $tmpPath"); + } else { + $this->say("Requested a temporary directory at $tmpPath, but it was not created"); + } + + // Run the task collection + $result = $collection->run(); + + if (is_dir($tmpPath)) { + $this->say("The temporary directory at $tmpPath was not cleaned up after the collection completed."); + } else { + $this->say("The temporary directory at $tmpPath was automatically deleted."); + } + } } diff --git a/composer.json b/composer.json index a3419ab2d..cdfaa91c6 100644 --- a/composer.json +++ b/composer.json @@ -15,13 +15,13 @@ }, "bin":["robo"], "require": { - "php": ">=5.4.0", + "php": ">=5.5.0", "consolidation/log": "~0", "symfony/finder": "~2.5|~3.0", "symfony/console": "~2.5|~3.0", "symfony/process": "~2.5|~3.0", "symfony/filesystem": "~2.5|~3.0", - "symfony/dependency-injection": "~2.5|~3.0" + "league/container": "~2.2" }, "require-dev": { "patchwork/jsqueeze": "~1.0", diff --git a/composer.lock b/composer.lock index ca47aabdb..8b5445a2c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,21 +4,21 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "639edf71f57e4b9a659504e18b7ea936", - "content-hash": "095fcad6e6cc71bd0490894aff92bffd", + "hash": "144b0cbc221523a48a63dab2017a27cf", + "content-hash": "607979e772abdfbc17aa7bff75f0b476", "packages": [ { "name": "consolidation/log", - "version": "0.1.2", + "version": "0.1.3", "source": { "type": "git", "url": "https://github.com/consolidation-org/log.git", - "reference": "35f6c653037de312f0d8834c9f0dd41f2ff76ebf" + "reference": "9db36693a66f02ab315ecf4447d4fe1bfefc4e5c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/consolidation-org/log/zipball/35f6c653037de312f0d8834c9f0dd41f2ff76ebf", - "reference": "35f6c653037de312f0d8834c9f0dd41f2ff76ebf", + "url": "https://api.github.com/repos/consolidation-org/log/zipball/9db36693a66f02ab315ecf4447d4fe1bfefc4e5c", + "reference": "9db36693a66f02ab315ecf4447d4fe1bfefc4e5c", "shasum": "" }, "require": { @@ -56,7 +56,98 @@ } ], "description": "Improved Psr-3 / Psr\\Log logger based on Symfony Console components.", - "time": "2016-03-05 06:42:28" + "time": "2016-03-07 01:12:40" + }, + { + "name": "container-interop/container-interop", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/container-interop/container-interop.git", + "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/container-interop/container-interop/zipball/fc08354828f8fd3245f77a66b9e23a6bca48297e", + "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Interop\\Container\\": "src/Interop/Container/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", + "time": "2014-12-30 15:22:37" + }, + { + "name": "league/container", + "version": "2.2.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/container.git", + "reference": "c0e7d947b690891f700dc4967ead7bdb3d6708c1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/container/zipball/c0e7d947b690891f700dc4967ead7bdb3d6708c1", + "reference": "c0e7d947b690891f700dc4967ead7bdb3d6708c1", + "shasum": "" + }, + "require": { + "container-interop/container-interop": "^1.1", + "php": ">=5.4.0" + }, + "provide": { + "container-interop/container-interop-implementation": "^1.1" + }, + "replace": { + "orno/di": "~2.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev", + "dev-1.x": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Container\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Phil Bennett", + "email": "philipobenito@gmail.com", + "homepage": "http://www.philipobenito.com", + "role": "Developer" + } + ], + "description": "A fast and intuitive dependency injection container.", + "homepage": "https://github.com/thephpleague/container", + "keywords": [ + "container", + "dependency", + "di", + "injection", + "league", + "provider", + "service" + ], + "time": "2016-03-17 11:07:59" }, { "name": "psr/log", @@ -368,7 +459,7 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.1.0", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", @@ -1737,16 +1828,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.8.23", + "version": "4.8.24", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "6e351261f9cd33daf205a131a1ba61c6d33bd483" + "reference": "a1066c562c52900a142a0e2bbf0582994671385e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6e351261f9cd33daf205a131a1ba61c6d33bd483", - "reference": "6e351261f9cd33daf205a131a1ba61c6d33bd483", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a1066c562c52900a142a0e2bbf0582994671385e", + "reference": "a1066c562c52900a142a0e2bbf0582994671385e", "shasum": "" }, "require": { @@ -1805,7 +1896,7 @@ "testing", "xunit" ], - "time": "2016-02-11 14:56:33" + "time": "2016-03-14 06:16:08" }, { "name": "phpunit/phpunit-mock-objects", @@ -2565,7 +2656,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.4.0" + "php": ">=5.5.0" }, "platform-dev": [] } diff --git a/src/Application.php b/src/Application.php index ad6356869..44b500a32 100644 --- a/src/Application.php +++ b/src/Application.php @@ -7,20 +7,40 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; -class Application extends SymfonyApplication +use League\Container\ContainerAwareInterface; +use League\Container\ContainerAwareTrait; + +class Application extends SymfonyApplication implements ContainerAwareInterface { + use ContainerAwareTrait; + + public function __construct($name, $version) + { + parent::__construct($name, $version); + + $this->getDefinition()->addOption( + new InputOption('--simulate', null, InputOption::VALUE_NONE, 'Run in simulated mode (show what would have happened).') + ); + } public function addCommandsFromClass($className, $passThrough = null) { + $container = $this->getContainer(); $roboTasks = new $className; + if ($roboTasks instanceof ContainerAwareInterface) { + $roboTasks->setContainer($container); + } - $commandNames = array_filter(get_class_methods($className), function($m) { - return !in_array($m, ['__construct']); + // Ignore special functions, such as __construct() and __call(), and + // accessor methods such as getFoo() and setFoo(), while allowing + // set or setup. + $commandNames = array_filter(get_class_methods($className), function ($m) { + return !preg_match('#^(_|get[A-Z]|set[A-Z])#', $m); }); foreach ($commandNames as $commandName) { $command = $this->createCommand(new TaskInfo($className, $commandName)); - $command->setCode(function(InputInterface $input) use ($roboTasks, $commandName, $passThrough) { + $command->setCode(function (InputInterface $input) use ($roboTasks, $commandName, $passThrough, $container) { // get passthru args $args = $input->getArguments(); array_shift($args); @@ -28,6 +48,10 @@ public function addCommandsFromClass($className, $passThrough = null) $args[key(array_slice($args, -1, 1, TRUE))] = $passThrough; } $args[] = $input->getOptions(); + // Need a better way to handle global options + // Also, this is not necessarily the best place to do this + Config::setGlobalOptions($input); + $container->setSimulated(Config::isSimulated()); $res = call_user_func_array([$roboTasks, $commandName], $args); if (is_int($res)) exit($res); @@ -97,4 +121,4 @@ public function addInitRoboFileCommand($roboFile, $roboClass) }); $this->add($createRoboFile); } -} \ No newline at end of file +} diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php index 56675bf3c..94a2a9e5c 100644 --- a/src/Collection/Collection.php +++ b/src/Collection/Collection.php @@ -3,6 +3,10 @@ use Robo\Result; use Robo\Contract\TaskInterface; +use Robo\Container\SimpleServiceProvider; + +use League\Container\ContainerAwareInterface; +use League\Container\ContainerAwareTrait; /** * Group tasks into a collection that run together. Supports @@ -30,8 +34,10 @@ * ?> * ``` */ -class Collection implements TaskInterface +class Collection implements TaskInterface, ContainerAwareInterface { + use ContainerAwareTrait; + // Unnamed tasks are assigned an arbitrary numeric index // in the task list. Any numeric value may be used, but the // UNNAMEDTASK constant is recommended for clarity. @@ -42,6 +48,19 @@ class Collection implements TaskInterface protected $completionStack = []; protected $previousResult; + /** + * Return services. + */ + public static function getCollectionServices() + { + return new SimpleServiceProvider( + [ + 'collection' => Collection::class, + 'completionWrapper' => CompletionWrapper::class, + ] + ); + } + /** * Constructor. */ @@ -274,7 +293,8 @@ protected function addTask($name, $task) { // Wrap the task as necessary. $task = $this->wrapTask($task); - $this->addToTaskStack($name, new TaskWrapper($this, $task)); + $task = $this->getContainer()->get('completionWrapper', [$this, $task]); + $this->addToTaskStack($name, $task); return $this; } diff --git a/src/Collection/TaskWrapper.php b/src/Collection/CompletionWrapper.php similarity index 74% rename from src/Collection/TaskWrapper.php rename to src/Collection/CompletionWrapper.php index a9187836f..a395ca8e4 100644 --- a/src/Collection/TaskWrapper.php +++ b/src/Collection/CompletionWrapper.php @@ -6,45 +6,46 @@ use Robo\Contract\TaskInterface; use Robo\Contract\RollbackInterface; use Robo\Contract\CompletionInterface; +use Robo\Contract\WrappedTaskInterface; /** * Creates a task wrapper that will manage rollback and collection * management to a task when it runs. Tasks are automatically - * wrapped in a TaskWrapper when added to a task collection. + * wrapped in a CompletionWrapper when added to a task collection. * - * Clients may need to wrap their task in a TaskWrapper if it + * Clients may need to wrap their task in a CompletionWrapper if it * creates temporary objects. This is usually best done via * Temporary::wrap(). * * @see Robo\Task\FileSystem\loadTasks::taskTmpDir */ -class TaskWrapper extends BaseTask +class CompletionWrapper extends BaseTask implements WrappedTaskInterface { private $collection; private $task; private $rollbackTask; /** - * Create a TaskWrapper. + * Create a CompletionWrapper. * - * Temporary tasks are always wrapped in a TaskWrapper, as are + * Temporary tasks are always wrapped in a CompletionWrapper, as are * any tasks that are added to a collection. If a temporary task * is added to a collection, then it is first unwrapped from its - * TaskWrapper (via its getTask method), and then added to a - * new TaskWrapper for the collection it is added to. + * CompletionWrapper (via its original() method), and then added to a + * new CompletionWrapper for the collection it is added to. * - * In this way, when the TaskWrapper is finally executed, the + * In this way, when the CompletionWrapper is finally executed, the * task's rollback and completion handlers will be registered on * whichever collection it was registered on. */ public function __construct(Collection $collection, TaskInterface $task, TaskInterface $rollbackTask = null) { $this->collection = $collection; - $this->task = ($task instanceof self) ? $task->getTask() : $task; + $this->task = ($task instanceof WrappedTaskInterface) ? $task->original() : $task; $this->rollbackTask = $rollbackTask; } - public function getTask() + public function original() { return $this->task; } diff --git a/src/Collection/ServiceProvider.php b/src/Collection/ServiceProvider.php new file mode 100644 index 000000000..9f7395793 --- /dev/null +++ b/src/Collection/ServiceProvider.php @@ -0,0 +1,17 @@ + Collection::class, + 'completionWrapper' => CompletionWrapper::class, + ] + ); + } +} diff --git a/src/Collection/Temporary.php b/src/Collection/Temporary.php index 9a93f4d79..633baa829 100644 --- a/src/Collection/Temporary.php +++ b/src/Collection/Temporary.php @@ -35,7 +35,7 @@ class Temporary public static function getCollection() { if (!static::$collection) { - static::$collection = new Collection(); + static::$collection = \Robo\Config::getContainer()->get('collection'); register_shutdown_function(function () { static::complete(); }); @@ -44,17 +44,6 @@ public static function getCollection() return static::$collection; } - /** - * Wrap the given task in a wrapper class that will ensure - * that its 'complete()' function is called when the program - * terminates, if not sooner (e.g. if the task is added to - * some other collection). - */ - public static function wrap(TaskInterface $task) - { - return new TaskWrapper(static::getCollection(), $task); - } - /** * Call the rollback method of all of the registered objects. */ diff --git a/src/Collection/loadTasks.php b/src/Collection/loadTasks.php deleted file mode 100644 index 3d3ff23cf..000000000 --- a/src/Collection/loadTasks.php +++ /dev/null @@ -1,14 +0,0 @@ -logger will always be set in Robo core tasks. + // TODO: Remove call to Config::logger() once maintaining backwards + // compatibility with legacy external Robo tasks is no longer desired. + if (!$this->logger) { + if (!static::$gaveDeprecationWarning) { + trigger_error('No logger set for ' . get_class($this) . '. Use $this->task("Foo") rather than new Foo() in loadTasks to ensure the DI container can initialize tasks.', E_USER_DEPRECATED); + static::$gaveDeprecationWarning = true; + } + return Config::logger(); + } + return $this->logger; + } + /** * Print information about a task in progress. * @@ -31,7 +52,7 @@ protected function printTaskInfo($text, $context = null) // The 'note' style is used for both 'notice' and 'info' log levels; // However, 'notice' is printed at VERBOSITY_NORMAL, whereas 'info' // is only printed at VERBOSITY_VERBOSE. - Config::logger()->notice($text, $this->getTaskContext($context)); + $this->logger()->notice($text, $this->getTaskContext($context)); } /** @@ -48,7 +69,7 @@ protected function printTaskSuccess($text, $context = null) // override in the context so that this message will be // logged as SUCCESS if that log level is recognized. $context['_level'] = ConsoleLogLevel::SUCCESS; - Config::logger()->notice($text, $this->getTaskContext($context)); + $this->logger()->notice($text, $this->getTaskContext($context)); } /** @@ -59,7 +80,7 @@ protected function printTaskSuccess($text, $context = null) */ protected function printTaskWarning($text, $context = null) { - Config::logger()->warning($text, $this->getTaskContext($context)); + $this->logger()->warning($text, $this->getTaskContext($context)); } /** @@ -70,7 +91,7 @@ protected function printTaskWarning($text, $context = null) */ protected function printTaskError($text, $context = null) { - Config::logger()->error($text, $this->getTaskContext($context)); + $this->logger()->error($text, $this->getTaskContext($context)); } /** @@ -79,7 +100,7 @@ protected function printTaskError($text, $context = null) */ protected function printTaskDebug($text, $context = null) { - Config::logger()->debug($text, $this->getTaskContext($context)); + $this->logger()->debug($text, $this->getTaskContext($context)); } /** diff --git a/src/Config.php b/src/Config.php index 82bc4f463..6088c1c8a 100644 --- a/src/Config.php +++ b/src/Config.php @@ -1,28 +1,29 @@ register('logStyler', 'Robo\Log\RoboLogStyle'); - $container->set('input', $input); - $container - ->register('output', 'Symfony\Component\Console\Output\ConsoleOutput'); - $container - ->register('logger', 'Robo\Log\RoboLogger') - ->addArgument(new Reference('output')) - ->addMethodCall('setLogOutputStyler', array(new Reference('logStyler'))); - $container - ->register('resultPrinter', 'Robo\Log\ResultPrinter') - ->addArgument(new Reference('logger')); - - return $container; - } - /** * Unsets the global container. */ @@ -113,7 +87,7 @@ public static function service($id) */ public static function setService($id, $service) { - static::getContainer()->set($id, $service); + static::getContainer()->add($id, $service); } /** @@ -183,14 +157,21 @@ public static function setInput(InputInterface $input) public static function get($key, $default = null) { - if (!static::$container->hasParameter($key)) { - return $default; - } - return static::$container->getParameter($key); + return isset(self::$config[$key]) ? self::$config[$key] : $default; } public static function set($key, $value) { - static::$container->setParameter($key, $value); + self::$config[$key] = $value; + } + + public static function setGlobalOptions($input) + { + static::$simulated = $input->getOption('simulate'); + } + + public static function isSimulated() + { + return static::$simulated; } } diff --git a/src/Container/RoboContainer.php b/src/Container/RoboContainer.php new file mode 100644 index 000000000..f72649cbe --- /dev/null +++ b/src/Container/RoboContainer.php @@ -0,0 +1,75 @@ +simulated = false; + } + + public function setSimulated($simulated) + { + $this->simulated = $simulated; + } + + public function isSimulated() + { + return $this->simulated; + } + + /** + * Get a serivice. Apply any service decorators. + */ + public function get($alias, array $args = []) + { + $service = parent::get($alias, $args); + + // Do not wrap our wrappers. + if ($service instanceof CompletionWrapper || $service instanceof Simulator) { + return $service; + } + + // Remember whether or not this is a task before + // it gets wrapped in any service decorator. + $isTask = $service instanceof TaskInterface; + $isCollection = $service instanceof Collection; + + // If the task implements CompletionInterface, ensure + // that its 'complete' method is called when the application + // terminates -- but only if its 'run' method is called + // first. If the task is added to a collection, then the + // task will be unwrapped via its `original` method, and + // it will be re-wrapped with a new completion wrapper for + // its new collection. + if ($service instanceof CompletionInterface) { + $service = parent::get('completionWrapper', [Temporary::getCollection(), $service]); + } + + // If we are in simulated mode, then wrap any task in + // a TaskSimulator. + if ($isTask && !$isCollection && ($this->isSimulated())) { + $service = parent::get('simulator', [$service, $args]); + } + + return $service; + } +} diff --git a/src/Container/SimpleServiceProvider.php b/src/Container/SimpleServiceProvider.php new file mode 100644 index 000000000..f3f67b6dd --- /dev/null +++ b/src/Container/SimpleServiceProvider.php @@ -0,0 +1,52 @@ +provides += $provides; + $this->signature = array_keys($provides)[0]; + } + + /** + * {@inheritdoc} + */ + public function provides($alias = null) + { + if (! is_null($alias)) { + return (array_key_exists($alias, $this->provides)); + } + + return array_keys($this->provides); + } + + /** + * {@inheritdoc} + */ + public function register() + { + foreach ($this->provides as $alias => $concrete) { + $this->getContainer()->add($alias, $concrete); + } + } +} diff --git a/src/Contract/CompletionInterface.php b/src/Contract/CompletionInterface.php index 093031cfc..d7198b108 100644 --- a/src/Contract/CompletionInterface.php +++ b/src/Contract/CompletionInterface.php @@ -6,15 +6,6 @@ * be called when the task collection it is added to * completes. * - * Tasks that should be cleaned up when the program - * terminates whenever they are used outside of a - * task collection should be wrapped in - * Temporary::wrap(). This will cause their - * complete() method to be called at shutdown time, but - * only if the object is not added to some other collection. - * - * @see Robo\Task\FileSystem\loadTasks::taskTmpDir - * * Interface CompletionInterface * @package Robo\Contract */ diff --git a/src/Contract/WrappedTaskInterface.php b/src/Contract/WrappedTaskInterface.php new file mode 100644 index 000000000..3523745c8 --- /dev/null +++ b/src/Contract/WrappedTaskInterface.php @@ -0,0 +1,10 @@ +logger = $logger; - } + use LoggerAwareTrait; /** * Log the result of a Robo task. diff --git a/src/Log/RoboLogLevel.php b/src/Log/RoboLogLevel.php new file mode 100644 index 000000000..d7d5eb0a6 --- /dev/null +++ b/src/Log/RoboLogLevel.php @@ -0,0 +1,11 @@ +labelStyles += [ + RoboLogLevel::SIMULATED_ACTION => self::TASK_STYLE_SIMULATED, + ]; + $this->messageStyles += [ + RoboLogLevel::SIMULATED_ACTION => '', + ]; + } + /** * Log style customization for Robo: replace the log level with * the task name. diff --git a/src/Log/RoboLogger.php b/src/Log/RoboLogger.php index 0f16d1561..8bd345987 100644 --- a/src/Log/RoboLogger.php +++ b/src/Log/RoboLogger.php @@ -24,6 +24,7 @@ public function __construct(OutputInterface $output) // the time, and 'info' for messages that appear only during verbose // output. We have no 'very verbose' (-vv) level. 'Debug' is -vvv, as usual. $roboVerbosityOverrides = [ + RoboLogLevel::SIMULATED_ACTION => OutputInterface::VERBOSITY_NORMAL, // Default is "verbose" LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL, // Default is "verbose" LogLevel::INFO => OutputInterface::VERBOSITY_VERBOSE, // Default is "very verbose" ]; diff --git a/src/Runner.php b/src/Runner.php index 27a1f4962..65766d075 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -3,7 +3,9 @@ use Robo\Config; use Robo\Common\IO; +use Robo\Container\RoboContainer; use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\ConsoleOutput; class Runner @@ -80,18 +82,21 @@ public function execute($input = null) register_shutdown_function(array($this, 'shutdown')); set_error_handler(array($this, 'handleError')); - // If we were not provided with a container, then create one + // If we were not provided a container, then create one if (!Config::hasContainer()) { $input = $this->prepareInput($input ? $input : $_SERVER['argv']); - $container = Config::createContainer($input); + // Set up our dependency injection container. + $container = new RoboContainer(); + static::configureContainer($container, $input); + static::addServiceProviders($container); + $container->share('application', \Robo\Application::class) + ->withArgument('Robo') + ->withArgument(self::VERSION); Config::setContainer($container); - - // Note: this freezes our container, preventing us from adding any further - // services to it. - $container->compile(); } - $app = new Application('Robo', self::VERSION); + $container = Config::getContainer(); + $app = $container->get('application'); if (!$this->loadRoboFile()) { $this->yell("Robo is not initialized here. Please run `robo init` to create a new RoboFile", 40, 'yellow'); @@ -100,7 +105,63 @@ public function execute($input = null) return; } $app->addCommandsFromClass($this->roboClass, $this->passThroughArgs); - $app->run(Config::input(), Config::output()); + $app->run($container->get('input'), $container->get('output')); + } + + /** + * Create a container and initiailze it. + */ + public static function configureContainer($container, $input = null, $output = null) + { + // Self-referential container refernce for the inflector + $container->add('container', $container); + + // Create default input and output objects if they were not provided + if (!$input) { + $input = new StringInput(''); + } + if (!$output) { + $output = new \Symfony\Component\Console\Output\ConsoleOutput(); + } + $container->add('input', $input); + $container->add('output', $output); + + // Register logging and related services. + $container->share('logStyler', \Robo\Log\RoboLogStyle::class); + $container->share('logger', \Robo\Log\RoboLogger::class) + ->withArgument('output') + ->withMethodCall('setLogOutputStyler', ['logStyler']); + $container->share('resultPrinter', \Robo\Log\ResultPrinter::class); + $container->add('simulator', \Robo\Task\Simulator::class); + + // Register our various inflectors. + $container->inflector(\Psr\Log\LoggerAwareInterface::class) + ->invokeMethod('setLogger', ['logger']); + $container->inflector(\League\Container\ContainerAwareInterface::class) + ->invokeMethod('setContainer', ['container']); + $container->inflector(\Symfony\Component\Console\Input\InputAwareInterface::class) + ->invokeMethod('setInput', ['input']); + } + + /** + * Register our service providers + */ + public static function addServiceProviders($container) + { + $container->addServiceProvider(\Robo\Collection\Collection::getCollectionServices()); + $container->addServiceProvider(\Robo\Task\ApiGen\loadTasks::getApiGenServices()); + $container->addServiceProvider(\Robo\Task\Archive\loadTasks::getArchiveServices()); + $container->addServiceProvider(\Robo\Task\Assets\loadTasks::getAssetsServices()); + $container->addServiceProvider(\Robo\Task\Base\loadTasks::getBaseServices()); + $container->addServiceProvider(\Robo\Task\Bower\loadTasks::getBowerServices()); + $container->addServiceProvider(\Robo\Task\Composer\loadTasks::getComposerServices()); + $container->addServiceProvider(\Robo\Task\Development\loadTasks::getDevelopmentServices()); + $container->addServiceProvider(\Robo\Task\Docker\loadTasks::getDockerServices()); + $container->addServiceProvider(\Robo\Task\File\loadTasks::getFileServices()); + $container->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); + $container->addServiceProvider(\Robo\Task\Remote\loadTasks::getRemoteServices()); + $container->addServiceProvider(\Robo\Task\Testing\loadTasks::getTestingServices()); + $container->addServiceProvider(\Robo\Task\Vcs\loadTasks::getVcsServices()); } /** diff --git a/src/Task/ApiGen/ApiGen.php b/src/Task/ApiGen/ApiGen.php index 780907ea7..20913184e 100644 --- a/src/Task/ApiGen/ApiGen.php +++ b/src/Task/ApiGen/ApiGen.php @@ -1,5 +1,4 @@ ApiGen::class, + ] + ); + } + /** * @param null $pathToApiGen * @return \Robo\Task\ApiGen\ApiGen */ protected function taskApiGen($pathToApiGen = null) { - return new ApiGen($pathToApiGen); + return $this->task(__FUNCTION__, $pathToApiGen); } - -} \ No newline at end of file +} diff --git a/src/Task/Archive/loadTasks.php b/src/Task/Archive/loadTasks.php index 67a5cbe1d..b7b4c594a 100644 --- a/src/Task/Archive/loadTasks.php +++ b/src/Task/Archive/loadTasks.php @@ -1,9 +1,23 @@ Extract::class, + 'taskPack' => Pack::class, + ] + ); + } + /** * @param $filename * @@ -11,7 +25,7 @@ trait loadTasks */ protected function taskPack($filename) { - return new Pack($filename); + return $this->task(__FUNCTION__, $filename); } /** @@ -21,6 +35,6 @@ protected function taskPack($filename) */ protected function taskExtract($filename) { - return new Extract($filename); + return $this->task(__FUNCTION__, $filename); } } diff --git a/src/Task/Assets/loadTasks.php b/src/Task/Assets/loadTasks.php index 93a2a695d..4eb69f248 100644 --- a/src/Task/Assets/loadTasks.php +++ b/src/Task/Assets/loadTasks.php @@ -1,15 +1,32 @@ Minify::class, + 'taskImageMinify' => ImageMinify::class, + 'taskLess' => Less::class, + 'taskScss' => Scss::class, + ] + ); + } + /** * @param $input * @return Minify */ protected function taskMinify($input) { - return new Minify($input); + return $this->task(__FUNCTION__, $input); } /** @@ -18,7 +35,7 @@ protected function taskMinify($input) */ protected function taskImageMinify($input) { - return new ImageMinify($input); + return $this->task(__FUNCTION__, $input); } /** @@ -27,7 +44,7 @@ protected function taskImageMinify($input) */ protected function taskLess($input) { - return new Less($input); + return $this->task(__FUNCTION__, $input); } /** @@ -36,6 +53,6 @@ protected function taskLess($input) */ protected function taskScss($input) { - return new Scss($input); + return $this->task(__FUNCTION__, $input); } } diff --git a/src/Task/Base/loadShortcuts.php b/src/Task/Base/loadShortcuts.php index 1d5408709..965a2a4f6 100644 --- a/src/Task/Base/loadShortcuts.php +++ b/src/Task/Base/loadShortcuts.php @@ -1,7 +1,7 @@ run(); + return $this->getContainer()->get('taskExec', [$command])->run(); } -} \ No newline at end of file +} diff --git a/src/Task/Base/loadTasks.php b/src/Task/Base/loadTasks.php index b9818bfb2..bee7a0451 100644 --- a/src/Task/Base/loadTasks.php +++ b/src/Task/Base/loadTasks.php @@ -1,20 +1,38 @@ Exec::class, + 'taskExecStack' => ExecStack::class, + 'taskParallelExec' => ParallelExec::class, + 'taskSymfonyCommand' => SymfonyCommand::class, + 'taskWatch' => Watch::class, + ] + ); + } + /** * @param $command * @return Exec */ protected function taskExec($command) { - return new Exec($command); + return $this->task(__FUNCTION__, $command); } protected function taskExecStack() { - return new ExecStack(); + return $this->task(__FUNCTION__); } /** @@ -22,7 +40,7 @@ protected function taskExecStack() */ protected function taskParallelExec() { - return new ParallelExec(); + return $this->task(__FUNCTION__); } /** @@ -31,7 +49,7 @@ protected function taskParallelExec() */ protected function taskSymfonyCommand($command) { - return new SymfonyCommand($command); + return $this->task(__FUNCTION__, $command); } /** @@ -39,6 +57,6 @@ protected function taskSymfonyCommand($command) */ protected function taskWatch() { - return new Watch($this); + return $this->task(__FUNCTION__, $this); } -} \ No newline at end of file +} diff --git a/src/Task/BaseTask.php b/src/Task/BaseTask.php index 71803c28c..a2b5274c8 100644 --- a/src/Task/BaseTask.php +++ b/src/Task/BaseTask.php @@ -5,10 +5,11 @@ use Robo\Common\TaskIO; use Robo\Collection\Collectable; use Robo\Contract\TaskInterface; +use Psr\Log\LoggerAwareInterface; -abstract class BaseTask implements TaskInterface +abstract class BaseTask implements TaskInterface, LoggerAwareInterface { - use TaskIO; + use TaskIO; // uses LoggerAwareTrait use Configuration; use Collectable; } diff --git a/src/Task/Bower/loadTasks.php b/src/Task/Bower/loadTasks.php index 786df0fef..91b382ded 100644 --- a/src/Task/Bower/loadTasks.php +++ b/src/Task/Bower/loadTasks.php @@ -1,24 +1,38 @@ Install::class, + 'taskBowerUpdate' => Update::class, + ] + ); + } + /** * @param null $pathToBower * @return Install */ protected function taskBowerInstall($pathToBower = null) { - return new Install($pathToBower); - } + return $this->task(__FUNCTION__, $pathToBower); + } /** * @param null $pathToBower * @return Update */ - protected function taskBowerUpdate($pathToBower = null) + protected function taskBowerUpdate($pathToBower = null) { - return new Update($pathToBower); - } - -} \ No newline at end of file + return $this->task(__FUNCTION__, $pathToBower); + } +} diff --git a/src/Task/Composer/loadTasks.php b/src/Task/Composer/loadTasks.php index b270c696d..aa32e3767 100644 --- a/src/Task/Composer/loadTasks.php +++ b/src/Task/Composer/loadTasks.php @@ -1,15 +1,31 @@ Install::class, + 'taskComposerUpdate' => Update::class, + 'taskComposerDumpAutoload' => DumpAutoload::class, + ] + ); + } + /** * @param null $pathToComposer * @return Install */ protected function taskComposerInstall($pathToComposer = null) { - return new Install($pathToComposer); + return $this->task(__FUNCTION__, $pathToComposer); } /** @@ -18,7 +34,7 @@ protected function taskComposerInstall($pathToComposer = null) */ protected function taskComposerUpdate($pathToComposer = null) { - return new Update($pathToComposer); + return $this->task(__FUNCTION__, $pathToComposer); } /** @@ -27,7 +43,6 @@ protected function taskComposerUpdate($pathToComposer = null) */ protected function taskComposerDumpAutoload($pathToComposer = null) { - return new DumpAutoload($pathToComposer); + return $this->task(__FUNCTION__, $pathToComposer); } - -} \ No newline at end of file +} diff --git a/src/Task/Development/SemVer.php b/src/Task/Development/SemVer.php index 1224080b8..2ae1ddb46 100644 --- a/src/Task/Development/SemVer.php +++ b/src/Task/Development/SemVer.php @@ -39,7 +39,7 @@ class SemVer implements TaskInterface 'metadata' => '' ]; - public function __construct($filename) + public function __construct($filename = '') { $this->path = $filename; @@ -155,4 +155,4 @@ protected function parse() list(, $major, $minor, $patch, $special, $metadata) = array_map('current', $matches); $this->version = compact('major', 'minor', 'patch', 'special', 'metadata'); } -} \ No newline at end of file +} diff --git a/src/Task/Development/loadTasks.php b/src/Task/Development/loadTasks.php index 2dfc7cb07..b7cd1f242 100644 --- a/src/Task/Development/loadTasks.php +++ b/src/Task/Development/loadTasks.php @@ -1,15 +1,35 @@ Changelog::class, + 'taskGenDoc' => GenerateMarkdownDoc::class, + 'taskSemVer' => SemVer::class, + 'taskServer' => PhpServer::class, + 'taskPackPhar' => PackPhar::class, + 'taskGitHubRelease' => GitHubRelease::class, + 'taskOpenBrowser' => OpenBrowser::class, + ] + ); + } + /** * @param string $filename * @return Changelog */ protected function taskChangelog($filename = 'CHANGELOG.md') { - return new Changelog($filename); + return $this->task(__FUNCTION__, $filename); } /** @@ -18,7 +38,7 @@ protected function taskChangelog($filename = 'CHANGELOG.md') */ protected function taskGenDoc($filename) { - return new GenerateMarkdownDoc($filename); + return $this->task(__FUNCTION__, $filename); } /** @@ -27,7 +47,7 @@ protected function taskGenDoc($filename) */ protected function taskSemVer($pathToSemVer = '.semver') { - return new SemVer($pathToSemVer); + return $this->task(__FUNCTION__, $pathToSemVer); } /** @@ -36,7 +56,7 @@ protected function taskSemVer($pathToSemVer = '.semver') */ protected function taskServer($port = 8000) { - return new PhpServer($port); + return $this->task(__FUNCTION__, $port); } /** @@ -45,7 +65,7 @@ protected function taskServer($port = 8000) */ protected function taskPackPhar($filename) { - return new PackPhar($filename); + return $this->task(__FUNCTION__, $filename); } /** @@ -54,7 +74,7 @@ protected function taskPackPhar($filename) */ protected function taskGitHubRelease($tag) { - return new GitHubRelease($tag); + return $this->task(__FUNCTION__, $tag); } /** @@ -63,6 +83,6 @@ protected function taskGitHubRelease($tag) */ protected function taskOpenBrowser($url) { - return new OpenBrowser($url); + return $this->task(__FUNCTION__, $url); } -} \ No newline at end of file +} diff --git a/src/Task/Docker/loadTasks.php b/src/Task/Docker/loadTasks.php index 10d0cf6e1..e0aedca74 100644 --- a/src/Task/Docker/loadTasks.php +++ b/src/Task/Docker/loadTasks.php @@ -1,39 +1,59 @@ - Run::class, + 'taskDockerPull' => Pull::class, + 'taskDockerBuild' => Build::class, + 'taskDockerStop' => Stop::class, + 'taskDockerCommit' => Commit::class, + 'taskDockerStart' => Start::class, + 'taskDockerRemove' => Remove::class, + ] + ); + } + protected function taskDockerRun($image) { - return new Run($image); + return $this->task(__FUNCTION__, $image); } protected function taskDockerPull($image) { - return new Pull($image); + return $this->task(__FUNCTION__, $image); } protected function taskDockerBuild($path = '.') { - return new Build($path); + return $this->task(__FUNCTION__, $path); } protected function taskDockerStop($cidOrResult) { - return new Stop($cidOrResult); + return $this->task(__FUNCTION__, $cidOrResult); } protected function taskDockerCommit($cidOrResult) { - return new Commit($cidOrResult); + return $this->task(__FUNCTION__, $cidOrResult); } protected function taskDockerStart($cidOrResult) { - return new Start($cidOrResult); + return $this->task(__FUNCTION__, $cidOrResult); } protected function taskDockerRemove($cidOrResult) { - return new Remove($cidOrResult); + return $this->task(__FUNCTION__, $cidOrResult); } protected function taskDockerExec($cidOrResult) { - return new Exec($cidOrResult); + return $this->task(__FUNCTION__, $cidOrResult); } -} \ No newline at end of file +} diff --git a/src/Task/File/loadTasks.php b/src/Task/File/loadTasks.php index 0d70f5b6b..138b64467 100644 --- a/src/Task/File/loadTasks.php +++ b/src/Task/File/loadTasks.php @@ -2,16 +2,32 @@ namespace Robo\Task\File; use Robo\Collection\Temporary; +use Robo\Container\SimpleServiceProvider; trait loadTasks { + /** + * Return services. + */ + public static function getFileServices() + { + return new SimpleServiceProvider( + [ + 'taskConcat' => Concat::class, + 'taskReplaceInFile' => Replace::class, + 'taskWriteToFile' => Write::class, + 'taskTmpFile' => TmpFile::class, + ] + ); + } + /** * @param $files * @return Concat */ protected function taskConcat($files) { - return new Concat($files); + return $this->task(__FUNCTION__, $files); } /** @@ -20,7 +36,7 @@ protected function taskConcat($files) */ protected function taskReplaceInFile($file) { - return new Replace($file); + return $this->task(__FUNCTION__, $file); } /** @@ -29,7 +45,7 @@ protected function taskReplaceInFile($file) */ protected function taskWriteToFile($file) { - return new Write($file); + return $this->task(__FUNCTION__, $file); } /** @@ -40,6 +56,6 @@ protected function taskWriteToFile($file) */ protected function taskTmpFile($filename = 'tmp', $extension = '', $baseDir = '', $includeRandomPart = true) { - return Temporary::wrap(new TmpFile($filename, $extension, $baseDir, $includeRandomPart)); + return $this->task(__FUNCTION__, $filename, $extension, $baseDir, $includeRandomPart); } } diff --git a/src/Task/FileSystem/TmpDir.php b/src/Task/FileSystem/TmpDir.php index 8a7882b07..a5a70b632 100644 --- a/src/Task/FileSystem/TmpDir.php +++ b/src/Task/FileSystem/TmpDir.php @@ -6,6 +6,9 @@ use Robo\Collection\Collection; use Robo\Contract\CompletionInterface; +use League\Container\ContainerAwareInterface; +use League\Container\ContainerAwareTrait; + /** * Create a temporary directory that is automatically cleaned up * once the task collection is is part of completes. @@ -28,8 +31,10 @@ * ?> * ``` */ -class TmpDir extends BaseDir implements CompletionInterface +class TmpDir extends BaseDir implements CompletionInterface, ContainerAwareInterface { + use ContainerAwareTrait; + protected $base; protected $prefix; protected $cwd; @@ -99,7 +104,7 @@ public function complete() if ($this->cwd) { chdir($this->savedWorkingDirectory); } - (new DeleteDir($this->dirs))->run(); + $this->getContainer()->get('taskDeleteDir', [$this->dirs])->run(); } /** diff --git a/src/Task/FileSystem/loadShortcuts.php b/src/Task/FileSystem/loadShortcuts.php index a32943228..abd0cdaa2 100644 --- a/src/Task/FileSystem/loadShortcuts.php +++ b/src/Task/FileSystem/loadShortcuts.php @@ -12,7 +12,7 @@ trait loadShortcuts */ protected function _copyDir($src, $dst) { - return (new CopyDir([$src => $dst]))->run(); + return $this->getContainer()->get('taskCopyDir', [[$src => $dst]])->run(); } /** @@ -22,7 +22,7 @@ protected function _copyDir($src, $dst) */ protected function _mirrorDir($src, $dst) { - return (new MirrorDir([$src => $dst]))->run(); + return $this->getContainer()->get('taskMirrorDir', [[$src => $dst]])->run(); } /** @@ -31,7 +31,7 @@ protected function _mirrorDir($src, $dst) */ protected function _deleteDir($dir) { - return (new DeleteDir($dir))->run(); + return $this->getContainer()->get('taskDeleteDir', [$dir])->run(); } /** @@ -40,7 +40,7 @@ protected function _deleteDir($dir) */ protected function _cleanDir($dir) { - return (new CleanDir($dir))->run(); + return $this->getContainer()->get('taskCleanDir', [$dir])->run(); } /** @@ -50,7 +50,7 @@ protected function _cleanDir($dir) */ protected function _rename($from, $to) { - return (new FilesystemStack)->rename($from, $to)->run(); + return $this->getContainer()->get('taskFileSystemStack')->rename($from, $to)->run(); } /** @@ -59,7 +59,7 @@ protected function _rename($from, $to) */ protected function _mkdir($dir) { - return (new FilesystemStack)->mkdir($dir)->run(); + return $this->getContainer()->get('taskFileSystemStack')->mkdir($dir)->run(); } /** @@ -68,7 +68,7 @@ protected function _mkdir($dir) */ protected function _tmpDir($prefix = 'tmp', $base = '', $includeRandomPart = true) { - $result = Temporary::wrap(new TmpDir($prefix, $base, $includeRandomPart))->run(); + $result = $this->getContainer()->get('taskTmpDir', [$prefix, $base, $includeRandomPart])->run(); $data = $result->getData() + ['path' => '']; return $data['path']; } @@ -79,7 +79,7 @@ protected function _tmpDir($prefix = 'tmp', $base = '', $includeRandomPart = tru */ protected function _touch($file) { - return (new FilesystemStack)->touch($file)->run(); + return $this->getContainer()->get('taskFileSystemStack')->touch($file)->run(); } /** @@ -88,7 +88,7 @@ protected function _touch($file) */ protected function _remove($file) { - return (new FilesystemStack)->remove($file)->run(); + return $this->getContainer()->get('taskFileSystemStack')->remove($file)->run(); } /** @@ -98,7 +98,7 @@ protected function _remove($file) */ protected function _chgrp($file, $group) { - return (new FilesystemStack)->chgrp($file, $group)->run(); + return $this->getContainer()->get('taskFileSystemStack')->chgrp($file, $group)->run(); } /** @@ -110,7 +110,7 @@ protected function _chgrp($file, $group) */ protected function _chmod($file, $permissions, $umask = 0000, $recursive = false) { - return (new FilesystemStack)->chmod($file, $permissions, $umask, $recursive)->run(); + return $this->getContainer()->get('taskFileSystemStack')->chmod($file, $permissions, $umask, $recursive)->run(); } /** @@ -120,7 +120,7 @@ protected function _chmod($file, $permissions, $umask = 0000, $recursive = false */ protected function _symlink($from, $to) { - return (new FilesystemStack)->symlink($from, $to)->run(); + return $this->getContainer()->get('taskFileSystemStack')->symlink($from, $to)->run(); } /** @@ -130,7 +130,7 @@ protected function _symlink($from, $to) */ protected function _copy($from, $to) { - return (new FilesystemStack)->copy($from, $to)->run(); + return $this->getContainer()->get('taskFileSystemStack')->copy($from, $to)->run(); } /** @@ -140,6 +140,6 @@ protected function _copy($from, $to) */ protected function _flattenDir($from, $to) { - return (new FlattenDir([$from => $to]))->run(); + return $this->getContainer()->get('taskFlattenDir', [[$from => $to]])->run(); } } diff --git a/src/Task/FileSystem/loadTasks.php b/src/Task/FileSystem/loadTasks.php index 80ccb4961..fd3cb3351 100644 --- a/src/Task/FileSystem/loadTasks.php +++ b/src/Task/FileSystem/loadTasks.php @@ -2,16 +2,35 @@ namespace Robo\Task\FileSystem; use Robo\Collection\Temporary; +use Robo\Container\SimpleServiceProvider; trait loadTasks { + /** + * Return services. + */ + public static function getFileSystemServices() + { + return new SimpleServiceProvider( + [ + 'taskCleanDir' => CleanDir::class, + 'taskDeleteDir' => DeleteDir::class, + 'taskTmpDir' => TmpDir::class, + 'taskCopyDir' => CopyDir::class, + 'taskMirrorDir' => MirrorDir::class, + 'taskFlattenDir' => FlattenDir::class, + 'taskFilesystemStack' => FilesystemStack::class, + ] + ); + } + /** * @param $dirs * @return CleanDir */ protected function taskCleanDir($dirs) { - return new CleanDir($dirs); + return $this->task(__FUNCTION__, $dirs); } /** @@ -20,7 +39,7 @@ protected function taskCleanDir($dirs) */ protected function taskDeleteDir($dirs) { - return new DeleteDir($dirs); + return $this->task(__FUNCTION__, $dirs); } /** @@ -31,7 +50,7 @@ protected function taskDeleteDir($dirs) */ protected function taskTmpDir($prefix = 'tmp', $base = '', $includeRandomPart = true) { - return Temporary::wrap(new TmpDir($prefix, $base, $includeRandomPart)); + return $this->task(__FUNCTION__, $prefix, $base, $includeRandomPart); } /** @@ -40,7 +59,7 @@ protected function taskTmpDir($prefix = 'tmp', $base = '', $includeRandomPart = */ protected function taskCopyDir($dirs) { - return new CopyDir($dirs); + return $this->task(__FUNCTION__, $dirs); } /** @@ -49,7 +68,7 @@ protected function taskCopyDir($dirs) */ protected function taskMirrorDir($dirs) { - return new MirrorDir($dirs); + return $this->task(__FUNCTION__, $dirs); } /** @@ -58,7 +77,7 @@ protected function taskMirrorDir($dirs) */ protected function taskFlattenDir($dirs) { - return new FlattenDir($dirs); + return $this->task(__FUNCTION__, $dirs); } /** @@ -66,6 +85,6 @@ protected function taskFlattenDir($dirs) */ protected function taskFilesystemStack() { - return new FilesystemStack(); + return $this->task(__FUNCTION__); } } diff --git a/src/Task/Gulp/loadTasks.php b/src/Task/Gulp/loadTasks.php index b0ff372f2..1f7725481 100644 --- a/src/Task/Gulp/loadTasks.php +++ b/src/Task/Gulp/loadTasks.php @@ -1,15 +1,28 @@ Run::class, + ] + ); + } + /** * @param $task * @param null $pathToGulp * @return Run */ protected function taskGulpRun($task='default',$pathToGulp = null) { - return new Run($task,$pathToGulp); + return $this->task(__FUNCTION__, $task,$pathToGulp); } -} \ No newline at end of file +} diff --git a/src/Task/Npm/loadTasks.php b/src/Task/Npm/loadTasks.php index d7fa297f9..49c866615 100644 --- a/src/Task/Npm/loadTasks.php +++ b/src/Task/Npm/loadTasks.php @@ -1,14 +1,29 @@ Install::class, + 'taskNpmUpdate' => Update::class, + ] + ); + } + /** * @param null $pathToNpm * @return Install */ protected function taskNpmInstall($pathToNpm = null) { - return new Install($pathToNpm); + return $this->task(__FUNCTION__, $pathToNpm); } /** @@ -16,6 +31,6 @@ protected function taskNpmInstall($pathToNpm = null) { * @return Update */ protected function taskNpmUpdate($pathToNpm = null) { - return new Update($pathToNpm); + return $this->task(__FUNCTION__, $pathToNpm); } -} \ No newline at end of file +} diff --git a/src/Task/Remote/loadTasks.php b/src/Task/Remote/loadTasks.php index 87fecc318..85450b029 100644 --- a/src/Task/Remote/loadTasks.php +++ b/src/Task/Remote/loadTasks.php @@ -1,14 +1,29 @@ Rsync::class, + 'taskSshExec' => Ssh::class, + ] + ); + } + /** * @return Rsync */ protected function taskRsync() { - return new Rsync(); + return $this->task(__FUNCTION__); } /** @@ -18,7 +33,6 @@ protected function taskRsync() */ protected function taskSshExec($hostname = null, $user = null) { - return new Ssh($hostname, $user); + return $this->task(__FUNCTION__, $hostname, $user); } - -} \ No newline at end of file +} diff --git a/src/Task/Simulator.php b/src/Task/Simulator.php new file mode 100644 index 000000000..6f3cf5577 --- /dev/null +++ b/src/Task/Simulator.php @@ -0,0 +1,75 @@ +task = ($task instanceof WrappedTaskInterface) ? $task->original() : $task; + $this->constructorParameters = $constructorParameters; + } + + public function __call($function, $args) + { + $this->stack[] = array_merge([$function], $args); + return $this; + } + + public function run() + { + $callchain = ''; + foreach ($this->stack as $action) { + $command = array_shift($action); + $parameters = $this->formatParameters($action); + $callchain .= "\n ->$command($parameters)"; + } + // RoboLogLevel::SIMULATED_ACTION + $this->logger()->log( + RoboLogLevel::SIMULATED_ACTION, + "Simulating {simulated}({parameters})$callchain", + $this->getTaskContext( + [ + 'simulated' => TaskInfo::formatTaskName($this->task), + 'parameters' => $this->formatParameters($this->constructorParameters), + '_style' => ['simulated' => 'fg=blue;options=bold'], + ] + ) + ); + return Result::success($this); + } + + protected function formatParameters($action) + { + $parameterList = array_map( + function ($item) { + if (is_callable($item)) { + return 'inline_function(...)'; + } + if (is_array($item)) { + return var_export($item, true); + } + if (is_object($item)) { + return '[object]'; +// return var_export($item, true); + } + if (is_string($item)) { + return "'$item'"; + } + return $item; + }, + $action + ); + return implode(', ', $parameterList); + } +} diff --git a/src/Task/Testing/loadTasks.php b/src/Task/Testing/loadTasks.php index 748c1b11c..94809323d 100644 --- a/src/Task/Testing/loadTasks.php +++ b/src/Task/Testing/loadTasks.php @@ -1,15 +1,31 @@ Codecept::class, + 'taskPHPUnit' => PHPUnit::class, + 'taskPhpspec' => Phpspec::class, + ] + ); + } + /** * @param null $pathToCodeception * @return Codecept */ protected function taskCodecept($pathToCodeception = null) { - return new Codecept($pathToCodeception); + return $this->task(__FUNCTION__, $pathToCodeception); } /** @@ -18,7 +34,7 @@ protected function taskCodecept($pathToCodeception = null) */ protected function taskPhpUnit($pathToPhpUnit = null) { - return new PHPUnit($pathToPhpUnit); + return $this->task(__FUNCTION__, $pathToPhpUnit); } /** @@ -27,6 +43,6 @@ protected function taskPhpUnit($pathToPhpUnit = null) */ protected function taskPhpspec($pathToPhpspec = null) { - return new Phpspec($pathToPhpspec); + return $this->task(__FUNCTION__, $pathToPhpspec); } -} \ No newline at end of file +} diff --git a/src/Task/Vcs/loadShortcuts.php b/src/Task/Vcs/loadShortcuts.php index 49bbc07f5..07a453218 100644 --- a/src/Task/Vcs/loadShortcuts.php +++ b/src/Task/Vcs/loadShortcuts.php @@ -1,4 +1,4 @@ -checkout($url)->run(); + return $this->getContainer()->get('taskSvnStack')->checkout($url)->run(); } /** @@ -18,6 +18,6 @@ protected function _svnCheckout($url) */ protected function _gitClone($url) { - return (new GitStack())->cloneRepo($url)->run(); + return $this->getContainer()->get('taskGitStack')->cloneRepo($url)->run(); } -} \ No newline at end of file +} diff --git a/src/Task/Vcs/loadTasks.php b/src/Task/Vcs/loadTasks.php index 379ca60ff..4fd576435 100644 --- a/src/Task/Vcs/loadTasks.php +++ b/src/Task/Vcs/loadTasks.php @@ -1,8 +1,23 @@ SvnStack::class, + 'taskGitStack' => GitStack::class, + ] + ); + } + /** * @param string $username * @param string $password @@ -11,7 +26,7 @@ trait loadTasks */ protected function taskSvnStack($username = '', $password = '', $pathToSvn = 'svn') { - return new SvnStack($username, $password, $pathToSvn); + return $this->task(__FUNCTION__, $username, $password, $pathToSvn); } /** @@ -20,7 +35,6 @@ protected function taskSvnStack($username = '', $password = '', $pathToSvn = 'sv */ protected function taskGitStack($pathToGit = 'git') { - return new GitStack($pathToGit); + return $this->task(__FUNCTION__, $pathToGit); } - } diff --git a/src/Tasklib.php b/src/Tasklib.php index ea6f77d72..a4cc6b406 100644 --- a/src/Tasklib.php +++ b/src/Tasklib.php @@ -3,9 +3,6 @@ trait Tasklib { - // collections of tasks - use Collection\loadTasks; - // standard tasks use Task\Base\loadTasks; use Task\Development\loadTasks; @@ -35,4 +32,49 @@ trait Tasklib use Task\Base\loadShortcuts; use Task\FileSystem\loadShortcuts; use Task\Vcs\loadShortcuts; + + + /** + * Convenience function. Use: + * + * $this->collection(); + * + * instead of: + * + * $this->getContainer()->get('collection'); + */ + protected function collection() + { + return $this->getContainer()->get('collection'); + } + + /** + * Convenience function. Use: + * + * $this->task('Foo', $a, $b); + * + * instead of: + * + * $this->getContainer()->get('taskFoo', [$a, $b]); + * + * Note that most tasks will define another convenience + * function, $this->taskFoo($a, $b), declared in a + * 'loadTasks' trait in the task's namespace. These + * 'loadTasks' convenience functions typically will call + * $this->task() to ensure that task objects are fetched + * from the container, so that their dependencies may be + * automatically resolved. + */ + protected function task() + { + $args = func_get_args(); + $name = array_shift($args); + // We'll allow callers to include the literal 'task' + // or not, as they wish; however, the container object + // that we fetch must always begin with 'task' + if (!preg_match('#^task#', $name)) { + $name = "task$name"; + } + return $this->getContainer()->get($name, $args); + } } diff --git a/src/Tasks.php b/src/Tasks.php index 559184dcb..12d8a98c7 100644 --- a/src/Tasks.php +++ b/src/Tasks.php @@ -2,9 +2,12 @@ namespace Robo; use Robo\Common\IO; +use League\Container\ContainerAwareInterface; +use League\Container\ContainerAwareTrait; -class Tasks +class Tasks implements ContainerAwareInterface { + use ContainerAwareTrait; use Tasklib; use IO; diff --git a/tests/_helpers/CliGuy.php b/tests/_helpers/CliGuy.php index 8a2a15877..7aa44ab4e 100644 --- a/tests/_helpers/CliGuy.php +++ b/tests/_helpers/CliGuy.php @@ -16,11 +16,16 @@ * * @SuppressWarnings(PHPMD) */ + +use League\Container\ContainerAwareInterface; +use League\Container\ContainerAwareTrait; +use Robo\Config; + class CliGuy extends \Codeception\Actor { use _generated\CliGuyActions; - /** - * Define custom actions here - */ + /** + * Define custom actions here + */ } diff --git a/tests/_helpers/CliHelper.php b/tests/_helpers/CliHelper.php index 7aef50a32..01e38a88e 100644 --- a/tests/_helpers/CliHelper.php +++ b/tests/_helpers/CliHelper.php @@ -5,39 +5,30 @@ use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\NullOutput; -class CliHelper extends \Codeception\Module +use League\Container\ContainerAwareInterface; +use League\Container\ContainerAwareTrait; + +class CliHelper extends \Codeception\Module implements ContainerAwareInterface { - use \Robo\Task\Base\loadTasks { + use ContainerAwareTrait; + + use \Robo\Tasklib { + task as public; taskExec as public; taskExecStack as public; - } - use \Robo\Task\File\loadTasks { taskWriteToFile as public; taskReplaceInFile as public; taskConcat as public; taskTmpFile as public; - } - - use \Robo\Task\FileSystem\loadTasks { taskCleanDir as public; taskCopyDir as public; taskDeleteDir as public; taskFlattenDir as public; taskFileSystemStack as public; taskTmpDir as public; - } - - use \Robo\Task\FileSystem\loadShortcuts { _copyDir as public shortcutCopyDir; _mirrorDir as public shortcutMirrorDir; _tmpDir as public shortcutTmpDir; - } - - use \Robo\Collection\loadTasks { - collection as public; - } - - use \Robo\Task\Archive\loadTasks { taskPack as public; taskExtract as public; } @@ -50,6 +41,7 @@ public function seeDirFound($dir) public function _before(\Codeception\TestCase $test) { $this->getModule('Filesystem')->copyDir(codecept_data_dir().'claypit', codecept_data_dir().'sandbox'); Config::setOutput(new NullOutput()); + $this->setContainer(Config::getContainer()); } public function _after(\Codeception\TestCase $test) { diff --git a/tests/_helpers/CodeHelper.php b/tests/_helpers/CodeHelper.php index 879035e84..fb0609d25 100644 --- a/tests/_helpers/CodeHelper.php +++ b/tests/_helpers/CodeHelper.php @@ -13,18 +13,17 @@ class CodeHelper extends \Codeception\Module { protected static $testPrinter; protected static $capturedOutput; + protected static $container; public function _before(\Codeception\TestCase $test) { static::$capturedOutput = ''; static::$testPrinter = new BufferedOutput(OutputInterface::VERBOSITY_DEBUG); - $testLogger = new \Robo\Log\RoboLogger(static::$testPrinter); - $testLogger->setLogOutputStyler(new \Robo\Log\RoboLogStyle()); - $resultPrinter = new \Robo\Log\ResultPrinter($testLogger); - Config::setOutput(static::$testPrinter); - Config::setService('logger', $testLogger); - Config::setService('resultPrinter', $resultPrinter); + + static::$container = new \Robo\Container\RoboContainer(); + \Robo\Runner::configureContainer(static::$container, null, static::$testPrinter); + Config::setContainer(static::$container); } public function _after(\Codeception\TestCase $test) diff --git a/tests/cli/CleanDirCept.php b/tests/cli/CleanDirCept.php index c23de5eec..83cc5485c 100644 --- a/tests/cli/CleanDirCept.php +++ b/tests/cli/CleanDirCept.php @@ -1,5 +1,7 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); + $I->wantTo('clean dir with DeleteDirTask'); $I->amInPath(codecept_data_dir()); $I->seeFileFound('robo.txt', 'sandbox'); @@ -7,4 +9,6 @@ ->run(); $I->dontSeeFileFound('box', 'sandbox'); $I->dontSeeFileFound('robo.txt', 'sandbox'); -$I->dontSeeFileFound('a.txt' , 'sandbox'); \ No newline at end of file +$I->dontSeeFileFound('a.txt' , 'sandbox'); + + diff --git a/tests/cli/CollectionCest.php b/tests/cli/CollectionCest.php index 131ec8276..f155964c6 100644 --- a/tests/cli/CollectionCest.php +++ b/tests/cli/CollectionCest.php @@ -11,13 +11,17 @@ class CollectionCest { public function _before(CliGuy $I) { + $I->getContainer()->addServiceProvider(\Robo\Collection\Collection::getCollectionServices()); + $I->getContainer()->addServiceProvider(\Robo\Task\File\loadTasks::getFileServices()); + $I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); + $I->amInPath(codecept_data_dir().'sandbox'); } public function toCreateDirViaCollection(CliGuy $I) { // Set up a collection to add tasks to - $collection = $I->collection(); + $collection = $I->getContainer()->get('collection'); // Set up a filesystem stack, but use addToCollection() to defer execution $I->taskFileSystemStack() @@ -37,7 +41,7 @@ public function toCreateDirViaCollection(CliGuy $I) public function toUseATmpDirAndConfirmItIsDeleted(CliGuy $I) { // Set up a collection to add tasks to - $collection = $I->collection(); + $collection = $I->getContainer()->get('collection'); // Get a temporary directory to work in. Note that we get a // name back, but the directory is not created until the task @@ -82,7 +86,7 @@ public function toUseATmpDirAndConfirmItIsDeleted(CliGuy $I) public function toUseATmpDirAndChangeWorkingDirectory(CliGuy $I) { // Set up a collection to add tasks to - $collection = $I->collection(); + $collection = $I->getContainer()->get('collection'); $cwd = getcwd(); @@ -131,7 +135,7 @@ public function toUseATmpDirAndChangeWorkingDirectory(CliGuy $I) public function toCreateATmpFileAndConfirmItIsDeleted(CliGuy $I) { // Set up a collection to add tasks to - $collection = $I->collection(); + $collection = $I->getContainer()->get('collection'); // Write to a temporary file. Note that we can get the path // to the tempoary file that will be created, even though the @@ -162,7 +166,7 @@ public function toCreateATmpFileAndConfirmItIsDeleted(CliGuy $I) public function toUseATmpDirWithAlternateSyntax(CliGuy $I) { - $collection = $I->collection(); + $collection = $I->getContainer()->get('collection'); // This test is equivalent to toUseATmpDirAndConfirmItIsDeleted, // but uses a different technique to create a collection of tasks. diff --git a/tests/cli/ConcatCept.php b/tests/cli/ConcatCept.php index 416673875..eb78bd207 100644 --- a/tests/cli/ConcatCept.php +++ b/tests/cli/ConcatCept.php @@ -1,9 +1,12 @@ -getContainer()->addServiceProvider(\Robo\Task\File\loadTasks::getFileServices()); + $I->wantTo('concat files using Concat Task'); $I->amInPath(codecept_data_dir() . 'sandbox'); $I->taskConcat(['a.txt', 'b.txt']) ->to('merged.txt') ->run(); $I->seeFileFound('merged.txt'); -$I->seeFileContentsEqual("A\nB\n"); \ No newline at end of file +$I->seeFileContentsEqual("A\nB\n"); + diff --git a/tests/cli/CopyDirCept.php b/tests/cli/CopyDirCept.php index 1205bbb09..3dfb487a0 100644 --- a/tests/cli/CopyDirCept.php +++ b/tests/cli/CopyDirCept.php @@ -1,8 +1,11 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); + $I->wantTo('copy dir with CopyDir task'); $I->amInPath(codecept_data_dir().'sandbox'); $I->taskCopyDir(['box' => 'bin']) ->run(); $I->seeDirFound('bin'); $I->seeFileFound('robo.txt', 'bin'); + diff --git a/tests/cli/CopyDirOverwritesFilesCept.php b/tests/cli/CopyDirOverwritesFilesCept.php index 133d6e7f8..2318bf70d 100644 --- a/tests/cli/CopyDirOverwritesFilesCept.php +++ b/tests/cli/CopyDirOverwritesFilesCept.php @@ -1,5 +1,7 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); + $I->wantTo('overwrite a file with CopyDir task'); $I->amInPath(codecept_data_dir() . 'sandbox'); $I->seeDirFound('some'); diff --git a/tests/cli/CopyDirRecursiveCept.php b/tests/cli/CopyDirRecursiveCept.php index 7ca8e4fd1..d6eb0bfee 100644 --- a/tests/cli/CopyDirRecursiveCept.php +++ b/tests/cli/CopyDirRecursiveCept.php @@ -1,5 +1,7 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); + $I->wantTo('copy dir recursively with CopyDir task'); $I->amInPath(codecept_data_dir() . 'sandbox'); $I->seeDirFound('some/deeply/nested'); diff --git a/tests/cli/DeleteDirCept.php b/tests/cli/DeleteDirCept.php index b42bfe5eb..f63095c3e 100644 --- a/tests/cli/DeleteDirCept.php +++ b/tests/cli/DeleteDirCept.php @@ -1,5 +1,8 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); + $I->wantTo('delete dir with DeleteDirTask'); $I->amInPath(codecept_data_dir()); $I->seeFileFound('robo.txt', 'sandbox'); diff --git a/tests/cli/ExecCest.php b/tests/cli/ExecCest.php index e2cb5449f..f71ef968c 100644 --- a/tests/cli/ExecCest.php +++ b/tests/cli/ExecCest.php @@ -1,6 +1,12 @@ getContainer()->addServiceProvider(\Robo\Task\Base\loadTasks::getBaseServices()); + } + // tests public function toExecLsCommand(CliGuy $I) { @@ -9,4 +15,4 @@ public function toExecLsCommand(CliGuy $I) verify($res->getMessage())->contains('src'); verify($res->getMessage())->contains('codeception.yml'); } -} \ No newline at end of file +} diff --git a/tests/cli/FileSystemStackCest.php b/tests/cli/FileSystemStackCest.php index 3a0dbb19a..603ce12f0 100644 --- a/tests/cli/FileSystemStackCest.php +++ b/tests/cli/FileSystemStackCest.php @@ -1,8 +1,10 @@ getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); $I->amInPath(codecept_data_dir().'sandbox'); } diff --git a/tests/cli/FlattenDirCept.php b/tests/cli/FlattenDirCept.php index 63074a477..44079c217 100644 --- a/tests/cli/FlattenDirCept.php +++ b/tests/cli/FlattenDirCept.php @@ -1,5 +1,7 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); + $I->wantTo('flatten dir with FlattenDir task'); $I->amInPath(codecept_data_dir().'sandbox'); $I->taskFlattenDir([ diff --git a/tests/cli/FlattenDirParentsCept.php b/tests/cli/FlattenDirParentsCept.php index 877610e0b..ba822396d 100644 --- a/tests/cli/FlattenDirParentsCept.php +++ b/tests/cli/FlattenDirParentsCept.php @@ -1,8 +1,10 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); + $I->wantTo('flatten dir with FlattenDir task including parents'); $I->amInPath(codecept_data_dir().'sandbox'); -$I->taskFlattenDir(['some/deeply/nested/*.re']) +$I->taskFlattenDir('some/deeply/nested/*.re') ->includeParents(array(1,1)) ->parentDir('some') ->to('flattened') diff --git a/tests/cli/PackExtractCept.php b/tests/cli/PackExtractCept.php index f97cde01b..20bfa7831 100644 --- a/tests/cli/PackExtractCept.php +++ b/tests/cli/PackExtractCept.php @@ -1,6 +1,11 @@ getContainer()->addServiceProvider(\Robo\Task\Archive\loadTasks::getArchiveServices()); +//$provider = \Robo\Task\Archive\loadTasks::getArchiveServices(); +//$provider->setContainer($I->getContainer()); +//$provider->register($I->getContainer()); + $I->wantTo('archive directory and then extract it again with Archive and Extract tasks'); $I->amInPath(codecept_data_dir().'sandbox'); $I->seeDirFound('some/deeply/nested'); diff --git a/tests/cli/WriteFileCest.php b/tests/cli/WriteFileCest.php index 913da8b69..d4194ce61 100644 --- a/tests/cli/WriteFileCest.php +++ b/tests/cli/WriteFileCest.php @@ -1,8 +1,10 @@ getContainer()->addServiceProvider(\Robo\Task\File\loadTasks::getFileServices()); $I->amInPath(codecept_data_dir('sandbox')); } @@ -62,7 +64,7 @@ public function replaceInFile(CliGuy $I) ->run(); $I->seeFileFound('a.txt'); $I->seeFileContentsEqual('B'); - + } public function replaceMultipleInFile(CliGuy $I) diff --git a/tests/cli/_bootstrap.php b/tests/cli/_bootstrap.php index 4bed6b698..77531f248 100644 --- a/tests/cli/_bootstrap.php +++ b/tests/cli/_bootstrap.php @@ -2,5 +2,11 @@ // Here you can initialize variables that will for your tests use Robo\Config; +use Robo\Runner; +use Robo\Container\RoboContainer; +use Symfony\Component\Console\Input\StringInput; -Config::setContainer(Config::createContainer()); +$container = new RoboContainer(); +$input = new StringInput(''); +Runner::configureContainer($container, $input); +Config::setContainer($container); diff --git a/tests/unit/Task/ApiGenTest.php b/tests/unit/Task/ApiGenTest.php index adc5e378d..e27a25835 100644 --- a/tests/unit/Task/ApiGenTest.php +++ b/tests/unit/Task/ApiGenTest.php @@ -1,9 +1,11 @@ null, 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\ApiGen\loadTasks::getApiGenServices()); } // tests @@ -26,7 +31,7 @@ public function testPHPUnitCommand() $skippedPaths->push('b'); // going for 'bang for the buck' here re: test converage - $task = $this->taskApiGen('apigen') + $task = $this->container->get('taskApiGen', ['apigen']) ->config('./apigen.neon') ->source('src') // single string value of Traversable ->extensions('php') // single string value of List @@ -44,5 +49,4 @@ public function testPHPUnitCommand() $task->run(); $this->apigen->verifyInvoked('executeCommand', [$cmd]); } - } diff --git a/tests/unit/Task/BowerTest.php b/tests/unit/Task/BowerTest.php index d63cf6a98..7d1c687ac 100644 --- a/tests/unit/Task/BowerTest.php +++ b/tests/unit/Task/BowerTest.php @@ -1,9 +1,10 @@ baseBower = test::double('Robo\Task\Bower\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->container = Config::getContainer(); + $this->container->addServiceProvider(Robo\Task\Bower\loadTasks::getBowerServices()); } // tests public function testBowerInstall() { $bower = test::double('Robo\Task\Bower\Install', ['executeCommand' => null]); - $this->taskBowerInstall('bower')->run(); + $this->container->get('taskBowerInstall', ['bower'])->run(); $bower->verifyInvoked('executeCommand', ['bower install']); } public function testBowerUpdate() { $bower = test::double('Robo\Task\Bower\Update', ['executeCommand' => null]); - $this->taskBowerUpdate('bower')->run(); + $this->container->get('taskBowerUpdate', ['bower'])->run(); $bower->verifyInvoked('executeCommand', ['bower update']); } public function testBowerInstallCommand() { verify( - $this->taskBowerInstall('bower')->getCommand() + $this->container->get('taskBowerInstall', ['bower'])->getCommand() )->equals('bower install'); verify( - $this->taskBowerInstall('bower')->getCommand() + $this->container->get('taskBowerInstall', ['bower'])->getCommand() )->equals('bower install'); verify( - $this->taskBowerInstall('bower') + $this->container->get('taskBowerInstall', ['bower']) ->allowRoot() ->forceLatest() ->offline() @@ -51,4 +54,4 @@ public function testBowerInstallCommand() )->equals('bower install --allow-root --force-latest --offline --production'); } -} \ No newline at end of file +} diff --git a/tests/unit/Task/CodeceptionTest.php b/tests/unit/Task/CodeceptionTest.php index 3314cd9c7..b2f5b8617 100644 --- a/tests/unit/Task/CodeceptionTest.php +++ b/tests/unit/Task/CodeceptionTest.php @@ -1,9 +1,11 @@ null, 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Testing\loadTasks::getTestingServices()); } // tests public function testCodeceptionCommand() { - verify($this->taskCodecept()->getCommand())->equals($this->command); - verify(trim($this->taskCodecept('codecept.phar')->getCommand()))->equals('codecept.phar run'); + verify($this->container->get('taskCodecept')->getCommand())->equals($this->command); + verify(trim($this->container->get('taskCodecept', ['codecept.phar'])->getCommand()))->equals('codecept.phar run'); } public function testCodeceptionRun() { - $this->taskCodecept()->run(); + $this->container->get('taskCodecept')->run(); $this->codecept->verifyInvoked('executeCommand', [$this->command]); } public function testCodeceptOptions() { - verify($this->taskCodecept('codecept') + verify($this->container->get('taskCodecept', ['codecept']) ->suite('unit') ->test('Codeception/Command') ->group('core') @@ -48,7 +52,7 @@ public function testCodeceptOptions() ->getCommand() )->equals('codecept run --group core --env process1 --coverage unit Codeception/Command'); - verify($this->taskCodecept('codecept') + verify($this->container->get('taskCodecept', ['codecept']) ->test('tests/unit/Codeception') ->configFile('~/Codeception') ->xml('result.xml') @@ -56,11 +60,11 @@ public function testCodeceptOptions() ->getCommand() )->equals('codecept run -c ~/Codeception --xml result.xml --html tests/unit/Codeception'); - verify($this->taskCodecept()->debug()->getCommand())->contains(' --debug'); - verify($this->taskCodecept()->silent()->getCommand())->contains(' --silent'); - verify($this->taskCodecept()->excludeGroup('g')->getCommand())->contains(' --skip-group g'); - verify($this->taskCodecept()->tap()->getCommand())->contains('--tap'); - verify($this->taskCodecept()->json()->getCommand())->contains('--json'); + verify($this->container->get('taskCodecept')->debug()->getCommand())->contains(' --debug'); + verify($this->container->get('taskCodecept')->silent()->getCommand())->contains(' --silent'); + verify($this->container->get('taskCodecept')->excludeGroup('g')->getCommand())->contains(' --skip-group g'); + verify($this->container->get('taskCodecept')->tap()->getCommand())->contains('--tap'); + verify($this->container->get('taskCodecept')->json()->getCommand())->contains('--json'); } -} \ No newline at end of file +} diff --git a/tests/unit/Task/CollectionTest.php b/tests/unit/Task/CollectionTest.php index 528375c7e..c5b90170a 100644 --- a/tests/unit/Task/CollectionTest.php +++ b/tests/unit/Task/CollectionTest.php @@ -10,12 +10,21 @@ use Robo\Task\BaseTask; use Robo\Contract\TaskInterface; use Robo\Collection\Collection; +use Robo\Config; class CollectionTest extends \Codeception\TestCase\Test { + protected $container; + + protected function _before() + { + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Collection\Collection::getCollectionServices()); + } + public function testBeforeAndAfterFilters() { - $collection = new Collection(); + $collection = $this->container->get('collection'); $taskA = new CollectionTestTask('a', 'value-a'); $taskB = new CollectionTestTask('b', 'value-b'); diff --git a/tests/unit/Task/CommandStackTest.php b/tests/unit/Task/CommandStackTest.php index 620e1668c..75e454053 100644 --- a/tests/unit/Task/CommandStackTest.php +++ b/tests/unit/Task/CommandStackTest.php @@ -1,8 +1,16 @@ container = Config::getContainer(); + } + public function testExecStackExecutableIsTrimmedFromCommand() { $commandStack = Stub::make('Robo\Task\CommandStack', array( diff --git a/tests/unit/Task/ComposerTest.php b/tests/unit/Task/ComposerTest.php index 108c93263..38ef3c57f 100644 --- a/tests/unit/Task/ComposerTest.php +++ b/tests/unit/Task/ComposerTest.php @@ -1,9 +1,10 @@ baseComposer = test::double('Robo\Task\Composer\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Composer\loadTasks::getComposerServices()); } // tests public function testComposerInstall() { $composer = test::double('Robo\Task\Composer\Install', ['executeCommand' => null]); - - $this->taskComposerInstall('composer')->run(); + + $this->container->get('taskComposerInstall', ['composer'])->run(); $composer->verifyInvoked('executeCommand', ['composer install']); - $this->taskComposerInstall('composer') + $this->container->get('taskComposerInstall', ['composer']) ->preferSource() ->run(); $composer->verifyInvoked('executeCommand', ['composer install --prefer-source']); - $this->taskComposerInstall('composer') + $this->container->get('taskComposerInstall', ['composer']) ->optimizeAutoloader() ->run(); $composer->verifyInvoked('executeCommand', ['composer install --optimize-autoloader']); @@ -38,11 +41,11 @@ public function testComposerInstall() public function testComposerUpdate() { $composer = test::double('Robo\Task\Composer\Update', ['executeCommand' => null]); - - $this->taskComposerUpdate('composer')->run(); + + $this->container->get('taskComposerUpdate', ['composer'])->run(); $composer->verifyInvoked('executeCommand', ['composer update']); - $this->taskComposerUpdate('composer') + $this->container->get('taskComposerUpdate', ['composer']) ->optimizeAutoloader() ->run(); $composer->verifyInvoked('executeCommand', ['composer update --optimize-autoloader']); @@ -51,21 +54,21 @@ public function testComposerUpdate() public function testComposerDumpAutoload() { $composer = test::double('Robo\Task\Composer\DumpAutoload', ['executeCommand' => null]); - - $this->taskComposerDumpAutoload('composer')->run(); + + $this->container->get('taskComposerDumpAutoload', ['composer'])->run(); $composer->verifyInvoked('executeCommand', ['composer dump-autoload']); - $this->taskComposerDumpAutoload('composer') + $this->container->get('taskComposerDumpAutoload', ['composer']) ->noDev() ->run(); $composer->verifyInvoked('executeCommand', ['composer dump-autoload --no-dev']); - $this->taskComposerDumpAutoload('composer') + $this->container->get('taskComposerDumpAutoload', ['composer']) ->optimize() ->run(); $composer->verifyInvoked('executeCommand', ['composer dump-autoload --optimize']); - $this->taskComposerDumpAutoload('composer') + $this->container->get('taskComposerDumpAutoload', ['composer']) ->optimize() ->noDev() ->run(); @@ -75,11 +78,11 @@ public function testComposerDumpAutoload() public function testComposerInstallCommand() { verify( - $this->taskComposerInstall('composer')->getCommand() + $this->container->get('taskComposerInstall', ['composer'])->getCommand() )->equals('composer install'); verify( - $this->taskComposerInstall('composer') + $this->container->get('taskComposerInstall', ['composer']) ->noDev() ->preferDist() ->optimizeAutoloader() @@ -90,18 +93,18 @@ public function testComposerInstallCommand() public function testComposerUpdateCommand() { verify( - $this->taskComposerUpdate('composer')->getCommand() + $this->container->get('taskComposerUpdate', ['composer'])->getCommand() )->equals('composer update'); verify( - $this->taskComposerUpdate('composer') + $this->container->get('taskComposerUpdate', ['composer']) ->noDev() ->preferDist() ->getCommand() )->equals('composer update --prefer-dist --no-dev'); verify( - $this->taskComposerUpdate('composer') + $this->container->get('taskComposerUpdate', ['composer']) ->noDev() ->preferDist() ->optimizeAutoloader() @@ -112,27 +115,27 @@ public function testComposerUpdateCommand() public function testComposerDumpAutoloadCommand() { verify( - $this->taskComposerDumpAutoload('composer')->getCommand() + $this->container->get('taskComposerDumpAutoload', ['composer'])->getCommand() )->equals('composer dump-autoload'); verify( - $this->taskComposerDumpAutoload('composer') + $this->container->get('taskComposerDumpAutoload', ['composer']) ->noDev() ->getCommand() )->equals('composer dump-autoload --no-dev'); verify( - $this->taskComposerDumpAutoload('composer') + $this->container->get('taskComposerDumpAutoload', ['composer']) ->optimize() ->getCommand() )->equals('composer dump-autoload --optimize'); verify( - $this->taskComposerDumpAutoload('composer') + $this->container->get('taskComposerDumpAutoload', ['composer']) ->optimize() ->noDev() ->getCommand() )->equals('composer dump-autoload --optimize --no-dev'); } -} \ No newline at end of file +} diff --git a/tests/unit/Task/ExecTaskTest.php b/tests/unit/Task/ExecTaskTest.php index 3ca6b6e06..39dff9859 100644 --- a/tests/unit/Task/ExecTaskTest.php +++ b/tests/unit/Task/ExecTaskTest.php @@ -1,9 +1,11 @@ 0 ]); test::double('Robo\Task\Base\Exec', ['getOutput' => new \Symfony\Component\Console\Output\NullOutput()]); + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Base\loadTasks::getBaseServices()); } public function testExec() { - $result = $this->taskExec('ls')->run(); + $result = $this->container->get('taskExec', ['ls'])->run(); $this->process->verifyInvoked('run'); verify($result->getMessage())->equals('Hello world'); verify($result->getExitCode())->equals(0); @@ -30,7 +34,7 @@ public function testExec() public function testExecInBackground() { - $result = $this->taskExec('ls')->background()->run(); + $result = $this->container->get('taskExec', ['ls'])->background()->run(); $this->process->verifyInvoked('start'); $this->process->verifyNeverInvoked('run'); verify('exit code was not received', $result->getExitCode())->notEquals(100); @@ -38,12 +42,12 @@ public function testExecInBackground() public function testGetCommand() { - verify($this->taskExec('ls')->getCommand())->equals('ls'); + verify($this->container->get('taskExec', ['ls'])->getCommand())->equals('ls'); } public function testExecStack() { - $this->taskExecStack() + $this->container->get('taskExecStack') ->exec('ls') ->exec('cd /') ->exec('cd home') @@ -53,11 +57,11 @@ public function testExecStack() public function testExecStackCommand() { - verify($this->taskExecStack() + verify($this->container->get('taskExecStack') ->exec('ls') ->exec('cd /') ->exec('cd home') ->getCommand() )->equals('ls && cd / && cd home'); } -}; \ No newline at end of file +}; diff --git a/tests/unit/Task/GitTest.php b/tests/unit/Task/GitTest.php index 7225a4d43..54ce03c88 100644 --- a/tests/unit/Task/GitTest.php +++ b/tests/unit/Task/GitTest.php @@ -1,10 +1,12 @@ new \AspectMock\Proxy\Anything(), 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Vcs\loadTasks::getVcsServices()); } // tests public function testGitStackRun() { - $this->taskGitStack('git')->stopOnFail()->add('-A')->pull()->run(); + $this->container->get('taskGitStack', ['git'])->stopOnFail()->add('-A')->pull()->run(); $this->git->verifyInvoked('executeCommand', ['git add -A']); $this->git->verifyInvoked('executeCommand', ['git pull']); - $this->taskGitStack('git')->add('-A')->pull()->run(); + $this->container->get('taskGitStack', ['git'])->add('-A')->pull()->run(); $this->git->verifyInvoked('executeCommand', ['git add -A && git pull']); } public function testGitStackCommands() { verify( - $this->taskGitStack() + $this->container->get('taskGitStack') ->cloneRepo('http://github.com/Codegyre/Robo') ->pull() ->add('-A') @@ -42,4 +46,4 @@ public function testGitStackCommands() ->getCommand() )->equals("git clone http://github.com/Codegyre/Robo && git pull && git add -A && git commit -m 'changed' && git push && git tag 0.6.0 && git push origin 0.6.0"); } -} \ No newline at end of file +} diff --git a/tests/unit/Task/GulpTest.php b/tests/unit/Task/GulpTest.php index 60cfb3e26..18a238b7a 100644 --- a/tests/unit/Task/GulpTest.php +++ b/tests/unit/Task/GulpTest.php @@ -1,9 +1,10 @@ baseGulp = test::double('Robo\Task\Gulp\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Gulp\loadTasks::getGulpServices()); } // tests @@ -24,63 +27,63 @@ public function testGulpRun() if ($isWindows) { verify( - $this->taskGulpRun('default','gulp')->getCommand() + $this->container->get('taskGulpRun', ['default','gulp'])->getCommand() )->equals('gulp "default"'); - + verify( - $this->taskGulpRun('another','gulp')->getCommand() + $this->container->get('taskGulpRun', ['another','gulp'])->getCommand() )->equals('gulp "another"'); verify( - $this->taskGulpRun('anotherWith weired!("\') Chars','gulp')->getCommand() + $this->container->get('taskGulpRun', ['anotherWith weired!("\') Chars','gulp'])->getCommand() )->equals('gulp "anotherWith weired!(\"\') Chars"'); verify( - $this->taskGulpRun('default','gulp')->silent()->getCommand() + $this->container->get('taskGulpRun', ['default','gulp'])->silent()->getCommand() )->equals('gulp "default" --silent'); verify( - $this->taskGulpRun('default','gulp')->noColor()->getCommand() + $this->container->get('taskGulpRun', ['default','gulp'])->noColor()->getCommand() )->equals('gulp "default" --no-color'); verify( - $this->taskGulpRun('default','gulp')->color()->getCommand() + $this->container->get('taskGulpRun', ['default','gulp'])->color()->getCommand() )->equals('gulp "default" --color'); verify( - $this->taskGulpRun('default','gulp')->simple()->getCommand() + $this->container->get('taskGulpRun', ['default','gulp'])->simple()->getCommand() )->equals('gulp "default" --tasks-simple'); } else { verify( - $this->taskGulpRun('default','gulp')->getCommand() + $this->container->get('taskGulpRun', ['default','gulp'])->getCommand() )->equals('gulp \'default\''); - + verify( - $this->taskGulpRun('another','gulp')->getCommand() + $this->container->get('taskGulpRun', ['another','gulp'])->getCommand() )->equals('gulp \'another\''); verify( - $this->taskGulpRun('anotherWith weired!("\') Chars','gulp')->getCommand() + $this->container->get('taskGulpRun', ['anotherWith weired!("\') Chars','gulp'])->getCommand() )->equals("gulp 'anotherWith weired!(\"'\\'') Chars'"); verify( - $this->taskGulpRun('default','gulp')->silent()->getCommand() + $this->container->get('taskGulpRun', ['default','gulp'])->silent()->getCommand() )->equals('gulp \'default\' --silent'); verify( - $this->taskGulpRun('default','gulp')->noColor()->getCommand() + $this->container->get('taskGulpRun', ['default','gulp'])->noColor()->getCommand() )->equals('gulp \'default\' --no-color'); verify( - $this->taskGulpRun('default','gulp')->color()->getCommand() + $this->container->get('taskGulpRun', ['default','gulp'])->color()->getCommand() )->equals('gulp \'default\' --color'); verify( - $this->taskGulpRun('default','gulp')->simple()->getCommand() + $this->container->get('taskGulpRun', ['default','gulp'])->simple()->getCommand() )->equals('gulp \'default\' --tasks-simple'); } } -} \ No newline at end of file +} diff --git a/tests/unit/Task/NpmTest.php b/tests/unit/Task/NpmTest.php index 5fca31110..751b260d3 100644 --- a/tests/unit/Task/NpmTest.php +++ b/tests/unit/Task/NpmTest.php @@ -1,9 +1,10 @@ baseNpm = test::double('Robo\Task\Npm\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Npm\loadTasks::getNpmServices()); } + // tests public function testNpmInstall() { $npm = test::double('Robo\Task\Npm\Install', ['executeCommand' => null]); - $this->taskNpmInstall('npm')->run(); + $this->container->get('taskNpmInstall', ['npm'])->run(); $npm->verifyInvoked('executeCommand', ['npm install']); } public function testNpmUpdate() { $npm = test::double('Robo\Task\Npm\Update', ['executeCommand' => null]); - $this->taskNpmUpdate('npm')->run(); + $this->container->get('taskNpmUpdate', ['npm'])->run(); $npm->verifyInvoked('executeCommand', ['npm update']); } public function testNpmInstallCommand() { verify( - $this->taskNpmInstall('npm')->getCommand() + $this->container->get('taskNpmInstall', ['npm'])->getCommand() )->equals('npm install'); verify( - $this->taskNpmInstall('npm')->getCommand() + $this->container->get('taskNpmInstall', ['npm'])->getCommand() )->equals('npm install'); verify( - $this->taskNpmInstall('npm') + $this->container->get('taskNpmInstall', ['npm']) ->noDev() ->getCommand() )->equals('npm install --production'); } -} \ No newline at end of file +} diff --git a/tests/unit/Task/PHPServerTest.php b/tests/unit/Task/PHPServerTest.php index b63aeeda9..ff44d2b0a 100644 --- a/tests/unit/Task/PHPServerTest.php +++ b/tests/unit/Task/PHPServerTest.php @@ -1,9 +1,12 @@ 0 ]); test::double('Robo\Task\Development\PhpServer', ['getOutput' => new \Symfony\Component\Console\Output\NullOutput()]); + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Development\loadTasks::getDevelopmentServices()); } public function testServerBackgroundRun() { - $this->taskServer('8000')->background()->run(); + $this->container->get('taskServer', ['8000'])->background()->run(); $this->process->verifyInvoked('start'); } public function testServerRun() { - $this->taskServer('8000')->run(); + $this->container->get('taskServer', ['8000'])->run(); $this->process->verifyInvoked('run'); } @@ -41,7 +46,7 @@ public function testServerCommand() } verify( - $this->taskServer('8000') + $this->container->get('taskServer', ['8000']) ->host('127.0.0.1') ->dir('web') ->getCommand() diff --git a/tests/unit/Task/PHPUnitTest.php b/tests/unit/Task/PHPUnitTest.php index c1783ea6c..f1cc4190a 100644 --- a/tests/unit/Task/PHPUnitTest.php +++ b/tests/unit/Task/PHPUnitTest.php @@ -1,9 +1,11 @@ null, 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Testing\loadTasks::getTestingServices()); } // tests @@ -22,14 +26,14 @@ public function testPhpUnitRun() { $isWindows = defined('PHP_WINDOWS_VERSION_MAJOR'); $command = $isWindows ? 'call vendor/bin/phpunit' : 'vendor/bin/phpunit'; - - $this->taskPHPUnit()->run(); + + $this->container->get('taskPHPUnit')->run(); $this->phpunit->verifyInvoked('executeCommand', [$command]); } public function testPHPUnitCommand() { - $task = $this->taskPHPUnit('phpunit') + $task = $this->container->get('taskPHPUnit', ['phpunit']) ->bootstrap('bootstrap.php') ->filter('Model') ->group('important') @@ -40,4 +44,4 @@ public function testPHPUnitCommand() $this->phpunit->verifyInvoked('executeCommand', ['phpunit --bootstrap bootstrap.php --filter Model --group important --log-junit result.xml --debug']); } -} \ No newline at end of file +} diff --git a/tests/unit/Task/ParallelExecTest.php b/tests/unit/Task/ParallelExecTest.php index cbb398974..a9b544dc3 100644 --- a/tests/unit/Task/ParallelExecTest.php +++ b/tests/unit/Task/ParallelExecTest.php @@ -1,12 +1,14 @@ 'Hello world', 'getExitCode' => 0 ]); + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Base\loadTasks::getBaseServices()); } public function testParallelExec() { - $result = $this->taskParallelExec() + $result = $this->container->get('taskParallelExec') ->process('ls 1') ->process('ls 2') ->process('ls 3') @@ -37,4 +41,4 @@ public function testParallelExec() $this->guy->seeInOutput("3 processes finished"); } -} \ No newline at end of file +} diff --git a/tests/unit/Task/PhpspecTest.php b/tests/unit/Task/PhpspecTest.php index ad52916be..798d7e0ad 100644 --- a/tests/unit/Task/PhpspecTest.php +++ b/tests/unit/Task/PhpspecTest.php @@ -1,9 +1,11 @@ null, 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Testing\loadTasks::getTestingServices()); } // tests public function testPhpSpecRun() { - $this->taskPhpspec('phpspec')->run(); + $this->container->get('taskPhpspec', ['phpspec'])->run(); $this->phpspec->verifyInvoked('executeCommand', ['phpspec run']); } public function testPHPSpecCommand() { - $task = $this->taskPhpspec('phpspec') + $task = $this->container->get('taskPhpspec', ['phpspec']) ->stopOnFail() ->noCodeGeneration() ->quiet() @@ -39,4 +43,4 @@ public function testPHPSpecCommand() $this->phpspec->verifyInvoked('executeCommand', ['phpspec run --stop-on-failure --no-code-generation --quiet -vv --no-ansi --no-interaction --format pretty']); } -} \ No newline at end of file +} diff --git a/tests/unit/Task/RsyncTest.php b/tests/unit/Task/RsyncTest.php index 10cf92ac8..545315188 100644 --- a/tests/unit/Task/RsyncTest.php +++ b/tests/unit/Task/RsyncTest.php @@ -1,19 +1,28 @@ container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Remote\loadTasks::getRemoteServices()); + } + // tests public function testRsync() { verify( - $this->taskRsync() + $this->container->get('taskRsync') ->fromPath('src/') ->toHost('localhost') ->toUser('dev') diff --git a/tests/unit/Task/SemVerTest.php b/tests/unit/Task/SemVerTest.php index 4bf66f548..599455d53 100644 --- a/tests/unit/Task/SemVerTest.php +++ b/tests/unit/Task/SemVerTest.php @@ -1,15 +1,22 @@ container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Development\loadTasks::getDevelopmentServices()); + } public function testSemver() { $semver = test::double('Robo\Task\Development\SemVer', ['dump' => null]); - $res = $this->taskSemVer() + $res = $this->container->get('taskSemVer') ->increment('major') ->prerelease('RC') ->increment('patch') @@ -24,7 +31,7 @@ public function testThrowsExceptionWhenSemverFileNotWriteable() 'Robo\Exception\TaskException', '/Failed to write semver file./' ); - $this->taskSemVer('/.semver') + $this->container->get('taskSemVer', ['/.semver']) ->increment('major') ->run(); } diff --git a/tests/unit/Task/SshTest.php b/tests/unit/Task/SshTest.php index 5fac8d7c8..d6f358b32 100644 --- a/tests/unit/Task/SshTest.php +++ b/tests/unit/Task/SshTest.php @@ -1,14 +1,23 @@ container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Remote\loadTasks::getRemoteServices()); + } + // tests public function testBasicCommand() { verify( - $this->taskSshExec('remote.example.com', 'user') + $this->container->get('taskSshExec', ['remote.example.com', 'user']) ->exec('ls -la') ->exec('chmod g+x logs') ->getCommand() @@ -18,7 +27,7 @@ public function testBasicCommand() public function testStopOnFail() { verify( - $this->taskSshExec('remote.example.com', 'user') + $this->container->get('taskSshExec', ['remote.example.com', 'user']) ->stopOnFail(false) ->exec('one') ->exec('two') @@ -33,24 +42,24 @@ public function testWorkingDirectoryStaticConfiguration() { \Robo\Task\Remote\Ssh::configure('remoteDir', '/some-dir'); verify( - $this->taskSshExec('remote.example.com', 'user') + $this->container->get('taskSshExec', ['remote.example.com', 'user']) ->exec('echo test') ->getCommand() )->equals("ssh user@remote.example.com 'cd \"/some-dir\" && echo test'"); verify( - $this->taskSshExec('remote.example.com', 'user') + $this->container->get('taskSshExec', ['remote.example.com', 'user']) ->remoteDir('/other-dir') ->exec('echo test') ->getCommand() )->equals("ssh user@remote.example.com 'cd \"/other-dir\" && echo test'"); verify( - $this->taskSshExec('remote.example.com', 'user') + $this->container->get('taskSshExec', ['remote.example.com', 'user']) ->exec('echo test') ->getCommand() )->equals("ssh user@remote.example.com 'cd \"/some-dir\" && echo test'"); \Robo\Task\Remote\Ssh::configure('remoteDir', null); verify( - $this->taskSshExec('remote.example.com', 'user') + $this->container->get('taskSshExec', ['remote.example.com', 'user']) ->exec('echo test') ->getCommand() )->equals("ssh user@remote.example.com 'echo test'"); diff --git a/tests/unit/Task/SvnTest.php b/tests/unit/Task/SvnTest.php index 925ce78b8..686ae580c 100644 --- a/tests/unit/Task/SvnTest.php +++ b/tests/unit/Task/SvnTest.php @@ -1,10 +1,12 @@ container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Vcs\loadTasks::getVcsServices()); + $this->svn = test::double('Robo\Task\Vcs\SvnStack', [ 'executeCommand' => new \AspectMock\Proxy\Anything(), - 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() + 'getOutput' => new \Symfony\Component\Console\Output\NullOutput(), + 'logger' => $this->container->get('logger'), ]); } @@ -28,7 +34,7 @@ public function testSvnStackRun() public function testSvnStackCommands() { verify( - $this->taskSvnStack('guest', 'foo') + $this->container->get('taskSvnStack', ['guest', 'foo']) ->checkout('svn://server/trunk') ->update() ->add()