From cea31294f4c861f5dd63c842d73242b27e106478 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Mon, 7 Mar 2016 08:19:49 -0800 Subject: [PATCH 01/34] Create a task assembly step, and use it in all loadTasks. This allows us to reduce internal coupling, and also support temporary and simulated tasks in a uniform way. --- composer.lock | 10 ++--- src/Application.php | 33 +++++++++++++- src/Common/TaskIO.php | 25 ++++++++--- src/Config.php | 15 +++++++ src/Log/RoboLogLevel.php | 11 +++++ src/Log/RoboLogStyle.php | 14 ++++++ src/Log/RoboLogger.php | 1 + src/Runner.php | 3 +- src/Task/ApiGen/loadTasks.php | 4 +- src/Task/Archive/loadTasks.php | 10 ++++- src/Task/Assets/loadTasks.php | 20 +++++++-- src/Task/Base/loadTasks.php | 27 +++++++++--- src/Task/Bower/loadTasks.php | 12 ++++-- src/Task/Composer/loadTasks.php | 17 ++++++-- src/Task/Development/loadTasks.php | 37 ++++++++++++---- src/Task/Docker/loadTasks.php | 44 ++++++++++++++----- src/Task/File/loadTasks.php | 20 +++++++-- src/Task/FileSystem/loadTasks.php | 36 ++++++++++++---- src/Task/Simulator.php | 64 ++++++++++++++++++++++++++++ src/TaskAssembler.php | 64 ++++++++++++++++++++++++++++ src/TaskSupport.php | 19 +++++++++ src/Tasklib.php | 3 ++ tests/_helpers/CliHelper.php | 5 +++ tests/unit/Task/ApiGenTest.php | 3 ++ tests/unit/Task/BowerTest.php | 5 ++- tests/unit/Task/CodeceptionTest.php | 2 +- tests/unit/Task/ComposerTest.php | 11 +++-- tests/unit/Task/ExecTaskTest.php | 5 ++- tests/unit/Task/GitTest.php | 5 ++- tests/unit/Task/GulpTest.php | 9 ++-- tests/unit/Task/NpmTest.php | 5 ++- tests/unit/Task/PHPServerTest.php | 3 ++ tests/unit/Task/PHPUnitTest.php | 7 ++- tests/unit/Task/ParallelExecTest.php | 11 +++-- tests/unit/Task/PhpspecTest.php | 5 ++- tests/unit/Task/RsyncTest.php | 8 ++++ tests/unit/Task/SemVerTest.php | 6 +++ tests/unit/Task/SshTest.php | 7 +++ tests/unit/Task/SvnTest.php | 3 ++ 39 files changed, 506 insertions(+), 83 deletions(-) create mode 100644 src/Log/RoboLogLevel.php create mode 100644 src/Task/Simulator.php create mode 100644 src/TaskAssembler.php create mode 100644 src/TaskSupport.php diff --git a/composer.lock b/composer.lock index ca47aabdb..2ffea8d67 100644 --- a/composer.lock +++ b/composer.lock @@ -9,16 +9,16 @@ "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,7 @@ } ], "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": "psr/log", diff --git a/src/Application.php b/src/Application.php index ad6356869..2c01fe4f6 100644 --- a/src/Application.php +++ b/src/Application.php @@ -9,10 +9,36 @@ class Application extends SymfonyApplication { + /** + * @var \Robo\TaskAssembler + */ + protected $taskAssembler; + + 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 setTaskAssembler($taskAssembler) + { + $this->taskAssembler = $taskAssembler; + } + + public function taskAssembler() + { + return $this->taskAssembler; + } public function addCommandsFromClass($className, $passThrough = null) { $roboTasks = new $className; + if ($roboTasks instanceof \Robo\Tasks) { + $roboTasks->setTaskAssembler($this->taskAssembler); + } $commandNames = array_filter(get_class_methods($className), function($m) { return !in_array($m, ['__construct']); @@ -28,6 +54,11 @@ 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); + // Avoid making taskAssembler depend on Config class. + Config::service('taskAssembler')->setSimulated(Config::isSimulated()); $res = call_user_func_array([$roboTasks, $commandName], $args); if (is_int($res)) exit($res); @@ -97,4 +128,4 @@ public function addInitRoboFileCommand($roboFile, $roboClass) }); $this->add($createRoboFile); } -} \ No newline at end of file +} diff --git a/src/Common/TaskIO.php b/src/Common/TaskIO.php index 150cdf124..86842f2b8 100644 --- a/src/Common/TaskIO.php +++ b/src/Common/TaskIO.php @@ -14,6 +14,21 @@ */ trait TaskIO { + /** + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + + public function setLogger($logger) + { + $this->logger = $logger; + } + + public function logger() + { + return $this->logger ?: Config::logger(); + } + /** * Print information about a task in progress. * @@ -31,7 +46,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 +63,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 +74,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 +85,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 +94,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..bf470db7d 100644 --- a/src/Config.php +++ b/src/Config.php @@ -12,6 +12,8 @@ class Config { + protected static $simulated; + /** * The currently active container object, or NULL if not initialized yet. * @@ -53,6 +55,9 @@ public static function createContainer($input = null) $container ->register('resultPrinter', 'Robo\Log\ResultPrinter') ->addArgument(new Reference('logger')); + $container + ->register('taskAssembler', 'Robo\TaskAssembler') + ->addArgument(new Reference('logger')); return $container; } @@ -193,4 +198,14 @@ public static function set($key, $value) { static::$container->setParameter($key, $value); } + + public static function setGlobalOptions($input) + { + static::$simulated = $input->getOption('simulate'); + } + + public static function isSimulated() + { + return static::$simulated; + } } 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..ea690e582 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -80,7 +80,7 @@ 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); @@ -92,6 +92,7 @@ public function execute($input = null) } $app = new Application('Robo', self::VERSION); + $app->setTaskAssembler(Config::service('taskAssembler')); if (!$this->loadRoboFile()) { $this->yell("Robo is not initialized here. Please run `robo init` to create a new RoboFile", 40, 'yellow'); diff --git a/src/Task/ApiGen/loadTasks.php b/src/Task/ApiGen/loadTasks.php index 91099de6e..4202dc1e1 100644 --- a/src/Task/ApiGen/loadTasks.php +++ b/src/Task/ApiGen/loadTasks.php @@ -1,7 +1,7 @@ taskAssembler()->assemble( + '\Robo\Task\Archive\Pack', + [$filename] + ); } /** @@ -21,6 +24,9 @@ protected function taskPack($filename) */ protected function taskExtract($filename) { - return new Extract($filename); + return $this->taskAssembler()->assemble( + '\Robo\Task\Archive\Extract', + [$filename] + ); } } diff --git a/src/Task/Assets/loadTasks.php b/src/Task/Assets/loadTasks.php index 93a2a695d..6dc16fa9e 100644 --- a/src/Task/Assets/loadTasks.php +++ b/src/Task/Assets/loadTasks.php @@ -9,7 +9,10 @@ trait loadTasks */ protected function taskMinify($input) { - return new Minify($input); + return $this->taskAssembler()->assemble( + '\Robo\Task\Assets\Minify', + [$input] + ); } /** @@ -18,7 +21,10 @@ protected function taskMinify($input) */ protected function taskImageMinify($input) { - return new ImageMinify($input); + return $this->taskAssembler()->assemble( + '\Robo\Task\Assets\ImageMinify', + [$input] + ); } /** @@ -27,7 +33,10 @@ protected function taskImageMinify($input) */ protected function taskLess($input) { - return new Less($input); + return $this->taskAssembler()->assemble( + '\Robo\Task\Assets\Less', + [$input] + ); } /** @@ -36,6 +45,9 @@ protected function taskLess($input) */ protected function taskScss($input) { - return new Scss($input); + return $this->taskAssembler()->assemble( + '\Robo\Task\Assets\Scss', + [$input] + ); } } diff --git a/src/Task/Base/loadTasks.php b/src/Task/Base/loadTasks.php index b9818bfb2..cdeb14f4d 100644 --- a/src/Task/Base/loadTasks.php +++ b/src/Task/Base/loadTasks.php @@ -9,12 +9,18 @@ trait loadTasks */ protected function taskExec($command) { - return new Exec($command); + return $this->taskAssembler()->assemble( + '\Robo\Task\Base\Exec', + [$command] + ); } protected function taskExecStack() { - return new ExecStack(); + return $this->taskAssembler()->assemble( + '\Robo\Task\Base\ExecStack', + [] + ); } /** @@ -22,7 +28,10 @@ protected function taskExecStack() */ protected function taskParallelExec() { - return new ParallelExec(); + return $this->taskAssembler()->assemble( + '\Robo\Task\Base\ParallelExec', + [] + ); } /** @@ -31,7 +40,10 @@ protected function taskParallelExec() */ protected function taskSymfonyCommand($command) { - return new SymfonyCommand($command); + return $this->taskAssembler()->assemble( + '\Robo\Task\Base\SymfonyCommand', + [$command] + ); } /** @@ -39,6 +51,9 @@ protected function taskSymfonyCommand($command) */ protected function taskWatch() { - return new Watch($this); + return $this->taskAssembler()->assemble( + '\Robo\Task\Base\Watch', + [$this] + ); } -} \ No newline at end of file +} diff --git a/src/Task/Bower/loadTasks.php b/src/Task/Bower/loadTasks.php index 786df0fef..79e7582a2 100644 --- a/src/Task/Bower/loadTasks.php +++ b/src/Task/Bower/loadTasks.php @@ -9,7 +9,10 @@ trait loadTasks */ protected function taskBowerInstall($pathToBower = null) { - return new Install($pathToBower); + return $this->taskAssembler()->assemble( + '\Robo\Task\Bower\Install', + [$pathToBower] + ); } /** @@ -18,7 +21,10 @@ protected function taskBowerInstall($pathToBower = null) */ protected function taskBowerUpdate($pathToBower = null) { - return new Update($pathToBower); + return $this->taskAssembler()->assemble( + '\Robo\Task\Bower\Update', + [$pathToBower] + ); } -} \ No newline at end of file +} diff --git a/src/Task/Composer/loadTasks.php b/src/Task/Composer/loadTasks.php index b270c696d..553895560 100644 --- a/src/Task/Composer/loadTasks.php +++ b/src/Task/Composer/loadTasks.php @@ -9,7 +9,10 @@ trait loadTasks */ protected function taskComposerInstall($pathToComposer = null) { - return new Install($pathToComposer); + return $this->taskAssembler()->assemble( + '\Robo\Task\Composer\Install', + [$pathToComposer] + ); } /** @@ -18,7 +21,10 @@ protected function taskComposerInstall($pathToComposer = null) */ protected function taskComposerUpdate($pathToComposer = null) { - return new Update($pathToComposer); + return $this->taskAssembler()->assemble( + '\Robo\Task\Composer\Update', + [$pathToComposer] + ); } /** @@ -27,7 +33,10 @@ protected function taskComposerUpdate($pathToComposer = null) */ protected function taskComposerDumpAutoload($pathToComposer = null) { - return new DumpAutoload($pathToComposer); + return $this->taskAssembler()->assemble( + '\Robo\Task\Composer\DumpAutoload', + [$pathToComposer] + ); } -} \ No newline at end of file +} diff --git a/src/Task/Development/loadTasks.php b/src/Task/Development/loadTasks.php index 2dfc7cb07..798d1615c 100644 --- a/src/Task/Development/loadTasks.php +++ b/src/Task/Development/loadTasks.php @@ -9,7 +9,10 @@ trait loadTasks */ protected function taskChangelog($filename = 'CHANGELOG.md') { - return new Changelog($filename); + return $this->taskAssembler()->assemble( + '\Robo\Task\Development\Changelog', + [$filename] + ); } /** @@ -18,7 +21,10 @@ protected function taskChangelog($filename = 'CHANGELOG.md') */ protected function taskGenDoc($filename) { - return new GenerateMarkdownDoc($filename); + return $this->taskAssembler()->assemble( + '\Robo\Task\Development\GenerateMarkdownDoc', + [$filename] + ); } /** @@ -27,7 +33,10 @@ protected function taskGenDoc($filename) */ protected function taskSemVer($pathToSemVer = '.semver') { - return new SemVer($pathToSemVer); + return $this->taskAssembler()->assemble( + '\Robo\Task\Development\SemVer', + [$pathToSemVer] + ); } /** @@ -36,7 +45,10 @@ protected function taskSemVer($pathToSemVer = '.semver') */ protected function taskServer($port = 8000) { - return new PhpServer($port); + return $this->taskAssembler()->assemble( + '\Robo\Task\Development\PhpServer', + [$port] + ); } /** @@ -45,7 +57,10 @@ protected function taskServer($port = 8000) */ protected function taskPackPhar($filename) { - return new PackPhar($filename); + return $this->taskAssembler()->assemble( + '\Robo\Task\Development\PackPhar', + [$filename] + ); } /** @@ -54,7 +69,10 @@ protected function taskPackPhar($filename) */ protected function taskGitHubRelease($tag) { - return new GitHubRelease($tag); + return $this->taskAssembler()->assemble( + '\Robo\Task\Development\GitHubRelease', + [$tag] + ); } /** @@ -63,6 +81,9 @@ protected function taskGitHubRelease($tag) */ protected function taskOpenBrowser($url) { - return new OpenBrowser($url); + return $this->taskAssembler()->assemble( + '\Robo\Task\Development\OpenBrowser', + [$url] + ); } -} \ No newline at end of file +} diff --git a/src/Task/Docker/loadTasks.php b/src/Task/Docker/loadTasks.php index 10d0cf6e1..7c8c67c1d 100644 --- a/src/Task/Docker/loadTasks.php +++ b/src/Task/Docker/loadTasks.php @@ -1,39 +1,63 @@ -taskAssembler()->assemble( + '\Robo\Task\Docker\Run', + [$image] + ); } protected function taskDockerPull($image) { - return new Pull($image); + return $this->taskAssembler()->assemble( + '\Robo\Task\Docker\Pull', + [$image] + ); } protected function taskDockerBuild($path = '.') { - return new Build($path); + return $this->taskAssembler()->assemble( + '\Robo\Task\Docker\Build', + [$path] + ); } protected function taskDockerStop($cidOrResult) { - return new Stop($cidOrResult); + return $this->taskAssembler()->assemble( + '\Robo\Task\Docker\Stop', + [$cidOrResult] + ); } protected function taskDockerCommit($cidOrResult) { - return new Commit($cidOrResult); + return $this->taskAssembler()->assemble( + '\Robo\Task\Docker\Commit', + [$cidOrResult] + ); } protected function taskDockerStart($cidOrResult) { - return new Start($cidOrResult); + return $this->taskAssembler()->assemble( + '\Robo\Task\Docker\Start', + [$cidOrResult] + ); } protected function taskDockerRemove($cidOrResult) { - return new Remove($cidOrResult); + return $this->taskAssembler()->assemble( + '\Robo\Task\Docker\Remove', + [$cidOrResult] + ); } protected function taskDockerExec($cidOrResult) { - return new Exec($cidOrResult); + return $this->taskAssembler()->assemble( + '\Robo\Task\Docker\Exec', + [$cidOrResult] + ); } -} \ No newline at end of file +} diff --git a/src/Task/File/loadTasks.php b/src/Task/File/loadTasks.php index 0d70f5b6b..86d1695aa 100644 --- a/src/Task/File/loadTasks.php +++ b/src/Task/File/loadTasks.php @@ -11,7 +11,10 @@ trait loadTasks */ protected function taskConcat($files) { - return new Concat($files); + return $this->taskAssembler()->assemble( + '\Robo\Task\File\Concat', + [$files] + ); } /** @@ -20,7 +23,10 @@ protected function taskConcat($files) */ protected function taskReplaceInFile($file) { - return new Replace($file); + return $this->taskAssembler()->assemble( + '\Robo\Task\File\Replace', + [$file] + ); } /** @@ -29,7 +35,10 @@ protected function taskReplaceInFile($file) */ protected function taskWriteToFile($file) { - return new Write($file); + return $this->taskAssembler()->assemble( + '\Robo\Task\File\Write', + [$file] + ); } /** @@ -40,6 +49,9 @@ protected function taskWriteToFile($file) */ protected function taskTmpFile($filename = 'tmp', $extension = '', $baseDir = '', $includeRandomPart = true) { - return Temporary::wrap(new TmpFile($filename, $extension, $baseDir, $includeRandomPart)); + return $this->taskAssembler()->assemble( + '\Robo\Task\File\TmpFile', + [$filename, $extension, $baseDir, $includeRandomPart] + ); } } diff --git a/src/Task/FileSystem/loadTasks.php b/src/Task/FileSystem/loadTasks.php index 80ccb4961..348b2e4e9 100644 --- a/src/Task/FileSystem/loadTasks.php +++ b/src/Task/FileSystem/loadTasks.php @@ -1,8 +1,6 @@ taskAssembler()->assemble( + '\Robo\Task\FileSystem\CleanDir', + [$dirs] + ); } /** @@ -20,7 +21,10 @@ protected function taskCleanDir($dirs) */ protected function taskDeleteDir($dirs) { - return new DeleteDir($dirs); + return $this->taskAssembler()->assemble( + '\Robo\Task\FileSystem\DeleteDir', + [$dirs] + ); } /** @@ -31,7 +35,10 @@ protected function taskDeleteDir($dirs) */ protected function taskTmpDir($prefix = 'tmp', $base = '', $includeRandomPart = true) { - return Temporary::wrap(new TmpDir($prefix, $base, $includeRandomPart)); + return $this->taskAssembler()->assemble( + '\Robo\Task\FileSystem\TmpDir', + [$prefix, $base, $includeRandomPart] + ); } /** @@ -40,7 +47,10 @@ protected function taskTmpDir($prefix = 'tmp', $base = '', $includeRandomPart = */ protected function taskCopyDir($dirs) { - return new CopyDir($dirs); + return $this->taskAssembler()->assemble( + '\Robo\Task\FileSystem\CopyDir', + [$dirs] + ); } /** @@ -49,7 +59,10 @@ protected function taskCopyDir($dirs) */ protected function taskMirrorDir($dirs) { - return new MirrorDir($dirs); + return $this->taskAssembler()->assemble( + '\Robo\Task\FileSystem\MirrorDir', + [$dirs] + ); } /** @@ -58,7 +71,10 @@ protected function taskMirrorDir($dirs) */ protected function taskFlattenDir($dirs) { - return new FlattenDir($dirs); + return $this->taskAssembler()->assemble( + '\Robo\Task\FileSystem\FlattenDir', + [$dirs] + ); } /** @@ -66,6 +82,8 @@ protected function taskFlattenDir($dirs) */ protected function taskFilesystemStack() { - return new FilesystemStack(); + return $this->taskAssembler()->assemble( + '\Robo\Task\FileSystem\FilesystemStack' + ); } } diff --git a/src/Task/Simulator.php b/src/Task/Simulator.php new file mode 100644 index 000000000..5deb24b62 --- /dev/null +++ b/src/Task/Simulator.php @@ -0,0 +1,64 @@ +task = $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), + 'callchain' => $callchain, + ] + ) + ); + return Result::success($this); + } + + protected function formatParameters($action) { + $parameterList = array_map( + function($item) { + if (is_array($item) || is_object($item)) { + return var_export($item, true); + } + if (is_string($item)) { + return "'$item'"; + } + return $item; + }, + $action + ); + return implode(', ', $parameterList); + } + +} diff --git a/src/TaskAssembler.php b/src/TaskAssembler.php new file mode 100644 index 000000000..04ca9971e --- /dev/null +++ b/src/TaskAssembler.php @@ -0,0 +1,64 @@ +logger = $logger; + $this->simulated = false; + } + + public function setSimulated($simulated) + { + $this->simulated = $simulated; + } + + public function isSimulated() + { + return $this->simulated; + } + + public function assemble($taskClass, $taskConstructorParameters = []) + { + $class = new \ReflectionClass($taskClass); + $task = $class->newInstanceArgs($taskConstructorParameters); + + // TODO: Would be more rigorous to have an interface for this. + if (method_exists($task, 'setLogger')) { + $task->setLogger($this->logger); + } + + // 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 its + // complete method will be called after the collection completes. + if ($task instanceof CompletionInterface) { + $task = Temporary::wrap($task); + } + + // If we are in simulated mode, then wrap the task in + // a TaskSimulator. + if ($this->isSimulated() || Config::isSimulated()) { + $task = new Simulator($task, $taskConstructorParameters); + } + + return $task; + } +} diff --git a/src/TaskSupport.php b/src/TaskSupport.php new file mode 100644 index 000000000..107dce864 --- /dev/null +++ b/src/TaskSupport.php @@ -0,0 +1,19 @@ +taskAssembler = $taskAssembler; + } + + public function taskAssembler() + { + return $this->taskAssembler; + } +} diff --git a/src/Tasklib.php b/src/Tasklib.php index ea6f77d72..12221a0af 100644 --- a/src/Tasklib.php +++ b/src/Tasklib.php @@ -3,6 +3,9 @@ trait Tasklib { + // Support methods required for 'load' traits to work. + use TaskSupport; + // collections of tasks use Collection\loadTasks; diff --git a/tests/_helpers/CliHelper.php b/tests/_helpers/CliHelper.php index 7aef50a32..4f81a2b3d 100644 --- a/tests/_helpers/CliHelper.php +++ b/tests/_helpers/CliHelper.php @@ -42,6 +42,11 @@ class CliHelper extends \Codeception\Module taskExtract as public; } + public function taskAssembler() + { + return Config::service('taskAssembler'); + } + public function seeDirFound($dir) { $this->assertTrue(is_dir($dir) && file_exists($dir), "Directory does not exist"); diff --git a/tests/unit/Task/ApiGenTest.php b/tests/unit/Task/ApiGenTest.php index adc5e378d..149d71ede 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->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); } // tests diff --git a/tests/unit/Task/BowerTest.php b/tests/unit/Task/BowerTest.php index d63cf6a98..bd50ea1dc 100644 --- a/tests/unit/Task/BowerTest.php +++ b/tests/unit/Task/BowerTest.php @@ -1,9 +1,11 @@ baseBower = test::double('Robo\Task\Bower\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); } // tests public function testBowerInstall() @@ -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..d03ac6f22 100644 --- a/tests/unit/Task/CodeceptionTest.php +++ b/tests/unit/Task/CodeceptionTest.php @@ -63,4 +63,4 @@ public function testCodeceptOptions() verify($this->taskCodecept()->json()->getCommand())->contains('--json'); } -} \ No newline at end of file +} diff --git a/tests/unit/Task/ComposerTest.php b/tests/unit/Task/ComposerTest.php index 108c93263..a6b485e34 100644 --- a/tests/unit/Task/ComposerTest.php +++ b/tests/unit/Task/ComposerTest.php @@ -1,9 +1,11 @@ baseComposer = test::double('Robo\Task\Composer\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); } // tests public function testComposerInstall() { $composer = test::double('Robo\Task\Composer\Install', ['executeCommand' => null]); - + $this->taskComposerInstall('composer')->run(); $composer->verifyInvoked('executeCommand', ['composer install']); @@ -38,7 +41,7 @@ public function testComposerInstall() public function testComposerUpdate() { $composer = test::double('Robo\Task\Composer\Update', ['executeCommand' => null]); - + $this->taskComposerUpdate('composer')->run(); $composer->verifyInvoked('executeCommand', ['composer update']); @@ -51,7 +54,7 @@ public function testComposerUpdate() public function testComposerDumpAutoload() { $composer = test::double('Robo\Task\Composer\DumpAutoload', ['executeCommand' => null]); - + $this->taskComposerDumpAutoload('composer')->run(); $composer->verifyInvoked('executeCommand', ['composer dump-autoload']); @@ -135,4 +138,4 @@ public function testComposerDumpAutoloadCommand() )->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..709aa70c7 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->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); } public function testExec() @@ -60,4 +63,4 @@ public function testExecStackCommand() ->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..80458b013 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->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); } // tests public function testGitStackRun() @@ -42,4 +45,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..720432d8c 100644 --- a/tests/unit/Task/GulpTest.php +++ b/tests/unit/Task/GulpTest.php @@ -1,9 +1,11 @@ baseGulp = test::double('Robo\Task\Gulp\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); } // tests @@ -26,7 +29,7 @@ public function testGulpRun() verify( $this->taskGulpRun('default','gulp')->getCommand() )->equals('gulp "default"'); - + verify( $this->taskGulpRun('another','gulp')->getCommand() )->equals('gulp "another"'); @@ -56,7 +59,7 @@ public function testGulpRun() verify( $this->taskGulpRun('default','gulp')->getCommand() )->equals('gulp \'default\''); - + verify( $this->taskGulpRun('another','gulp')->getCommand() )->equals('gulp \'another\''); @@ -83,4 +86,4 @@ public function testGulpRun() } } -} \ No newline at end of file +} diff --git a/tests/unit/Task/NpmTest.php b/tests/unit/Task/NpmTest.php index 5fca31110..6b6f477af 100644 --- a/tests/unit/Task/NpmTest.php +++ b/tests/unit/Task/NpmTest.php @@ -1,9 +1,11 @@ baseNpm = test::double('Robo\Task\Npm\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); } // tests public function testNpmInstall() @@ -48,4 +51,4 @@ public function testNpmInstallCommand() )->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..8e3f18613 100644 --- a/tests/unit/Task/PHPServerTest.php +++ b/tests/unit/Task/PHPServerTest.php @@ -1,9 +1,11 @@ 0 ]); test::double('Robo\Task\Development\PhpServer', ['getOutput' => new \Symfony\Component\Console\Output\NullOutput()]); + $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); } public function testServerBackgroundRun() diff --git a/tests/unit/Task/PHPUnitTest.php b/tests/unit/Task/PHPUnitTest.php index c1783ea6c..6a6f6b882 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->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); } // tests @@ -22,7 +25,7 @@ public function testPhpUnitRun() { $isWindows = defined('PHP_WINDOWS_VERSION_MAJOR'); $command = $isWindows ? 'call vendor/bin/phpunit' : 'vendor/bin/phpunit'; - + $this->taskPHPUnit()->run(); $this->phpunit->verifyInvoked('executeCommand', [$command]); } @@ -40,4 +43,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..948046c17 100644 --- a/tests/unit/Task/ParallelExecTest.php +++ b/tests/unit/Task/ParallelExecTest.php @@ -1,12 +1,14 @@ 'Hello world', 'getExitCode' => 0 ]); + $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); } public function testParallelExec() @@ -37,4 +40,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..54e42aba4 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->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); } // tests @@ -39,4 +42,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..a07522dd1 100644 --- a/tests/unit/Task/RsyncTest.php +++ b/tests/unit/Task/RsyncTest.php @@ -1,8 +1,16 @@ setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + } /** * @var \CodeGuy diff --git a/tests/unit/Task/SemVerTest.php b/tests/unit/Task/SemVerTest.php index 4bf66f548..7278d2ee7 100644 --- a/tests/unit/Task/SemVerTest.php +++ b/tests/unit/Task/SemVerTest.php @@ -1,10 +1,16 @@ setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + } public function testSemver() { diff --git a/tests/unit/Task/SshTest.php b/tests/unit/Task/SshTest.php index 5fac8d7c8..2d24b40e8 100644 --- a/tests/unit/Task/SshTest.php +++ b/tests/unit/Task/SshTest.php @@ -1,9 +1,16 @@ setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + } // tests public function testBasicCommand() { diff --git a/tests/unit/Task/SvnTest.php b/tests/unit/Task/SvnTest.php index 925ce78b8..8a06464d5 100644 --- a/tests/unit/Task/SvnTest.php +++ b/tests/unit/Task/SvnTest.php @@ -1,10 +1,12 @@ new \AspectMock\Proxy\Anything(), 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); } // tests From 084e165f73cc2a1c570a3865d5915c514e4d9000 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Mon, 7 Mar 2016 08:34:31 -0800 Subject: [PATCH 02/34] Improve styling of simulator output. --- src/Task/Simulator.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Task/Simulator.php b/src/Task/Simulator.php index 5deb24b62..cbef9dcd6 100644 --- a/src/Task/Simulator.php +++ b/src/Task/Simulator.php @@ -30,15 +30,15 @@ public function run() foreach ($this->stack as $action) { $command = array_shift($action); $parameters = $this->formatParameters($action); - $callchain .= "\n ->$command($parameters)"; + $callchain .= "\n ->$command($parameters)"; } // RoboLogLevel::SIMULATED_ACTION - $this->logger()->log(RoboLogLevel::SIMULATED_ACTION, 'Simulating {simulated}({parameters}){callchain}', + $this->logger()->log(RoboLogLevel::SIMULATED_ACTION, "Simulating {simulated}({parameters})$callchain", $this->getTaskContext( [ 'simulated' => TaskInfo::formatTaskName($this->task), 'parameters' => $this->formatParameters($this->constructorParameters), - 'callchain' => $callchain, + '_style' => ['simulated' => 'fg=blue;options=bold'], ] ) ); @@ -48,6 +48,9 @@ public function run() protected function formatParameters($action) { $parameterList = array_map( function($item) { + if (is_callable($item)) { + return 'inline_function(...)'; + } if (is_array($item) || is_object($item)) { return var_export($item, true); } From 3d59092bd82f8d5c0acea5ec4a7b474ce08d947b Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Mon, 7 Mar 2016 10:33:53 -0800 Subject: [PATCH 03/34] Fix Nitpick CI issues. --- src/Task/Simulator.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Task/Simulator.php b/src/Task/Simulator.php index cbef9dcd6..cc106d674 100644 --- a/src/Task/Simulator.php +++ b/src/Task/Simulator.php @@ -33,7 +33,9 @@ public function run() $callchain .= "\n ->$command($parameters)"; } // RoboLogLevel::SIMULATED_ACTION - $this->logger()->log(RoboLogLevel::SIMULATED_ACTION, "Simulating {simulated}({parameters})$callchain", + $this->logger()->log( + RoboLogLevel::SIMULATED_ACTION, + "Simulating {simulated}({parameters})$callchain", $this->getTaskContext( [ 'simulated' => TaskInfo::formatTaskName($this->task), @@ -45,9 +47,10 @@ public function run() return Result::success($this); } - protected function formatParameters($action) { + protected function formatParameters($action) + { $parameterList = array_map( - function($item) { + function ($item) { if (is_callable($item)) { return 'inline_function(...)'; } @@ -63,5 +66,4 @@ function($item) { ); return implode(', ', $parameterList); } - } From dcf1b032f4d0caaac73849c0bc5fd4041d225c65 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Mon, 7 Mar 2016 11:30:53 -0800 Subject: [PATCH 04/34] Automatically exclude accessor methods from command list. --- src/Application.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Application.php b/src/Application.php index 2c01fe4f6..578366e49 100644 --- a/src/Application.php +++ b/src/Application.php @@ -33,6 +33,34 @@ public function taskAssembler() return $this->taskAssembler; } + protected static function findAccessorMethods($commandNames) + { + $accessorNames = []; + // Using get_class_vars is not reliable, because it only + // exposes public class variables. + foreach ($commandNames as $commandName) { + // We count a set of methods as accessor methods if + // there is a setter and at least one getter. + if (strpos($commandName, 'set') === 0) { + $name = lcfirst(substr($commandName, 3)); + $getter = 'get' . ucfirst($name); + $hasGetter = false; + if (in_array($name, $commandNames)) { + $accessorNames[] = $name; + $hasGetter = true; + } + if (in_array($getter, $commandNames)) { + $accessorNames[] = $getter; + $hasGetter = true; + } + if ($hasGetter) { + $accessorNames[] = $commandName; + } + } + } + return $accessorNames; + } + public function addCommandsFromClass($className, $passThrough = null) { $roboTasks = new $className; @@ -40,9 +68,11 @@ public function addCommandsFromClass($className, $passThrough = null) $roboTasks->setTaskAssembler($this->taskAssembler); } - $commandNames = array_filter(get_class_methods($className), function($m) { + $commandNames = array_filter(get_class_methods($className), function ($m) { return !in_array($m, ['__construct']); }); + $accessorNames = static::findAccessorMethods($commandNames); + $commandNames = array_diff($commandNames, $accessorNames); foreach ($commandNames as $commandName) { $command = $this->createCommand(new TaskInfo($className, $commandName)); From f0ae7e90e84022296b31cb041b860197b9454bef Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Mon, 7 Mar 2016 14:14:05 -0800 Subject: [PATCH 05/34] Use reverse styling instead of assuming the terminal colors. --- src/Log/RoboLogStyle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Log/RoboLogStyle.php b/src/Log/RoboLogStyle.php index ddf48536d..416fd0dba 100644 --- a/src/Log/RoboLogStyle.php +++ b/src/Log/RoboLogStyle.php @@ -10,7 +10,7 @@ */ class RoboLogStyle extends LogOutputStyler { - const TASK_STYLE_SIMULATED = 'fg=white;bg=black;options=bold'; + const TASK_STYLE_SIMULATED = 'options=reverse;bold'; public function __construct($labelStyles = [], $messageStyles = []) { From dfff66040f28ea0d89f75e1c28f802539b0853c1 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 9 Mar 2016 17:19:00 -0800 Subject: [PATCH 06/34] Switch to league/container for Dependency Injection. --- composer.json | 2 +- composer.lock | 97 +++++++++++++++++++++++++++++++++++++-- src/Config.php | 50 +++++++++----------- src/Log/ResultPrinter.php | 14 ++---- src/Runner.php | 4 -- src/TaskAssembler.php | 19 ++++---- 6 files changed, 132 insertions(+), 54 deletions(-) diff --git a/composer.json b/composer.json index a3419ab2d..41d236fbb 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "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" }, "require-dev": { "patchwork/jsqueeze": "~1.0", diff --git a/composer.lock b/composer.lock index 2ffea8d67..85af98989 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "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": "934e092df45477d3b806941c0b4a4826", + "content-hash": "a410f2bc2d13132cf7c5982824f8bab4", "packages": [ { "name": "consolidation/log", @@ -58,6 +58,97 @@ "description": "Improved Psr-3 / Psr\\Log logger based on Symfony Console components.", "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.0.3", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/container.git", + "reference": "d4b5e0dde44aec50e4025c7249d668ea74b1ae44" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/container/zipball/d4b5e0dde44aec50e4025c7249d668ea74b1ae44", + "reference": "d4b5e0dde44aec50e4025c7249d668ea74b1ae44", + "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.1-dev", + "dev-1.x": "1.5-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": "2015-09-07 10:16:18" + }, { "name": "psr/log", "version": "1.0.0", @@ -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", diff --git a/src/Config.php b/src/Config.php index bf470db7d..231b9e5f6 100644 --- a/src/Config.php +++ b/src/Config.php @@ -1,11 +1,9 @@ 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')); - $container - ->register('taskAssembler', 'Robo\TaskAssembler') - ->addArgument(new Reference('logger')); + $container = new Container(); + + $container->add('input', $input); + $container->share('output', 'Symfony\Component\Console\Output\ConsoleOutput'); + $container->share('logStyler', 'Robo\Log\RoboLogStyle'); + $container->share('logger', 'Robo\Log\RoboLogger') + ->withArgument('output') + ->withMethodCall('setLogOutputStyler', ['logStyler']); + $container->share('resultPrinter', 'Robo\Log\ResultPrinter'); + $container->share('taskAssembler', 'Robo\TaskAssembler'); + + $container->inflector('Psr\Log\LoggerAwareInterface') + ->invokeMethod('setLogger', ['logger']); return $container; } @@ -118,7 +115,7 @@ public static function service($id) */ public static function setService($id, $service) { - static::getContainer()->set($id, $service); + static::getContainer()->add($id, $service); } /** @@ -188,15 +185,12 @@ 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) diff --git a/src/Log/ResultPrinter.php b/src/Log/ResultPrinter.php index 1af3c65f3..060618782 100644 --- a/src/Log/ResultPrinter.php +++ b/src/Log/ResultPrinter.php @@ -6,21 +6,15 @@ use Robo\Contract\PrintedInterface; use Psr\Log\LoggerInterface; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; /** * Robo's default logger */ -class ResultPrinter +class ResultPrinter implements LoggerAwareInterface { - /** - * var LoggerInterface - */ - protected $logger; - - public function __construct(LoggerInterface $logger) - { - $this->logger = $logger; - } + use LoggerAwareTrait; /** * Log the result of a Robo task. diff --git a/src/Runner.php b/src/Runner.php index ea690e582..528d5ef63 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -85,10 +85,6 @@ public function execute($input = null) $input = $this->prepareInput($input ? $input : $_SERVER['argv']); $container = Config::createContainer($input); 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); diff --git a/src/TaskAssembler.php b/src/TaskAssembler.php index 04ca9971e..ccb6e7b1f 100644 --- a/src/TaskAssembler.php +++ b/src/TaskAssembler.php @@ -1,26 +1,29 @@ logger = $logger; $this->simulated = false; } From d9c20af98cc6f01f9e81419c9e6af083306c3a5c Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 9 Mar 2016 17:21:33 -0800 Subject: [PATCH 07/34] Adjust whitespace for NitPick. --- src/Log/ResultPrinter.php | 2 +- src/TaskAssembler.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Log/ResultPrinter.php b/src/Log/ResultPrinter.php index 060618782..63be24a16 100644 --- a/src/Log/ResultPrinter.php +++ b/src/Log/ResultPrinter.php @@ -14,7 +14,7 @@ */ class ResultPrinter implements LoggerAwareInterface { - use LoggerAwareTrait; + use LoggerAwareTrait; /** * Log the result of a Robo task. diff --git a/src/TaskAssembler.php b/src/TaskAssembler.php index ccb6e7b1f..ac6c8ae37 100644 --- a/src/TaskAssembler.php +++ b/src/TaskAssembler.php @@ -9,13 +9,12 @@ use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; - /** * Put together tasks */ class TaskAssembler implements LoggerAwareInterface { - use LoggerAwareTrait; + use LoggerAwareTrait; /** * @var boolean From ec5d60f5ed8513f9496d7fef9ee9dd8a6a4dd14d Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Fri, 11 Mar 2016 15:23:24 -0800 Subject: [PATCH 08/34] Remove test code left in by accident. --- src/TaskAssembler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TaskAssembler.php b/src/TaskAssembler.php index ac6c8ae37..8e91085e9 100644 --- a/src/TaskAssembler.php +++ b/src/TaskAssembler.php @@ -57,7 +57,7 @@ public function assemble($taskClass, $taskConstructorParameters = []) // If we are in simulated mode, then wrap the task in // a TaskSimulator. - if ($this->isSimulated() || Config::isSimulated()) { + if ($this->isSimulated()) { $task = new Simulator($task, $taskConstructorParameters); } From 4b3f96496fda6a208ed0114ad08579a347c90be9 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Sat, 12 Mar 2016 19:39:54 -0800 Subject: [PATCH 09/34] Use ::class instead of strings when setting up DI container. --- src/Application.php | 4 ++-- src/Config.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Application.php b/src/Application.php index 578366e49..002c180c6 100644 --- a/src/Application.php +++ b/src/Application.php @@ -71,8 +71,8 @@ public function addCommandsFromClass($className, $passThrough = null) $commandNames = array_filter(get_class_methods($className), function ($m) { return !in_array($m, ['__construct']); }); - $accessorNames = static::findAccessorMethods($commandNames); - $commandNames = array_diff($commandNames, $accessorNames); + //$accessorNames = static::findAccessorMethods($commandNames); + //$commandNames = array_diff($commandNames, $accessorNames); foreach ($commandNames as $commandName) { $command = $this->createCommand(new TaskInfo($className, $commandName)); diff --git a/src/Config.php b/src/Config.php index 231b9e5f6..304494d3e 100644 --- a/src/Config.php +++ b/src/Config.php @@ -45,15 +45,15 @@ public static function createContainer($input = null) $container = new Container(); $container->add('input', $input); - $container->share('output', 'Symfony\Component\Console\Output\ConsoleOutput'); - $container->share('logStyler', 'Robo\Log\RoboLogStyle'); - $container->share('logger', 'Robo\Log\RoboLogger') + $container->share('output', \Symfony\Component\Console\Output\ConsoleOutput::class); + $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'); - $container->share('taskAssembler', 'Robo\TaskAssembler'); + $container->share('resultPrinter', \Robo\Log\ResultPrinter::class); + $container->share('taskAssembler', \Robo\TaskAssembler::class); - $container->inflector('Psr\Log\LoggerAwareInterface') + $container->inflector(\Psr\Log\LoggerAwareInterface::class) ->invokeMethod('setLogger', ['logger']); return $container; From 5f66ab361e62f0f54c5c6b11c37e5cc97cf2f82e Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Sat, 12 Mar 2016 19:41:59 -0800 Subject: [PATCH 10/34] Declare minimum php to be 5.5 now. --- composer.json | 2 +- composer.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 41d236fbb..475cfbb39 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ }, "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", diff --git a/composer.lock b/composer.lock index 85af98989..a1aec78fa 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "934e092df45477d3b806941c0b4a4826", - "content-hash": "a410f2bc2d13132cf7c5982824f8bab4", + "hash": "6b0bc51ba3b8a9199b5d71667c427285", + "content-hash": "2a5b7b6477b38ddb137bf8f24526fdb4", "packages": [ { "name": "consolidation/log", @@ -2656,7 +2656,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.4.0" + "php": ">=5.5.0" }, "platform-dev": [] } From 254c647acbdd5a0aeaf48507f63e0196dd16aef8 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Sat, 12 Mar 2016 20:18:56 -0800 Subject: [PATCH 11/34] Don't test php 5.4. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) 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 From 009fcde9bc93eb64ccd6091cd451b2bb751cb630 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Mon, 14 Mar 2016 16:52:56 -0700 Subject: [PATCH 12/34] Remove all loadTask traits; fetch from our container instead. --- src/Application.php | 60 ++--------- src/Collection/ServiceProvider.php | 16 +++ src/Collection/loadTasks.php | 14 --- src/Config.php | 28 ------ src/Container/RoboContainer.php | 123 +++++++++++++++++++++++ src/Runner.php | 71 ++++++++++++- src/Task/ApiGen/ServiceProvider.php | 16 +++ src/Task/ApiGen/loadTasks.php | 15 --- src/Task/Archive/ServiceProvider.php | 18 ++++ src/Task/Archive/loadTasks.php | 32 ------ src/Task/Assets/ServiceProvider.php | 22 ++++ src/Task/Assets/loadTasks.php | 53 ---------- src/Task/Base/ServiceProvider.php | 24 +++++ src/Task/Base/loadShortcuts.php | 6 +- src/Task/Base/loadTasks.php | 59 ----------- src/Task/Bower/ServiceProvider.php | 18 ++++ src/Task/Bower/loadTasks.php | 30 ------ src/Task/Composer/ServiceProvider.php | 20 ++++ src/Task/Composer/loadTasks.php | 42 -------- src/Task/Development/SemVer.php | 4 +- src/Task/Development/ServiceProvider.php | 28 ++++++ src/Task/Development/loadTasks.php | 89 ---------------- src/Task/Docker/ServiceProvider.php | 28 ++++++ src/Task/Docker/loadTasks.php | 63 ------------ src/Task/File/ServiceProvider.php | 22 ++++ src/Task/File/loadTasks.php | 57 ----------- src/Task/FileSystem/ServiceProvider.php | 28 ++++++ src/Task/FileSystem/loadShortcuts.php | 28 +++--- src/Task/FileSystem/loadTasks.php | 89 ---------------- src/Task/Gulp/ServiceProvider.php | 16 +++ src/Task/Gulp/loadTasks.php | 15 --- src/Task/Npm/ServiceProvider.php | 18 ++++ src/Task/Npm/loadTasks.php | 21 ---- src/Task/Remote/ServiceProvider.php | 18 ++++ src/Task/Remote/loadTasks.php | 24 ----- src/Task/Testing/ServiceProvider.php | 20 ++++ src/Task/Testing/loadTasks.php | 32 ------ src/Task/Vcs/ServiceProvider.php | 18 ++++ src/Task/Vcs/loadShortcuts.php | 8 +- src/Task/Vcs/loadTasks.php | 26 ----- src/TaskAssembler.php | 66 ------------ src/TaskSupport.php | 19 ---- src/Tasklib.php | 41 -------- src/Tasks.php | 31 +++++- tests/_helpers/CliGuy.php | 11 +- tests/_helpers/CliHelper.php | 40 ++------ tests/cli/CleanDirCept.php | 8 +- tests/cli/CollectionCest.php | 38 +++---- tests/cli/ConcatCept.php | 8 +- tests/cli/CopyDirCept.php | 6 +- tests/cli/CopyDirOverwritesFilesCept.php | 6 +- tests/cli/CopyDirRecursiveCept.php | 6 +- tests/cli/DeleteDirCept.php | 7 +- tests/cli/ExecCest.php | 10 +- tests/cli/FileSystemStackCest.php | 6 +- tests/cli/FlattenDirCept.php | 8 +- tests/cli/FlattenDirParentsCept.php | 6 +- tests/cli/PackExtractCept.php | 12 ++- tests/cli/WriteFileCest.php | 14 +-- tests/cli/_bootstrap.php | 8 +- tests/unit/Task/ApiGenTest.php | 15 +-- tests/unit/Task/BowerTest.php | 20 ++-- tests/unit/Task/CodeceptionTest.php | 28 ++++-- tests/unit/Task/CollectionTest.php | 13 ++- tests/unit/Task/CommandStackTest.php | 10 ++ tests/unit/Task/ComposerTest.php | 46 +++++---- tests/unit/Task/ExecTaskTest.php | 21 ++-- tests/unit/Task/GitTest.php | 17 ++-- tests/unit/Task/GulpTest.php | 37 +++---- tests/unit/Task/NpmTest.php | 21 ++-- tests/unit/Task/PHPServerTest.php | 18 ++-- tests/unit/Task/PHPUnitTest.php | 15 +-- tests/unit/Task/ParallelExecTest.php | 13 ++- tests/unit/Task/PhpspecTest.php | 15 +-- tests/unit/Task/RsyncTest.php | 21 ++-- tests/unit/Task/SemVerTest.php | 15 +-- tests/unit/Task/SshTest.php | 24 +++-- tests/unit/Task/SvnTest.php | 14 ++- 78 files changed, 905 insertions(+), 1128 deletions(-) create mode 100644 src/Collection/ServiceProvider.php delete mode 100644 src/Collection/loadTasks.php create mode 100644 src/Container/RoboContainer.php create mode 100644 src/Task/ApiGen/ServiceProvider.php delete mode 100644 src/Task/ApiGen/loadTasks.php create mode 100644 src/Task/Archive/ServiceProvider.php delete mode 100644 src/Task/Archive/loadTasks.php create mode 100644 src/Task/Assets/ServiceProvider.php delete mode 100644 src/Task/Assets/loadTasks.php create mode 100644 src/Task/Base/ServiceProvider.php delete mode 100644 src/Task/Base/loadTasks.php create mode 100644 src/Task/Bower/ServiceProvider.php delete mode 100644 src/Task/Bower/loadTasks.php create mode 100644 src/Task/Composer/ServiceProvider.php delete mode 100644 src/Task/Composer/loadTasks.php create mode 100644 src/Task/Development/ServiceProvider.php delete mode 100644 src/Task/Development/loadTasks.php create mode 100644 src/Task/Docker/ServiceProvider.php delete mode 100644 src/Task/Docker/loadTasks.php create mode 100644 src/Task/File/ServiceProvider.php delete mode 100644 src/Task/File/loadTasks.php create mode 100644 src/Task/FileSystem/ServiceProvider.php delete mode 100644 src/Task/FileSystem/loadTasks.php create mode 100644 src/Task/Gulp/ServiceProvider.php delete mode 100644 src/Task/Gulp/loadTasks.php create mode 100644 src/Task/Npm/ServiceProvider.php delete mode 100644 src/Task/Npm/loadTasks.php create mode 100644 src/Task/Remote/ServiceProvider.php delete mode 100644 src/Task/Remote/loadTasks.php create mode 100644 src/Task/Testing/ServiceProvider.php delete mode 100644 src/Task/Testing/loadTasks.php create mode 100644 src/Task/Vcs/ServiceProvider.php delete mode 100644 src/Task/Vcs/loadTasks.php delete mode 100644 src/TaskAssembler.php delete mode 100644 src/TaskSupport.php delete mode 100644 src/Tasklib.php diff --git a/src/Application.php b/src/Application.php index 002c180c6..db262ce99 100644 --- a/src/Application.php +++ b/src/Application.php @@ -7,12 +7,12 @@ 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 { - /** - * @var \Robo\TaskAssembler - */ - protected $taskAssembler; + use ContainerAwareTrait; public function __construct($name, $version) { @@ -23,60 +23,21 @@ public function __construct($name, $version) ); } - public function setTaskAssembler($taskAssembler) - { - $this->taskAssembler = $taskAssembler; - } - - public function taskAssembler() - { - return $this->taskAssembler; - } - - protected static function findAccessorMethods($commandNames) - { - $accessorNames = []; - // Using get_class_vars is not reliable, because it only - // exposes public class variables. - foreach ($commandNames as $commandName) { - // We count a set of methods as accessor methods if - // there is a setter and at least one getter. - if (strpos($commandName, 'set') === 0) { - $name = lcfirst(substr($commandName, 3)); - $getter = 'get' . ucfirst($name); - $hasGetter = false; - if (in_array($name, $commandNames)) { - $accessorNames[] = $name; - $hasGetter = true; - } - if (in_array($getter, $commandNames)) { - $accessorNames[] = $getter; - $hasGetter = true; - } - if ($hasGetter) { - $accessorNames[] = $commandName; - } - } - } - return $accessorNames; - } - public function addCommandsFromClass($className, $passThrough = null) { + $container = $this->getContainer(); $roboTasks = new $className; - if ($roboTasks instanceof \Robo\Tasks) { - $roboTasks->setTaskAssembler($this->taskAssembler); + if ($roboTasks instanceof ContainerAwareInterface) { + $roboTasks->setContainer($container); } $commandNames = array_filter(get_class_methods($className), function ($m) { return !in_array($m, ['__construct']); }); - //$accessorNames = static::findAccessorMethods($commandNames); - //$commandNames = array_diff($commandNames, $accessorNames); 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); @@ -87,8 +48,7 @@ public function addCommandsFromClass($className, $passThrough = null) // Need a better way to handle global options // Also, this is not necessarily the best place to do this Config::setGlobalOptions($input); - // Avoid making taskAssembler depend on Config class. - Config::service('taskAssembler')->setSimulated(Config::isSimulated()); + $container->setSimulated(Config::isSimulated()); $res = call_user_func_array([$roboTasks, $commandName], $args); if (is_int($res)) exit($res); diff --git a/src/Collection/ServiceProvider.php b/src/Collection/ServiceProvider.php new file mode 100644 index 000000000..2198aadb7 --- /dev/null +++ b/src/Collection/ServiceProvider.php @@ -0,0 +1,16 @@ +getContainer()->add('collection', Collection::class); + } +} 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 @@ -add('input', $input); - $container->share('output', \Symfony\Component\Console\Output\ConsoleOutput::class); - $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->share('taskAssembler', \Robo\TaskAssembler::class); - - $container->inflector(\Psr\Log\LoggerAwareInterface::class) - ->invokeMethod('setLogger', ['logger']); - - return $container; - } - /** * Unsets the global container. */ diff --git a/src/Container/RoboContainer.php b/src/Container/RoboContainer.php new file mode 100644 index 000000000..8069a0be4 --- /dev/null +++ b/src/Container/RoboContainer.php @@ -0,0 +1,123 @@ +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 = []) + { + // TODO: put back to: $service = parent::get($alias, $args); + // after https://github.com/thephpleague/container/pull/92 is merged. + $service = $this->parentGet($alias, $args); + + // 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 its + // complete method will be called after the collection completes. + if ($service instanceof CompletionInterface) { + $service = Temporary::wrap($service); + } + + // If we are in simulated mode, then wrap any task in + // a TaskSimulator. + if ($isTask && !$isCollection && ($this->isSimulated())) { + $service = new Simulator($service, $args); + } + + return $service; + } + + /** + * TODO: Remove after https://github.com/thephpleague/container/pull/92 is merged + */ + public function parentGet($alias, array $args = []) + { + $service = $this->getFromThisContainer($alias, $args); + + if (!$service && $this->providers->provides($alias)) { + $this->providers->register($alias); + $service = $this->getFromThisContainer($alias, $args); + } + + if ($service) { + return $service; + } + + if ($resolved = $this->getFromDelegate($alias, $args)) { + return $this->inflectors->inflect($resolved); + } + + throw new NotFoundException( + sprintf('Alias (%s) is not being managed by the container', $alias) + ); + } + + /** + * TODO: Remove after https://github.com/thephpleague/container/pull/92 is merged + * + * Get a service that has been registered in this container. + * + * @return mixed Entry|false. + */ + protected function getFromThisContainer($alias, array $args = []) + { + if ($this->hasShared($alias, true)) { + return $this->inflectors->inflect($this->shared[$alias]); + } + + if (array_key_exists($alias, $this->sharedDefinitions)) { + $shared = $this->inflectors->inflect($this->sharedDefinitions[$alias]->build()); + $this->shared[$alias] = $shared; + return $shared; + } + + if (array_key_exists($alias, $this->definitions)) { + return $this->inflectors->inflect( + $this->definitions[$alias]->build($args) + ); + } + + return false; + } +} diff --git a/src/Runner.php b/src/Runner.php index 528d5ef63..5172a918c 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 @@ -83,12 +85,18 @@ public function execute($input = null) // 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); } - $app = new Application('Robo', self::VERSION); - $app->setTaskAssembler(Config::service('taskAssembler')); + $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'); @@ -97,7 +105,62 @@ 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); + + // 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\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\ApiGen\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\Archive\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\Assets\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\Base\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\Bower\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\Composer\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\Development\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\Docker\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\File\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\Remote\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\Testing\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\Vcs\ServiceProvider::class); } /** diff --git a/src/Task/ApiGen/ServiceProvider.php b/src/Task/ApiGen/ServiceProvider.php new file mode 100644 index 000000000..be57cd76b --- /dev/null +++ b/src/Task/ApiGen/ServiceProvider.php @@ -0,0 +1,16 @@ +getContainer()->add('taskApiGen', ApiGen::class); + } +} diff --git a/src/Task/ApiGen/loadTasks.php b/src/Task/ApiGen/loadTasks.php deleted file mode 100644 index 4202dc1e1..000000000 --- a/src/Task/ApiGen/loadTasks.php +++ /dev/null @@ -1,15 +0,0 @@ -getContainer()->add('taskExtract', Extract::class); + $this->getContainer()->add('taskPack', Pack::class); + } +} diff --git a/src/Task/Archive/loadTasks.php b/src/Task/Archive/loadTasks.php deleted file mode 100644 index 2684bff8a..000000000 --- a/src/Task/Archive/loadTasks.php +++ /dev/null @@ -1,32 +0,0 @@ -taskAssembler()->assemble( - '\Robo\Task\Archive\Pack', - [$filename] - ); - } - - /** - * @param $filename - * - * @return Extract - */ - protected function taskExtract($filename) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Archive\Extract', - [$filename] - ); - } -} diff --git a/src/Task/Assets/ServiceProvider.php b/src/Task/Assets/ServiceProvider.php new file mode 100644 index 000000000..661e9b58e --- /dev/null +++ b/src/Task/Assets/ServiceProvider.php @@ -0,0 +1,22 @@ +getContainer()->add('taskMinify', Minify::class); + $this->getContainer()->add('taskImageMinify', ImageMinify::class); + $this->getContainer()->add('taskLess', Less::class); + $this->getContainer()->add('taskScss', Scss::class); + } +} diff --git a/src/Task/Assets/loadTasks.php b/src/Task/Assets/loadTasks.php deleted file mode 100644 index 6dc16fa9e..000000000 --- a/src/Task/Assets/loadTasks.php +++ /dev/null @@ -1,53 +0,0 @@ -taskAssembler()->assemble( - '\Robo\Task\Assets\Minify', - [$input] - ); - } - - /** - * @param $input - * @return ImageMinify - */ - protected function taskImageMinify($input) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Assets\ImageMinify', - [$input] - ); - } - - /** - * @param $input - * @return Less - */ - protected function taskLess($input) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Assets\Less', - [$input] - ); - } - - /** - * @param $input - * @return Scss - */ - protected function taskScss($input) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Assets\Scss', - [$input] - ); - } -} diff --git a/src/Task/Base/ServiceProvider.php b/src/Task/Base/ServiceProvider.php new file mode 100644 index 000000000..a67144f67 --- /dev/null +++ b/src/Task/Base/ServiceProvider.php @@ -0,0 +1,24 @@ +getContainer()->add('taskExec', Exec::class); + $this->getContainer()->add('taskExecStack', ExecStack::class); + $this->getContainer()->add('taskParallelExec', ParallelExec::class); + $this->getContainer()->add('taskSymfonyCommand', SymfonyCommand::class); + $this->getContainer()->add('taskWatch', Watch::class); + } +} 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 deleted file mode 100644 index cdeb14f4d..000000000 --- a/src/Task/Base/loadTasks.php +++ /dev/null @@ -1,59 +0,0 @@ -taskAssembler()->assemble( - '\Robo\Task\Base\Exec', - [$command] - ); - } - - protected function taskExecStack() - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Base\ExecStack', - [] - ); - } - - /** - * @return ParallelExec - */ - protected function taskParallelExec() - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Base\ParallelExec', - [] - ); - } - - /** - * @param $command - * @return SymfonyCommand - */ - protected function taskSymfonyCommand($command) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Base\SymfonyCommand', - [$command] - ); - } - - /** - * @return Watch - */ - protected function taskWatch() - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Base\Watch', - [$this] - ); - } -} diff --git a/src/Task/Bower/ServiceProvider.php b/src/Task/Bower/ServiceProvider.php new file mode 100644 index 000000000..a85353a97 --- /dev/null +++ b/src/Task/Bower/ServiceProvider.php @@ -0,0 +1,18 @@ +getContainer()->add('taskBowerInstall', Install::class); + $this->getContainer()->add('taskBowerUpdate', Update::class); + } +} diff --git a/src/Task/Bower/loadTasks.php b/src/Task/Bower/loadTasks.php deleted file mode 100644 index 79e7582a2..000000000 --- a/src/Task/Bower/loadTasks.php +++ /dev/null @@ -1,30 +0,0 @@ -taskAssembler()->assemble( - '\Robo\Task\Bower\Install', - [$pathToBower] - ); - } - - /** - * @param null $pathToBower - * @return Update - */ - protected function taskBowerUpdate($pathToBower = null) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Bower\Update', - [$pathToBower] - ); - } - -} diff --git a/src/Task/Composer/ServiceProvider.php b/src/Task/Composer/ServiceProvider.php new file mode 100644 index 000000000..f27d7c506 --- /dev/null +++ b/src/Task/Composer/ServiceProvider.php @@ -0,0 +1,20 @@ +getContainer()->add('taskComposerInstall', Install::class); + $this->getContainer()->add('taskComposerUpdate', Update::class); + $this->getContainer()->add('taskComposerDumpAutoload', DumpAutoload::class); + } +} diff --git a/src/Task/Composer/loadTasks.php b/src/Task/Composer/loadTasks.php deleted file mode 100644 index 553895560..000000000 --- a/src/Task/Composer/loadTasks.php +++ /dev/null @@ -1,42 +0,0 @@ -taskAssembler()->assemble( - '\Robo\Task\Composer\Install', - [$pathToComposer] - ); - } - - /** - * @param null $pathToComposer - * @return Update - */ - protected function taskComposerUpdate($pathToComposer = null) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Composer\Update', - [$pathToComposer] - ); - } - - /** - * @param null $pathToComposer - * @return DumpAutoload - */ - protected function taskComposerDumpAutoload($pathToComposer = null) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Composer\DumpAutoload', - [$pathToComposer] - ); - } - -} 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/ServiceProvider.php b/src/Task/Development/ServiceProvider.php new file mode 100644 index 000000000..fb516132a --- /dev/null +++ b/src/Task/Development/ServiceProvider.php @@ -0,0 +1,28 @@ +getContainer()->add('taskChangelog', Changelog::class); + $this->getContainer()->add('taskGenDoc', GenerateMarkdownDoc::class); + $this->getContainer()->add('taskSemVer', SemVer::class); + $this->getContainer()->add('taskServer', PhpServer::class); + $this->getContainer()->add('taskPackPhar', PackPhar::class); + $this->getContainer()->add('taskGitHubRelease', DumpAutoload::class); + $this->getContainer()->add('taskOpenBrowser', OpenBrowser::class); + } +} diff --git a/src/Task/Development/loadTasks.php b/src/Task/Development/loadTasks.php deleted file mode 100644 index 798d1615c..000000000 --- a/src/Task/Development/loadTasks.php +++ /dev/null @@ -1,89 +0,0 @@ -taskAssembler()->assemble( - '\Robo\Task\Development\Changelog', - [$filename] - ); - } - - /** - * @param $filename - * @return GenerateMarkdownDoc - */ - protected function taskGenDoc($filename) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Development\GenerateMarkdownDoc', - [$filename] - ); - } - - /** - * @param string $pathToSemVer - * @return SemVer - */ - protected function taskSemVer($pathToSemVer = '.semver') - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Development\SemVer', - [$pathToSemVer] - ); - } - - /** - * @param int $port - * @return PhpServer - */ - protected function taskServer($port = 8000) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Development\PhpServer', - [$port] - ); - } - - /** - * @param $filename - * @return PackPhar - */ - protected function taskPackPhar($filename) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Development\PackPhar', - [$filename] - ); - } - - /** - * @param $tag - * @return GitHubRelease - */ - protected function taskGitHubRelease($tag) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Development\GitHubRelease', - [$tag] - ); - } - - /** - * @param string|array $url - * @return OpenBrowser - */ - protected function taskOpenBrowser($url) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Development\OpenBrowser', - [$url] - ); - } -} diff --git a/src/Task/Docker/ServiceProvider.php b/src/Task/Docker/ServiceProvider.php new file mode 100644 index 000000000..2ac0a58c7 --- /dev/null +++ b/src/Task/Docker/ServiceProvider.php @@ -0,0 +1,28 @@ +getContainer()->add('taskDockerRun', Run::class); + $this->getContainer()->add('taskDockerPull', Pull::class); + $this->getContainer()->add('taskDockerBuild', Build::class); + $this->getContainer()->add('taskDockerStop', Stop::class); + $this->getContainer()->add('taskDockerCommit', Commit::class); + $this->getContainer()->add('taskDockerStart', Start::class); + $this->getContainer()->add('taskDockerRemove', Remove::class); + } +} diff --git a/src/Task/Docker/loadTasks.php b/src/Task/Docker/loadTasks.php deleted file mode 100644 index 7c8c67c1d..000000000 --- a/src/Task/Docker/loadTasks.php +++ /dev/null @@ -1,63 +0,0 @@ -taskAssembler()->assemble( - '\Robo\Task\Docker\Run', - [$image] - ); - } - protected function taskDockerPull($image) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Docker\Pull', - [$image] - ); - } - protected function taskDockerBuild($path = '.') - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Docker\Build', - [$path] - ); - } - protected function taskDockerStop($cidOrResult) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Docker\Stop', - [$cidOrResult] - ); - } - protected function taskDockerCommit($cidOrResult) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Docker\Commit', - [$cidOrResult] - ); - } - protected function taskDockerStart($cidOrResult) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Docker\Start', - [$cidOrResult] - ); - } - protected function taskDockerRemove($cidOrResult) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Docker\Remove', - [$cidOrResult] - ); - } - - protected function taskDockerExec($cidOrResult) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\Docker\Exec', - [$cidOrResult] - ); - } -} diff --git a/src/Task/File/ServiceProvider.php b/src/Task/File/ServiceProvider.php new file mode 100644 index 000000000..3361aa542 --- /dev/null +++ b/src/Task/File/ServiceProvider.php @@ -0,0 +1,22 @@ +getContainer()->add('taskConcat', Concat::class); + $this->getContainer()->add('taskReplaceInFile', Replace::class); + $this->getContainer()->add('taskWriteToFile', Write::class); + $this->getContainer()->add('taskTmpFile', TmpFile::class); + } +} diff --git a/src/Task/File/loadTasks.php b/src/Task/File/loadTasks.php deleted file mode 100644 index 86d1695aa..000000000 --- a/src/Task/File/loadTasks.php +++ /dev/null @@ -1,57 +0,0 @@ -taskAssembler()->assemble( - '\Robo\Task\File\Concat', - [$files] - ); - } - - /** - * @param $file - * @return Replace - */ - protected function taskReplaceInFile($file) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\File\Replace', - [$file] - ); - } - - /** - * @param $file - * @return Write - */ - protected function taskWriteToFile($file) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\File\Write', - [$file] - ); - } - - /** - * @param $prefix - * @param $base - * @param $includeRandomPart - * @return TmpFile - */ - protected function taskTmpFile($filename = 'tmp', $extension = '', $baseDir = '', $includeRandomPart = true) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\File\TmpFile', - [$filename, $extension, $baseDir, $includeRandomPart] - ); - } -} diff --git a/src/Task/FileSystem/ServiceProvider.php b/src/Task/FileSystem/ServiceProvider.php new file mode 100644 index 000000000..267f161e4 --- /dev/null +++ b/src/Task/FileSystem/ServiceProvider.php @@ -0,0 +1,28 @@ +getContainer()->add('taskCleanDir', CleanDir::class); + $this->getContainer()->add('taskDeleteDir', DeleteDir::class); + $this->getContainer()->add('taskTmpDir', TmpDir::class); + $this->getContainer()->add('taskCopyDir', CopyDir::class); + $this->getContainer()->add('taskMirrorDir', MirrorDir::class); + $this->getContainer()->add('taskFlattenDir', FlattenDir::class); + $this->getContainer()->add('taskFileSystemStack', FilesystemStack::class); + } +} 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 deleted file mode 100644 index 348b2e4e9..000000000 --- a/src/Task/FileSystem/loadTasks.php +++ /dev/null @@ -1,89 +0,0 @@ -taskAssembler()->assemble( - '\Robo\Task\FileSystem\CleanDir', - [$dirs] - ); - } - - /** - * @param $dirs - * @return DeleteDir - */ - protected function taskDeleteDir($dirs) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\FileSystem\DeleteDir', - [$dirs] - ); - } - - /** - * @param $prefix - * @param $base - * @param $includeRandomPart - * @return TmpDir - */ - protected function taskTmpDir($prefix = 'tmp', $base = '', $includeRandomPart = true) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\FileSystem\TmpDir', - [$prefix, $base, $includeRandomPart] - ); - } - - /** - * @param $dirs - * @return CopyDir - */ - protected function taskCopyDir($dirs) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\FileSystem\CopyDir', - [$dirs] - ); - } - - /** - * @param $dirs - * @return MirrorDir - */ - protected function taskMirrorDir($dirs) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\FileSystem\MirrorDir', - [$dirs] - ); - } - - /** - * @param $dirs - * @return FlattenDir - */ - protected function taskFlattenDir($dirs) - { - return $this->taskAssembler()->assemble( - '\Robo\Task\FileSystem\FlattenDir', - [$dirs] - ); - } - - /** - * @return FilesystemStack - */ - protected function taskFilesystemStack() - { - return $this->taskAssembler()->assemble( - '\Robo\Task\FileSystem\FilesystemStack' - ); - } -} diff --git a/src/Task/Gulp/ServiceProvider.php b/src/Task/Gulp/ServiceProvider.php new file mode 100644 index 000000000..195b03221 --- /dev/null +++ b/src/Task/Gulp/ServiceProvider.php @@ -0,0 +1,16 @@ +getContainer()->add('taskGulpRun', Run::class); + } +} diff --git a/src/Task/Gulp/loadTasks.php b/src/Task/Gulp/loadTasks.php deleted file mode 100644 index b0ff372f2..000000000 --- a/src/Task/Gulp/loadTasks.php +++ /dev/null @@ -1,15 +0,0 @@ -getContainer()->add('taskNpmInstall', Install::class); + $this->getContainer()->add('taskNpmUpdate', Update::class); + } +} diff --git a/src/Task/Npm/loadTasks.php b/src/Task/Npm/loadTasks.php deleted file mode 100644 index d7fa297f9..000000000 --- a/src/Task/Npm/loadTasks.php +++ /dev/null @@ -1,21 +0,0 @@ -getContainer()->add('taskRsync', Rsync::class); + $this->getContainer()->add('taskSshExec', Ssh::class); + } +} diff --git a/src/Task/Remote/loadTasks.php b/src/Task/Remote/loadTasks.php deleted file mode 100644 index 87fecc318..000000000 --- a/src/Task/Remote/loadTasks.php +++ /dev/null @@ -1,24 +0,0 @@ -getContainer()->add('taskCodecept', Codecept::class); + $this->getContainer()->add('taskPHPUnit', PHPUnit::class); + $this->getContainer()->add('taskPhpspec', Phpspec::class); + } +} diff --git a/src/Task/Testing/loadTasks.php b/src/Task/Testing/loadTasks.php deleted file mode 100644 index 748c1b11c..000000000 --- a/src/Task/Testing/loadTasks.php +++ /dev/null @@ -1,32 +0,0 @@ -getContainer()->add('taskSvnStack', SvnStack::class); + $this->getContainer()->add('taskGitStack', GitStack::class); + } +} 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 deleted file mode 100644 index 379ca60ff..000000000 --- a/src/Task/Vcs/loadTasks.php +++ /dev/null @@ -1,26 +0,0 @@ -simulated = false; - } - - public function setSimulated($simulated) - { - $this->simulated = $simulated; - } - - public function isSimulated() - { - return $this->simulated; - } - - public function assemble($taskClass, $taskConstructorParameters = []) - { - $class = new \ReflectionClass($taskClass); - $task = $class->newInstanceArgs($taskConstructorParameters); - - // TODO: Would be more rigorous to have an interface for this. - if (method_exists($task, 'setLogger')) { - $task->setLogger($this->logger); - } - - // 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 its - // complete method will be called after the collection completes. - if ($task instanceof CompletionInterface) { - $task = Temporary::wrap($task); - } - - // If we are in simulated mode, then wrap the task in - // a TaskSimulator. - if ($this->isSimulated()) { - $task = new Simulator($task, $taskConstructorParameters); - } - - return $task; - } -} diff --git a/src/TaskSupport.php b/src/TaskSupport.php deleted file mode 100644 index 107dce864..000000000 --- a/src/TaskSupport.php +++ /dev/null @@ -1,19 +0,0 @@ -taskAssembler = $taskAssembler; - } - - public function taskAssembler() - { - return $this->taskAssembler; - } -} diff --git a/src/Tasklib.php b/src/Tasklib.php deleted file mode 100644 index 12221a0af..000000000 --- a/src/Tasklib.php +++ /dev/null @@ -1,41 +0,0 @@ -getContainer()->get('collection'); + } + + /** + * Backwards compatibility: convert $this->taskFoo($a, $b) into + * $this->getContainer()->get('taskFoo', [$a, $b]); + */ + public function __call($functionName, $args) + { + if (preg_match('#^task#', $functionName)) { + $service = $this->getContainer()->get($functionName, $args); + if ($service) { + return $service; + } + } + throw new \Exception("No such method $functionName"); + } } 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 4f81a2b3d..6518c2b52 100644 --- a/tests/_helpers/CliHelper.php +++ b/tests/_helpers/CliHelper.php @@ -5,27 +5,12 @@ use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\NullOutput; -class CliHelper extends \Codeception\Module -{ - use \Robo\Task\Base\loadTasks { - taskExec as public; - taskExecStack as public; - } - use \Robo\Task\File\loadTasks { - taskWriteToFile as public; - taskReplaceInFile as public; - taskConcat as public; - taskTmpFile as public; - } +use League\Container\ContainerAwareInterface; +use League\Container\ContainerAwareTrait; - use \Robo\Task\FileSystem\loadTasks { - taskCleanDir as public; - taskCopyDir as public; - taskDeleteDir as public; - taskFlattenDir as public; - taskFileSystemStack as public; - taskTmpDir as public; - } +class CliHelper extends \Codeception\Module implements ContainerAwareInterface +{ + use ContainerAwareTrait; use \Robo\Task\FileSystem\loadShortcuts { _copyDir as public shortcutCopyDir; @@ -33,20 +18,6 @@ class CliHelper extends \Codeception\Module _tmpDir as public shortcutTmpDir; } - use \Robo\Collection\loadTasks { - collection as public; - } - - use \Robo\Task\Archive\loadTasks { - taskPack as public; - taskExtract as public; - } - - public function taskAssembler() - { - return Config::service('taskAssembler'); - } - public function seeDirFound($dir) { $this->assertTrue(is_dir($dir) && file_exists($dir), "Directory does not exist"); @@ -55,6 +26,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/cli/CleanDirCept.php b/tests/cli/CleanDirCept.php index c23de5eec..421e8ee66 100644 --- a/tests/cli/CleanDirCept.php +++ b/tests/cli/CleanDirCept.php @@ -1,10 +1,12 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); + $I->wantTo('clean dir with DeleteDirTask'); $I->amInPath(codecept_data_dir()); $I->seeFileFound('robo.txt', 'sandbox'); -$I->taskCleanDir(['sandbox']) +$I->getContainer()->get('taskCleanDir', [['sandbox']]) ->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..36ff7a090 100644 --- a/tests/cli/CollectionCest.php +++ b/tests/cli/CollectionCest.php @@ -11,16 +11,20 @@ class CollectionCest { public function _before(CliGuy $I) { + $I->getContainer()->addServiceProvider(\Robo\Collection\ServiceProvider::class); + $I->getContainer()->addServiceProvider(\Robo\Task\File\ServiceProvider::class); + $I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); + $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() + $I->getContainer()->get('taskFileSystemStack') ->mkdir('log') ->touch('log/error.txt') ->addToCollection($collection); @@ -37,13 +41,13 @@ 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 // runs. This technically is not thread-safe, but we create // a random name, so it is unlikely to conflict. - $tmpPath = $I->taskTmpDir() + $tmpPath = $I->getContainer()->get('taskTmpDir') ->addToCollection($collection) ->getPath(); @@ -56,13 +60,13 @@ public function toUseATmpDirAndConfirmItIsDeleted(CliGuy $I) $I->seeDirFound($tmpPath); // Set up a filesystem stack, but use addToCollection() to defer execution - $I->taskFileSystemStack() + $I->getContainer()->get('taskFileSystemStack') ->mkdir("$tmpPath/log") ->touch("$tmpPath/log/error.txt") ->addToCollection($collection); // Copy our tmp directory to a location that is not transient - $I->taskCopyDir([$tmpPath => 'copied']) + $I->getContainer()->get('taskCopyDir', [[$tmpPath => 'copied']]) ->addToCollection($collection); // FileSystemStack has not run yet, so no files should be found. @@ -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(); @@ -90,7 +94,7 @@ public function toUseATmpDirAndChangeWorkingDirectory(CliGuy $I) // 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 = $I->taskTmpDir() + $tmpPath = $I->getContainer()->get('taskTmpDir') ->cwd() ->addToCollection($collection) ->getPath(); @@ -98,13 +102,13 @@ public function toUseATmpDirAndChangeWorkingDirectory(CliGuy $I) // Set up a filesystem stack, but use addToCollection() to defer execution. // Note that since we used 'cwd()' above, the relative file paths // used below will be inside the temporary directory. - $I->taskFileSystemStack() + $I->getContainer()->get('taskFileSystemStack') ->mkdir("log") ->touch("log/error.txt") ->addToCollection($collection); // Copy our tmp directory to a location that is not transient - $I->taskCopyDir(['log' => "$cwd/copied2"]) + $I->getContainer()->get('taskCopyDir', [['log' => "$cwd/copied2"]]) ->addToCollection($collection); // FileSystemStack has not run yet, so no files should be found. @@ -131,18 +135,18 @@ 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 // the file is not created until the task collecction runs. - $tmpPath = $I->taskTmpFile('tmp', '.txt') + $tmpPath = $I->getContainer()->get('taskTmpFile', ['tmp', '.txt']) ->line("This is a test file") ->addToCollection($collection) ->getPath(); // Copy our tmp directory to a location that is not transient - $I->taskFileSystemStack() + $I->getContainer()->get('taskFileSystemStack') ->copy($tmpPath, 'copied.txt') ->addToCollection($collection); @@ -162,14 +166,14 @@ 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. // We start off the same way, using addToCollection() to add our temporary // directory task to the collection, so that we have easy access to the // temporary directory's path via the getPath() method. - $tmpPath = $I->taskTmpDir() + $tmpPath = $I->getContainer()->get('taskTmpDir') ->addToCollection($collection) ->getPath(); @@ -178,8 +182,8 @@ public function toUseATmpDirWithAlternateSyntax(CliGuy $I) // via the add() method. $result = $collection->add( [ - $I->taskFileSystemStack()->mkdir("$tmpPath/log")->touch("$tmpPath/log/error.txt"), - $I->taskCopyDir([$tmpPath => 'copied3']), + $I->getContainer()->get('taskFileSystemStack')->mkdir("$tmpPath/log")->touch("$tmpPath/log/error.txt"), + $I->getContainer()->get('taskCopyDir', [[$tmpPath => 'copied3']]), ] )->run(); diff --git a/tests/cli/ConcatCept.php b/tests/cli/ConcatCept.php index 416673875..0aa2b6472 100644 --- a/tests/cli/ConcatCept.php +++ b/tests/cli/ConcatCept.php @@ -1,9 +1,11 @@ -getContainer()->addServiceProvider(\Robo\Task\File\ServiceProvider::class); + $I->wantTo('concat files using Concat Task'); $I->amInPath(codecept_data_dir() . 'sandbox'); -$I->taskConcat(['a.txt', 'b.txt']) +$I->getContainer()->get('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..91e87b0e6 100644 --- a/tests/cli/CopyDirCept.php +++ b/tests/cli/CopyDirCept.php @@ -1,8 +1,10 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); + $I->wantTo('copy dir with CopyDir task'); $I->amInPath(codecept_data_dir().'sandbox'); -$I->taskCopyDir(['box' => 'bin']) +$I->getContainer()->get('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..aa405f6f9 100644 --- a/tests/cli/CopyDirOverwritesFilesCept.php +++ b/tests/cli/CopyDirOverwritesFilesCept.php @@ -1,10 +1,12 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); + $I->wantTo('overwrite a file with CopyDir task'); $I->amInPath(codecept_data_dir() . 'sandbox'); $I->seeDirFound('some'); $I->seeFileFound('existing_file', 'some'); -$I->taskCopyDir(['some' => 'some_destination']) +$I->getContainer()->get('taskCopyDir', [['some' => 'some_destination']]) ->run(); $I->seeFileFound('existing_file', 'some_destination/deeply'); $I->openFile('some_destination/deeply/existing_file'); diff --git a/tests/cli/CopyDirRecursiveCept.php b/tests/cli/CopyDirRecursiveCept.php index 7ca8e4fd1..1034e4f97 100644 --- a/tests/cli/CopyDirRecursiveCept.php +++ b/tests/cli/CopyDirRecursiveCept.php @@ -1,10 +1,12 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); + $I->wantTo('copy dir recursively with CopyDir task'); $I->amInPath(codecept_data_dir() . 'sandbox'); $I->seeDirFound('some/deeply/nested'); $I->seeFileFound('structu.re', 'some/deeply/nested'); -$I->taskCopyDir(['some/deeply' => 'some_destination/deeply']) +$I->getContainer()->get('taskCopyDir', [['some/deeply' => 'some_destination/deeply']]) ->run(); $I->seeDirFound('some_destination/deeply/nested'); $I->seeFileFound('structu.re', 'some_destination/deeply/nested'); diff --git a/tests/cli/DeleteDirCept.php b/tests/cli/DeleteDirCept.php index b42bfe5eb..635f77abe 100644 --- a/tests/cli/DeleteDirCept.php +++ b/tests/cli/DeleteDirCept.php @@ -1,9 +1,12 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); + $I->wantTo('delete dir with DeleteDirTask'); $I->amInPath(codecept_data_dir()); $I->seeFileFound('robo.txt', 'sandbox'); -$I->taskDeleteDir(['sandbox/box']) +$I->getContainer()->get('taskDeleteDir', [['sandbox/box']]) ->run(); $I->dontSeeFileFound('box', 'sandbox'); $I->dontSeeFileFound('robo.txt', 'sandbox'); diff --git a/tests/cli/ExecCest.php b/tests/cli/ExecCest.php index e2cb5449f..e3f99d208 100644 --- a/tests/cli/ExecCest.php +++ b/tests/cli/ExecCest.php @@ -1,12 +1,18 @@ getContainer()->addServiceProvider(\Robo\Task\Base\ServiceProvider::class); + } + // tests public function toExecLsCommand(CliGuy $I) { $command = strncasecmp(PHP_OS, 'WIN', 3) == 0 ? 'dir' : 'ls'; - $res = $I->taskExec($command)->run(); + $res = $I->getContainer()->get('taskExec', [$command])->run(); 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..824b5ecf6 100644 --- a/tests/cli/FileSystemStackCest.php +++ b/tests/cli/FileSystemStackCest.php @@ -1,14 +1,16 @@ getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); $I->amInPath(codecept_data_dir().'sandbox'); } public function toCreateDir(CliGuy $I) { - $I->taskFileSystemStack() + $I->getContainer()->get('taskFileSystemStack') ->mkdir('log') ->touch('log/error.txt') ->run(); @@ -17,7 +19,7 @@ public function toCreateDir(CliGuy $I) public function toDeleteFile(CliGuy $I) { - $I->taskFileSystemStack() + $I->getContainer()->get('taskFileSystemStack') ->stopOnFail() ->remove('a.txt') ->run(); diff --git a/tests/cli/FlattenDirCept.php b/tests/cli/FlattenDirCept.php index 63074a477..cfc930d69 100644 --- a/tests/cli/FlattenDirCept.php +++ b/tests/cli/FlattenDirCept.php @@ -1,11 +1,13 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); + $I->wantTo('flatten dir with FlattenDir task'); $I->amInPath(codecept_data_dir().'sandbox'); -$I->taskFlattenDir([ +$I->getContainer()->get('taskFlattenDir', [[ 'some/deeply/nested/*.re' => 'flattened', '*.txt' => 'flattened' - ]) + ]]) ->run(); $I->seeDirFound('flattened'); $I->seeFileFound('structu.re', 'flattened'); diff --git a/tests/cli/FlattenDirParentsCept.php b/tests/cli/FlattenDirParentsCept.php index 877610e0b..5ad4fc965 100644 --- a/tests/cli/FlattenDirParentsCept.php +++ b/tests/cli/FlattenDirParentsCept.php @@ -1,8 +1,10 @@ -getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); + $I->wantTo('flatten dir with FlattenDir task including parents'); $I->amInPath(codecept_data_dir().'sandbox'); -$I->taskFlattenDir(['some/deeply/nested/*.re']) +$I->getContainer()->get('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..649f90a1f 100644 --- a/tests/cli/PackExtractCept.php +++ b/tests/cli/PackExtractCept.php @@ -1,6 +1,8 @@ getContainer()->addServiceProvider(\Robo\Task\Archive\ServiceProvider::class); + $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'); @@ -11,7 +13,7 @@ foreach (['zip', 'tar', 'tar.gz', 'tar.bz2', 'tgz'] as $archiveType) { // First, take everything from the folder 'some/deeply' and make // an archive for it located in 'deep' - $I->taskPack("deeply.$archiveType") + $I->getContainer()->get('taskPack', ["deeply.$archiveType"]) ->add(['deep' => 'some/deeply']) ->run(); $I->seeFileFound("deeply.$archiveType"); @@ -20,7 +22,7 @@ // for each archive type we test). We rely on the default behavior // of our extractor to remove the top-level directory in the archive // ("deeply"). - $I->taskExtract("deeply.$archiveType") + $I->getContainer()->get('taskExtract', ["deeply.$archiveType"]) ->to("extracted-$archiveType") ->preserveTopDirectory(false) // this is the default ->run(); @@ -29,7 +31,7 @@ $I->seeFileFound('structu.re', "extracted-$archiveType/nested"); // Next, we'll extract the same archive again, this time preserving // the top-level folder. - $I->taskExtract("deeply.$archiveType") + $I->getContainer()->get('taskExtract', ["deeply.$archiveType"]) ->to("preserved-$archiveType") ->preserveTopDirectory() ->run(); @@ -37,14 +39,14 @@ $I->seeDirFound("preserved-$archiveType/deep/nested"); $I->seeFileFound('structu.re', "preserved-$archiveType/deep/nested"); // Make another archive, this time composed of fanciful locations - $I->taskPack("composed.$archiveType") + $I->getContainer()->get('taskPack', ["composed.$archiveType"]) ->add(['a/b/existing_file' => 'some/deeply/existing_file']) ->add(['x/y/z/structu.re' => 'some/deeply/nested/structu.re']) ->run(); $I->seeFileFound("composed.$archiveType"); // Extract our composed archive, and see if the resulting file // structure matches expectations. - $I->taskExtract("composed.$archiveType") + $I->getContainer()->get('taskExtract', ["composed.$archiveType"]) ->to("decomposed-$archiveType") ->preserveTopDirectory() ->run(); diff --git a/tests/cli/WriteFileCest.php b/tests/cli/WriteFileCest.php index 913da8b69..a4403371d 100644 --- a/tests/cli/WriteFileCest.php +++ b/tests/cli/WriteFileCest.php @@ -1,15 +1,17 @@ getContainer()->addServiceProvider(\Robo\Task\File\ServiceProvider::class); $I->amInPath(codecept_data_dir('sandbox')); } public function writeFewLines(CliGuy $I) { $I->wantTo('write lines with WriteToFile task'); - $I->taskWriteToFile('blogpost.md') + $I->getContainer()->get('taskWriteToFile', ['blogpost.md']) ->line('****') ->line('hello world') ->line('****') @@ -26,7 +28,7 @@ public function writeFewLines(CliGuy $I) public function appendToFile(CliGuy $I) { - $I->taskWriteToFile('a.txt') + $I->getContainer()->get('taskWriteToFile', ['a.txt']) ->append() ->line('hello world') ->run(); @@ -40,7 +42,7 @@ public function appendToFile(CliGuy $I) public function insertFile(CliGuy $I) { - $I->taskWriteToFile('a.txt') + $I->getContainer()->get('taskWriteToFile', ['a.txt']) ->line('****') ->textFromFile('b.txt') ->line("C") @@ -56,18 +58,18 @@ public function insertFile(CliGuy $I) public function replaceInFile(CliGuy $I) { - $I->taskReplaceInFile('a.txt') + $I->getContainer()->get('taskReplaceInFile', ['a.txt']) ->from('A') ->to('B') ->run(); $I->seeFileFound('a.txt'); $I->seeFileContentsEqual('B'); - + } public function replaceMultipleInFile(CliGuy $I) { - $I->taskReplaceInFile('box/robo.txt') + $I->getContainer()->get('taskReplaceInFile', ['box/robo.txt']) ->from(array('HELLO', 'ROBO')) ->to(array('Hello ', 'robo.li!')) ->run(); 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 149d71ede..07dc983f2 100644 --- a/tests/unit/Task/ApiGenTest.php +++ b/tests/unit/Task/ApiGenTest.php @@ -1,11 +1,12 @@ null, 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\ApiGen\ServiceProvider::class); } // tests @@ -29,7 +33,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 @@ -47,5 +51,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 bd50ea1dc..870bddfdc 100644 --- a/tests/unit/Task/BowerTest.php +++ b/tests/unit/Task/BowerTest.php @@ -1,11 +1,11 @@ baseBower = test::double('Robo\Task\Bower\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(Robo\Task\Bower\ServiceProvider::class); } // 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() diff --git a/tests/unit/Task/CodeceptionTest.php b/tests/unit/Task/CodeceptionTest.php index d03ac6f22..3ada89396 100644 --- a/tests/unit/Task/CodeceptionTest.php +++ b/tests/unit/Task/CodeceptionTest.php @@ -1,9 +1,12 @@ null, 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Testing\ServiceProvider::class); } // 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 +54,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 +62,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'); } } diff --git a/tests/unit/Task/CollectionTest.php b/tests/unit/Task/CollectionTest.php index 528375c7e..b144720e8 100644 --- a/tests/unit/Task/CollectionTest.php +++ b/tests/unit/Task/CollectionTest.php @@ -10,12 +10,23 @@ use Robo\Task\BaseTask; use Robo\Contract\TaskInterface; use Robo\Collection\Collection; +use Robo\Runner; +use Robo\Container\RoboContainer; class CollectionTest extends \Codeception\TestCase\Test { + protected $container; + + protected function _before() + { + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Collection\ServiceProvider::class); + } + 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..70f6355b8 100644 --- a/tests/unit/Task/CommandStackTest.php +++ b/tests/unit/Task/CommandStackTest.php @@ -1,8 +1,18 @@ container = new RoboContainer(); + Runner::configureContainer($this->container); + } + 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 a6b485e34..e8d2e1f17 100644 --- a/tests/unit/Task/ComposerTest.php +++ b/tests/unit/Task/ComposerTest.php @@ -1,11 +1,11 @@ baseComposer = test::double('Robo\Task\Composer\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Composer\ServiceProvider::class); } // 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']); @@ -42,10 +44,10 @@ 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']); @@ -55,20 +57,20 @@ 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(); @@ -78,11 +80,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() @@ -93,18 +95,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() @@ -115,23 +117,23 @@ 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() diff --git a/tests/unit/Task/ExecTaskTest.php b/tests/unit/Task/ExecTaskTest.php index 709aa70c7..77c6cdc0a 100644 --- a/tests/unit/Task/ExecTaskTest.php +++ b/tests/unit/Task/ExecTaskTest.php @@ -1,11 +1,12 @@ 0 ]); test::double('Robo\Task\Base\Exec', ['getOutput' => new \Symfony\Component\Console\Output\NullOutput()]); - $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Base\ServiceProvider::class); } 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); @@ -33,7 +36,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); @@ -41,12 +44,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') @@ -56,7 +59,7 @@ public function testExecStack() public function testExecStackCommand() { - verify($this->taskExecStack() + verify($this->container->get('taskExecStack') ->exec('ls') ->exec('cd /') ->exec('cd home') diff --git a/tests/unit/Task/GitTest.php b/tests/unit/Task/GitTest.php index 80458b013..ffe4050f2 100644 --- a/tests/unit/Task/GitTest.php +++ b/tests/unit/Task/GitTest.php @@ -1,12 +1,13 @@ new \AspectMock\Proxy\Anything(), 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Vcs\ServiceProvider::class); } // 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') diff --git a/tests/unit/Task/GulpTest.php b/tests/unit/Task/GulpTest.php index 720432d8c..975a36417 100644 --- a/tests/unit/Task/GulpTest.php +++ b/tests/unit/Task/GulpTest.php @@ -1,11 +1,12 @@ baseGulp = test::double('Robo\Task\Gulp\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Gulp\ServiceProvider::class); } // tests @@ -27,61 +30,61 @@ 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'); } } diff --git a/tests/unit/Task/NpmTest.php b/tests/unit/Task/NpmTest.php index 6b6f477af..2ab8591e5 100644 --- a/tests/unit/Task/NpmTest.php +++ b/tests/unit/Task/NpmTest.php @@ -1,11 +1,11 @@ baseNpm = test::double('Robo\Task\Npm\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Npm\ServiceProvider::class); } + // 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'); diff --git a/tests/unit/Task/PHPServerTest.php b/tests/unit/Task/PHPServerTest.php index 8e3f18613..c9197be02 100644 --- a/tests/unit/Task/PHPServerTest.php +++ b/tests/unit/Task/PHPServerTest.php @@ -1,11 +1,13 @@ 0 ]); test::double('Robo\Task\Development\PhpServer', ['getOutput' => new \Symfony\Component\Console\Output\NullOutput()]); - $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Development\ServiceProvider::class); } 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'); } @@ -44,7 +48,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 6a6f6b882..7e9c14627 100644 --- a/tests/unit/Task/PHPUnitTest.php +++ b/tests/unit/Task/PHPUnitTest.php @@ -1,11 +1,12 @@ null, 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Testing\ServiceProvider::class); } // tests @@ -26,13 +29,13 @@ 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') diff --git a/tests/unit/Task/ParallelExecTest.php b/tests/unit/Task/ParallelExecTest.php index 948046c17..d39938c43 100644 --- a/tests/unit/Task/ParallelExecTest.php +++ b/tests/unit/Task/ParallelExecTest.php @@ -1,11 +1,12 @@ 'Hello world', 'getExitCode' => 0 ]); - $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Base\ServiceProvider::class); } public function testParallelExec() { - $result = $this->taskParallelExec() + $result = $this->container->get('taskParallelExec') ->process('ls 1') ->process('ls 2') ->process('ls 3') diff --git a/tests/unit/Task/PhpspecTest.php b/tests/unit/Task/PhpspecTest.php index 54e42aba4..d7da1b9f7 100644 --- a/tests/unit/Task/PhpspecTest.php +++ b/tests/unit/Task/PhpspecTest.php @@ -1,11 +1,12 @@ null, 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Testing\ServiceProvider::class); } // 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() diff --git a/tests/unit/Task/RsyncTest.php b/tests/unit/Task/RsyncTest.php index a07522dd1..f05c80842 100644 --- a/tests/unit/Task/RsyncTest.php +++ b/tests/unit/Task/RsyncTest.php @@ -1,27 +1,30 @@ setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); - } - /** * @var \CodeGuy */ protected $guy; + protected $container; + + protected function _before() + { + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Remote\ServiceProvider::class); + } + // 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 7278d2ee7..c8f81f911 100644 --- a/tests/unit/Task/SemVerTest.php +++ b/tests/unit/Task/SemVerTest.php @@ -1,21 +1,24 @@ setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Development\ServiceProvider::class); } 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') @@ -30,7 +33,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 2d24b40e8..e8a1a67c1 100644 --- a/tests/unit/Task/SshTest.php +++ b/tests/unit/Task/SshTest.php @@ -1,21 +1,25 @@ setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Remote\ServiceProvider::class); } + // 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() @@ -25,7 +29,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') @@ -40,24 +44,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 8a06464d5..3cbf5a034 100644 --- a/tests/unit/Task/SvnTest.php +++ b/tests/unit/Task/SvnTest.php @@ -1,12 +1,13 @@ new \AspectMock\Proxy\Anything(), 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->setTaskAssembler(new \Robo\TaskAssembler(Config::logger())); + + $this->container = new RoboContainer(); + Runner::configureContainer($this->container); + $this->container->addServiceProvider(\Robo\Task\Vcs\ServiceProvider::class); } // tests @@ -31,7 +35,7 @@ public function testSvnStackRun() public function testSvnStackCommands() { verify( - $this->taskSvnStack('guest', 'foo') + $this->container->get('taskSvnStack', ['guest', 'foo']) ->checkout('svn://server/trunk') ->update() ->add() From 269e6d0b025c5c873bac4e9bb481dfca737a035b Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Mon, 14 Mar 2016 16:56:19 -0700 Subject: [PATCH 13/34] Filter out accessor methods from command list. --- src/Application.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Application.php b/src/Application.php index db262ce99..64082104a 100644 --- a/src/Application.php +++ b/src/Application.php @@ -31,8 +31,11 @@ public function addCommandsFromClass($className, $passThrough = null) $roboTasks->setContainer($container); } + // 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 !in_array($m, ['__construct']); + return !preg_match('#^(_|get[A-Z]|set[A-Z])#', $m); }); foreach ($commandNames as $commandName) { From 40b1bf525e311e5f525c354c93cbc39451c86d74 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Mon, 14 Mar 2016 17:01:18 -0700 Subject: [PATCH 14/34] Fix spacing for NitPick. --- src/Application.php | 4 ++-- src/Container/RoboContainer.php | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Application.php b/src/Application.php index 64082104a..44b500a32 100644 --- a/src/Application.php +++ b/src/Application.php @@ -10,7 +10,7 @@ use League\Container\ContainerAwareInterface; use League\Container\ContainerAwareTrait; -class Application extends SymfonyApplication implements ContainerAwareInterface +class Application extends SymfonyApplication implements ContainerAwareInterface { use ContainerAwareTrait; @@ -40,7 +40,7 @@ public function addCommandsFromClass($className, $passThrough = null) foreach ($commandNames as $commandName) { $command = $this->createCommand(new TaskInfo($className, $commandName)); - $command->setCode(function(InputInterface $input) use ($roboTasks, $commandName, $passThrough, $container) { + $command->setCode(function (InputInterface $input) use ($roboTasks, $commandName, $passThrough, $container) { // get passthru args $args = $input->getArguments(); array_shift($args); diff --git a/src/Container/RoboContainer.php b/src/Container/RoboContainer.php index 8069a0be4..08a8b8182 100644 --- a/src/Container/RoboContainer.php +++ b/src/Container/RoboContainer.php @@ -17,11 +17,10 @@ class RoboContainer extends Container protected $simulated; public function __construct( - ServiceProviderAggregateInterface $providers = null, - InflectorAggregateInterface $inflectors = null, - DefinitionFactoryInterface $definitionFactory = null - ) - { + ServiceProviderAggregateInterface $providers = null, + InflectorAggregateInterface $inflectors = null, + DefinitionFactoryInterface $definitionFactory = null + ) { parent::__construct($providers, $inflectors, $definitionFactory); $this->simulated = false; } From ff7850b83b47a20175b9d4ab74300aae40a48311 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Mon, 14 Mar 2016 17:55:11 -0700 Subject: [PATCH 15/34] Introdoce 'task' convenience function to make fetching task services look more like the original API. --- RoboFile.php | 50 ++++++++++++------------ src/Tasks.php | 25 ++++++++++++ tests/_helpers/CliGuy.php | 6 +++ tests/cli/CleanDirCept.php | 2 +- tests/cli/CollectionCest.php | 24 ++++++------ tests/cli/ConcatCept.php | 2 +- tests/cli/CopyDirCept.php | 2 +- tests/cli/CopyDirOverwritesFilesCept.php | 2 +- tests/cli/CopyDirRecursiveCept.php | 2 +- tests/cli/DeleteDirCept.php | 2 +- tests/cli/ExecCest.php | 2 +- tests/cli/FileSystemStackCest.php | 4 +- tests/cli/FlattenDirCept.php | 4 +- tests/cli/FlattenDirParentsCept.php | 2 +- tests/cli/PackExtractCept.php | 10 ++--- tests/cli/WriteFileCest.php | 10 ++--- 16 files changed, 90 insertions(+), 59 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 65ad92974..958cd18fb 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -75,7 +75,7 @@ public function release() $this->yell("Releasing Robo"); $this->docs(); - $this->taskGitStack() + $this->task('GitStack') ->add('-A') ->commit("auto-update") ->pull() @@ -85,7 +85,7 @@ public function release() $this->pharPublish(); $this->publish(); - $this->taskGitHubRelease(\Robo\Runner::VERSION) + $this->task('GitHubRelease', \Robo\Runner::VERSION) ->uri('Codegyre/Robo') ->askDescription() ->run(); @@ -95,14 +95,14 @@ public function release() public function test($args = "") { - return $this->taskCodecept() + return $this->task('Codecept') ->args($args) ->run(); } public function changed($addition) { - $this->taskChangelog() + $this->task('Changelog') ->version(\Robo\Runner::VERSION) ->change($addition) ->run(); @@ -115,7 +115,7 @@ public function versionBump($version = null) $versionParts[count($versionParts)-1]++; $version = implode('.', $versionParts); } - $this->taskReplaceInFile(__DIR__.'/src/Runner.php') + $this->task('ReplaceInFile', __DIR__.'/src/Runner.php') ->from("VERSION = '".\Robo\Runner::VERSION."'") ->to("VERSION = '".$version."'") ->run(); @@ -147,7 +147,7 @@ class_exists($class = "Robo\\Task\\$ns\\$class"); ksort($docs); foreach ($docs as $ns => $tasks) { - $taskGenerator = $this->taskGenDoc("docs/tasks/$ns.md"); + $taskGenerator = $this->task('GenDoc', "docs/tasks/$ns.md"); $taskGenerator->filterClasses(function (\ReflectionClass $r) { return !($r->isAbstract() or $r->isTrait()) and $r->implementsInterface('Robo\Contract\TaskInterface'); })->prepend("# $ns Tasks"); @@ -195,20 +195,20 @@ public function publish() $current_branch = exec('git rev-parse --abbrev-ref HEAD'); $collection = $this->collection(); - $this->taskGitStack() + $this->task('GitStack') ->checkout('site') ->merge('master') ->addToCollection($collection); - $this->taskGitStack() + $this->task('GitStack') ->checkout($current_branch) ->addAsCompletion($collection); - $this->taskFilesystemStack() + $this->task('FilesystemStack') ->copy('CHANGELOG.md', 'docs/changelog.md') ->addToCollection($collection); - $this->taskFilesystemStack() + $this->task('FilesystemStack') ->remove('docs/changelog.md') ->addAsCompletion($collection); - $this->taskExec('mkdocs gh-deploy') + $this->task('Exec', 'mkdocs gh-deploy') ->addToCollection($collection); $collection->run(); } @@ -217,12 +217,12 @@ public function pharBuild() { $collection = $this->collection(); - $this->taskComposerInstall() + $this->task('ComposerInstall') ->noDev() ->printed(false) ->addToCollection($collection); - $packer = $this->taskPackPhar('robo.phar'); + $packer = $this->task('PackPhar', 'robo.phar'); $files = Finder::create()->ignoreVCS(true) ->files() ->name('*.php') @@ -243,7 +243,7 @@ public function pharBuild() ->executable('robo') ->addToCollection($collection); - $this->taskComposerInstall() + $this->task('ComposerInstall') ->printed(false) ->addToCollection($collection); @@ -252,7 +252,7 @@ public function pharBuild() public function pharInstall() { - $this->taskExec('sudo cp') + $this->task('Exec', 'sudo cp') ->arg('robo.phar') ->arg('/usr/bin/robo') ->run(); @@ -263,12 +263,12 @@ public function pharPublish() $this->pharBuild(); $this->_rename('robo.phar', 'robo-release.phar'); - $this->taskGitStack()->checkout('gh-pages')->run(); - $this->taskFilesystemStack() + $this->task('GitStack')->checkout('gh-pages')->run(); + $this->task('FilesystemStack') ->remove('robo.phar') ->rename('robo-release.phar', 'robo.phar') ->run(); - $this->taskGitStack() + $this->task('GitStack') ->add('robo.phar') ->commit('robo.phar published') ->push('origin','gh-pages') @@ -278,8 +278,8 @@ public function pharPublish() public function tryWatch() { - $this->taskWatch()->monitor(['composer.json', 'composer.lock'], function() { - $this->taskComposerUpdate()->run(); + $this->task('Watch')->monitor(['composer.json', 'composer.lock'], function() { + $this->task('ComposerUpdate')->run(); })->run(); } @@ -301,7 +301,7 @@ public function tryInput() */ public function tryPara() { - $this->taskParallelExec() + $this->task('ParallelExec') ->process('php ~/demos/robotests/parascript.php hey') ->process('php ~/demos/robotests/parascript.php hoy') ->process('php ~/demos/robotests/parascript.php gou') @@ -316,7 +316,7 @@ public function tryOptbool($opts = ['silent|s' => false]) public function tryServer() { - $this->taskServer(8000) + $this->task('Server', 8000) ->dir('site') ->arg('site/index.php') ->run(); @@ -324,7 +324,7 @@ public function tryServer() public function tryOpenBrowser() { - $this->taskOpenBrowser([ + $this->task('OpenBrowser', [ 'http://robo.li', 'https://github.com/Codegyre/Robo' ]) @@ -339,11 +339,11 @@ public function tryInteractive() public function tryError() { - $result = $this->taskExec('ls xyzzy' . date('U'))->dir('/tmp')->run(); + $result = $this->task('Exec', 'ls xyzzy' . date('U'))->dir('/tmp')->run(); } public function trySuccess() { - $result = $this->taskExec('pwd')->run(); + $result = $this->task('Exec', 'pwd')->run(); } } diff --git a/src/Tasks.php b/src/Tasks.php index 102979e3c..8483df110 100644 --- a/src/Tasks.php +++ b/src/Tasks.php @@ -20,11 +20,36 @@ protected function stopOnFail($stopOnFail = true) Result::$stopOnFail = $stopOnFail; } + /** + * 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]); + */ + protected function task() + { + $args = func_get_args(); + $name = array_shift($args); + return $this->getContainer()->get("task$name", $args); + } + /** * Backwards compatibility: convert $this->taskFoo($a, $b) into * $this->getContainer()->get('taskFoo', [$a, $b]); diff --git a/tests/_helpers/CliGuy.php b/tests/_helpers/CliGuy.php index 7aa44ab4e..ab4e5f2c2 100644 --- a/tests/_helpers/CliGuy.php +++ b/tests/_helpers/CliGuy.php @@ -28,4 +28,10 @@ class CliGuy extends \Codeception\Actor /** * Define custom actions here */ + public function task() + { + $args = func_get_args(); + $name = array_shift($args); + return $this->getContainer()->get("task$name", $args); + } } diff --git a/tests/cli/CleanDirCept.php b/tests/cli/CleanDirCept.php index 421e8ee66..7cb2c5cb4 100644 --- a/tests/cli/CleanDirCept.php +++ b/tests/cli/CleanDirCept.php @@ -5,7 +5,7 @@ $I->wantTo('clean dir with DeleteDirTask'); $I->amInPath(codecept_data_dir()); $I->seeFileFound('robo.txt', 'sandbox'); -$I->getContainer()->get('taskCleanDir', [['sandbox']]) +$I->task('CleanDir', ['sandbox']) ->run(); $I->dontSeeFileFound('box', 'sandbox'); $I->dontSeeFileFound('robo.txt', 'sandbox'); diff --git a/tests/cli/CollectionCest.php b/tests/cli/CollectionCest.php index 36ff7a090..458a3be5a 100644 --- a/tests/cli/CollectionCest.php +++ b/tests/cli/CollectionCest.php @@ -24,7 +24,7 @@ public function toCreateDirViaCollection(CliGuy $I) $collection = $I->getContainer()->get('collection'); // Set up a filesystem stack, but use addToCollection() to defer execution - $I->getContainer()->get('taskFileSystemStack') + $I->task('FileSystemStack') ->mkdir('log') ->touch('log/error.txt') ->addToCollection($collection); @@ -47,7 +47,7 @@ public function toUseATmpDirAndConfirmItIsDeleted(CliGuy $I) // 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 = $I->getContainer()->get('taskTmpDir') + $tmpPath = $I->task('TmpDir') ->addToCollection($collection) ->getPath(); @@ -60,13 +60,13 @@ public function toUseATmpDirAndConfirmItIsDeleted(CliGuy $I) $I->seeDirFound($tmpPath); // Set up a filesystem stack, but use addToCollection() to defer execution - $I->getContainer()->get('taskFileSystemStack') + $I->task('FileSystemStack') ->mkdir("$tmpPath/log") ->touch("$tmpPath/log/error.txt") ->addToCollection($collection); // Copy our tmp directory to a location that is not transient - $I->getContainer()->get('taskCopyDir', [[$tmpPath => 'copied']]) + $I->task('CopyDir', [$tmpPath => 'copied']) ->addToCollection($collection); // FileSystemStack has not run yet, so no files should be found. @@ -94,7 +94,7 @@ public function toUseATmpDirAndChangeWorkingDirectory(CliGuy $I) // 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 = $I->getContainer()->get('taskTmpDir') + $tmpPath = $I->task('TmpDir') ->cwd() ->addToCollection($collection) ->getPath(); @@ -102,13 +102,13 @@ public function toUseATmpDirAndChangeWorkingDirectory(CliGuy $I) // Set up a filesystem stack, but use addToCollection() to defer execution. // Note that since we used 'cwd()' above, the relative file paths // used below will be inside the temporary directory. - $I->getContainer()->get('taskFileSystemStack') + $I->task('FileSystemStack') ->mkdir("log") ->touch("log/error.txt") ->addToCollection($collection); // Copy our tmp directory to a location that is not transient - $I->getContainer()->get('taskCopyDir', [['log' => "$cwd/copied2"]]) + $I->task('CopyDir', ['log' => "$cwd/copied2"]) ->addToCollection($collection); // FileSystemStack has not run yet, so no files should be found. @@ -140,13 +140,13 @@ public function toCreateATmpFileAndConfirmItIsDeleted(CliGuy $I) // Write to a temporary file. Note that we can get the path // to the tempoary file that will be created, even though the // the file is not created until the task collecction runs. - $tmpPath = $I->getContainer()->get('taskTmpFile', ['tmp', '.txt']) + $tmpPath = $I->task('TmpFile', 'tmp', '.txt') ->line("This is a test file") ->addToCollection($collection) ->getPath(); // Copy our tmp directory to a location that is not transient - $I->getContainer()->get('taskFileSystemStack') + $I->task('FileSystemStack') ->copy($tmpPath, 'copied.txt') ->addToCollection($collection); @@ -173,7 +173,7 @@ public function toUseATmpDirWithAlternateSyntax(CliGuy $I) // We start off the same way, using addToCollection() to add our temporary // directory task to the collection, so that we have easy access to the // temporary directory's path via the getPath() method. - $tmpPath = $I->getContainer()->get('taskTmpDir') + $tmpPath = $I->task('TmpDir') ->addToCollection($collection) ->getPath(); @@ -182,8 +182,8 @@ public function toUseATmpDirWithAlternateSyntax(CliGuy $I) // via the add() method. $result = $collection->add( [ - $I->getContainer()->get('taskFileSystemStack')->mkdir("$tmpPath/log")->touch("$tmpPath/log/error.txt"), - $I->getContainer()->get('taskCopyDir', [[$tmpPath => 'copied3']]), + $I->task('FileSystemStack')->mkdir("$tmpPath/log")->touch("$tmpPath/log/error.txt"), + $I->task('CopyDir', [$tmpPath => 'copied3']), ] )->run(); diff --git a/tests/cli/ConcatCept.php b/tests/cli/ConcatCept.php index 0aa2b6472..7319987ba 100644 --- a/tests/cli/ConcatCept.php +++ b/tests/cli/ConcatCept.php @@ -4,7 +4,7 @@ $I->wantTo('concat files using Concat Task'); $I->amInPath(codecept_data_dir() . 'sandbox'); -$I->getContainer()->get('taskConcat', [['a.txt', 'b.txt']]) +$I->task('Concat', ['a.txt', 'b.txt']) ->to('merged.txt') ->run(); $I->seeFileFound('merged.txt'); diff --git a/tests/cli/CopyDirCept.php b/tests/cli/CopyDirCept.php index 91e87b0e6..b09318a9a 100644 --- a/tests/cli/CopyDirCept.php +++ b/tests/cli/CopyDirCept.php @@ -4,7 +4,7 @@ $I->wantTo('copy dir with CopyDir task'); $I->amInPath(codecept_data_dir().'sandbox'); -$I->getContainer()->get('taskCopyDir', [['box' => 'bin']]) +$I->task('CopyDir', ['box' => 'bin']) ->run(); $I->seeDirFound('bin'); $I->seeFileFound('robo.txt', 'bin'); diff --git a/tests/cli/CopyDirOverwritesFilesCept.php b/tests/cli/CopyDirOverwritesFilesCept.php index aa405f6f9..292af2ffe 100644 --- a/tests/cli/CopyDirOverwritesFilesCept.php +++ b/tests/cli/CopyDirOverwritesFilesCept.php @@ -6,7 +6,7 @@ $I->amInPath(codecept_data_dir() . 'sandbox'); $I->seeDirFound('some'); $I->seeFileFound('existing_file', 'some'); -$I->getContainer()->get('taskCopyDir', [['some' => 'some_destination']]) +$I->task('CopyDir', ['some' => 'some_destination']) ->run(); $I->seeFileFound('existing_file', 'some_destination/deeply'); $I->openFile('some_destination/deeply/existing_file'); diff --git a/tests/cli/CopyDirRecursiveCept.php b/tests/cli/CopyDirRecursiveCept.php index 1034e4f97..8550d4580 100644 --- a/tests/cli/CopyDirRecursiveCept.php +++ b/tests/cli/CopyDirRecursiveCept.php @@ -6,7 +6,7 @@ $I->amInPath(codecept_data_dir() . 'sandbox'); $I->seeDirFound('some/deeply/nested'); $I->seeFileFound('structu.re', 'some/deeply/nested'); -$I->getContainer()->get('taskCopyDir', [['some/deeply' => 'some_destination/deeply']]) +$I->task('CopyDir', ['some/deeply' => 'some_destination/deeply']) ->run(); $I->seeDirFound('some_destination/deeply/nested'); $I->seeFileFound('structu.re', 'some_destination/deeply/nested'); diff --git a/tests/cli/DeleteDirCept.php b/tests/cli/DeleteDirCept.php index 635f77abe..dcf7af588 100644 --- a/tests/cli/DeleteDirCept.php +++ b/tests/cli/DeleteDirCept.php @@ -6,7 +6,7 @@ $I->wantTo('delete dir with DeleteDirTask'); $I->amInPath(codecept_data_dir()); $I->seeFileFound('robo.txt', 'sandbox'); -$I->getContainer()->get('taskDeleteDir', [['sandbox/box']]) +$I->task('DeleteDir', ['sandbox/box']) ->run(); $I->dontSeeFileFound('box', 'sandbox'); $I->dontSeeFileFound('robo.txt', 'sandbox'); diff --git a/tests/cli/ExecCest.php b/tests/cli/ExecCest.php index e3f99d208..4cc3f0026 100644 --- a/tests/cli/ExecCest.php +++ b/tests/cli/ExecCest.php @@ -11,7 +11,7 @@ public function _before(CliGuy $I) public function toExecLsCommand(CliGuy $I) { $command = strncasecmp(PHP_OS, 'WIN', 3) == 0 ? 'dir' : 'ls'; - $res = $I->getContainer()->get('taskExec', [$command])->run(); + $res = $I->task('Exec', $command)->run(); verify($res->getMessage())->contains('src'); verify($res->getMessage())->contains('codeception.yml'); } diff --git a/tests/cli/FileSystemStackCest.php b/tests/cli/FileSystemStackCest.php index 824b5ecf6..5aba6d6e1 100644 --- a/tests/cli/FileSystemStackCest.php +++ b/tests/cli/FileSystemStackCest.php @@ -10,7 +10,7 @@ public function _before(CliGuy $I) public function toCreateDir(CliGuy $I) { - $I->getContainer()->get('taskFileSystemStack') + $I->task('FileSystemStack') ->mkdir('log') ->touch('log/error.txt') ->run(); @@ -19,7 +19,7 @@ public function toCreateDir(CliGuy $I) public function toDeleteFile(CliGuy $I) { - $I->getContainer()->get('taskFileSystemStack') + $I->task('FileSystemStack') ->stopOnFail() ->remove('a.txt') ->run(); diff --git a/tests/cli/FlattenDirCept.php b/tests/cli/FlattenDirCept.php index cfc930d69..377fd2f27 100644 --- a/tests/cli/FlattenDirCept.php +++ b/tests/cli/FlattenDirCept.php @@ -4,10 +4,10 @@ $I->wantTo('flatten dir with FlattenDir task'); $I->amInPath(codecept_data_dir().'sandbox'); -$I->getContainer()->get('taskFlattenDir', [[ +$I->task('FlattenDir', [ 'some/deeply/nested/*.re' => 'flattened', '*.txt' => 'flattened' - ]]) + ]) ->run(); $I->seeDirFound('flattened'); $I->seeFileFound('structu.re', 'flattened'); diff --git a/tests/cli/FlattenDirParentsCept.php b/tests/cli/FlattenDirParentsCept.php index 5ad4fc965..1f6c0a14f 100644 --- a/tests/cli/FlattenDirParentsCept.php +++ b/tests/cli/FlattenDirParentsCept.php @@ -4,7 +4,7 @@ $I->wantTo('flatten dir with FlattenDir task including parents'); $I->amInPath(codecept_data_dir().'sandbox'); -$I->getContainer()->get('taskFlattenDir', [['some/deeply/nested/*.re']]) +$I->task('FlattenDir', '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 649f90a1f..b617ad25b 100644 --- a/tests/cli/PackExtractCept.php +++ b/tests/cli/PackExtractCept.php @@ -13,7 +13,7 @@ foreach (['zip', 'tar', 'tar.gz', 'tar.bz2', 'tgz'] as $archiveType) { // First, take everything from the folder 'some/deeply' and make // an archive for it located in 'deep' - $I->getContainer()->get('taskPack', ["deeply.$archiveType"]) + $I->task('Pack', "deeply.$archiveType") ->add(['deep' => 'some/deeply']) ->run(); $I->seeFileFound("deeply.$archiveType"); @@ -22,7 +22,7 @@ // for each archive type we test). We rely on the default behavior // of our extractor to remove the top-level directory in the archive // ("deeply"). - $I->getContainer()->get('taskExtract', ["deeply.$archiveType"]) + $I->task('Extract', "deeply.$archiveType") ->to("extracted-$archiveType") ->preserveTopDirectory(false) // this is the default ->run(); @@ -31,7 +31,7 @@ $I->seeFileFound('structu.re', "extracted-$archiveType/nested"); // Next, we'll extract the same archive again, this time preserving // the top-level folder. - $I->getContainer()->get('taskExtract', ["deeply.$archiveType"]) + $I->task('Extract', "deeply.$archiveType") ->to("preserved-$archiveType") ->preserveTopDirectory() ->run(); @@ -39,14 +39,14 @@ $I->seeDirFound("preserved-$archiveType/deep/nested"); $I->seeFileFound('structu.re', "preserved-$archiveType/deep/nested"); // Make another archive, this time composed of fanciful locations - $I->getContainer()->get('taskPack', ["composed.$archiveType"]) + $I->task('Pack', "composed.$archiveType") ->add(['a/b/existing_file' => 'some/deeply/existing_file']) ->add(['x/y/z/structu.re' => 'some/deeply/nested/structu.re']) ->run(); $I->seeFileFound("composed.$archiveType"); // Extract our composed archive, and see if the resulting file // structure matches expectations. - $I->getContainer()->get('taskExtract', ["composed.$archiveType"]) + $I->task('Extract', "composed.$archiveType") ->to("decomposed-$archiveType") ->preserveTopDirectory() ->run(); diff --git a/tests/cli/WriteFileCest.php b/tests/cli/WriteFileCest.php index a4403371d..e17c2f927 100644 --- a/tests/cli/WriteFileCest.php +++ b/tests/cli/WriteFileCest.php @@ -11,7 +11,7 @@ public function _before(CliGuy $I) public function writeFewLines(CliGuy $I) { $I->wantTo('write lines with WriteToFile task'); - $I->getContainer()->get('taskWriteToFile', ['blogpost.md']) + $I->task('WriteToFile', 'blogpost.md') ->line('****') ->line('hello world') ->line('****') @@ -28,7 +28,7 @@ public function writeFewLines(CliGuy $I) public function appendToFile(CliGuy $I) { - $I->getContainer()->get('taskWriteToFile', ['a.txt']) + $I->task('WriteToFile', 'a.txt') ->append() ->line('hello world') ->run(); @@ -42,7 +42,7 @@ public function appendToFile(CliGuy $I) public function insertFile(CliGuy $I) { - $I->getContainer()->get('taskWriteToFile', ['a.txt']) + $I->task('WriteToFile', 'a.txt') ->line('****') ->textFromFile('b.txt') ->line("C") @@ -58,7 +58,7 @@ public function insertFile(CliGuy $I) public function replaceInFile(CliGuy $I) { - $I->getContainer()->get('taskReplaceInFile', ['a.txt']) + $I->task('ReplaceInFile', 'a.txt') ->from('A') ->to('B') ->run(); @@ -69,7 +69,7 @@ public function replaceInFile(CliGuy $I) public function replaceMultipleInFile(CliGuy $I) { - $I->getContainer()->get('taskReplaceInFile', ['box/robo.txt']) + $I->task('ReplaceInFile', 'box/robo.txt') ->from(array('HELLO', 'ROBO')) ->to(array('Hello ', 'robo.li!')) ->run(); From eb0d5c7cb6b35064e698d38832da201492b09f91 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Tue, 15 Mar 2016 09:23:12 -0700 Subject: [PATCH 16/34] Remove workaround in RoboContainer now that League/Container has been fixed. --- composer.json | 2 +- composer.lock | 24 +++++++------- src/Container/RoboContainer.php | 57 +-------------------------------- 3 files changed, 14 insertions(+), 69 deletions(-) diff --git a/composer.json b/composer.json index 475cfbb39..44fb1ddf1 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "symfony/console": "~2.5|~3.0", "symfony/process": "~2.5|~3.0", "symfony/filesystem": "~2.5|~3.0", - "league/container": "~2" + "league/container": "~2.1" }, "require-dev": { "patchwork/jsqueeze": "~1.0", diff --git a/composer.lock b/composer.lock index a1aec78fa..83a67261c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "6b0bc51ba3b8a9199b5d71667c427285", - "content-hash": "2a5b7b6477b38ddb137bf8f24526fdb4", + "hash": "15d62a29b192b8970d071cff5ce71350", + "content-hash": "37b5fc93d771c0b587e3413af833b2e3", "packages": [ { "name": "consolidation/log", @@ -87,16 +87,16 @@ }, { "name": "league/container", - "version": "2.0.3", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/thephpleague/container.git", - "reference": "d4b5e0dde44aec50e4025c7249d668ea74b1ae44" + "reference": "bf916eb2023c4cc73724e945d264a4ae5eb4df38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/container/zipball/d4b5e0dde44aec50e4025c7249d668ea74b1ae44", - "reference": "d4b5e0dde44aec50e4025c7249d668ea74b1ae44", + "url": "https://api.github.com/repos/thephpleague/container/zipball/bf916eb2023c4cc73724e945d264a4ae5eb4df38", + "reference": "bf916eb2023c4cc73724e945d264a4ae5eb4df38", "shasum": "" }, "require": { @@ -147,7 +147,7 @@ "provider", "service" ], - "time": "2015-09-07 10:16:18" + "time": "2016-03-15 08:17:43" }, { "name": "psr/log", @@ -1828,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": { @@ -1896,7 +1896,7 @@ "testing", "xunit" ], - "time": "2016-02-11 14:56:33" + "time": "2016-03-14 06:16:08" }, { "name": "phpunit/phpunit-mock-objects", diff --git a/src/Container/RoboContainer.php b/src/Container/RoboContainer.php index 08a8b8182..1cd5b9b11 100644 --- a/src/Container/RoboContainer.php +++ b/src/Container/RoboContainer.php @@ -40,9 +40,7 @@ public function isSimulated() */ public function get($alias, array $args = []) { - // TODO: put back to: $service = parent::get($alias, $args); - // after https://github.com/thephpleague/container/pull/92 is merged. - $service = $this->parentGet($alias, $args); + $service = parent::get($alias, $args); // Remember whether or not this is a task before // it gets wrapped in any service decorator. @@ -66,57 +64,4 @@ public function get($alias, array $args = []) return $service; } - - /** - * TODO: Remove after https://github.com/thephpleague/container/pull/92 is merged - */ - public function parentGet($alias, array $args = []) - { - $service = $this->getFromThisContainer($alias, $args); - - if (!$service && $this->providers->provides($alias)) { - $this->providers->register($alias); - $service = $this->getFromThisContainer($alias, $args); - } - - if ($service) { - return $service; - } - - if ($resolved = $this->getFromDelegate($alias, $args)) { - return $this->inflectors->inflect($resolved); - } - - throw new NotFoundException( - sprintf('Alias (%s) is not being managed by the container', $alias) - ); - } - - /** - * TODO: Remove after https://github.com/thephpleague/container/pull/92 is merged - * - * Get a service that has been registered in this container. - * - * @return mixed Entry|false. - */ - protected function getFromThisContainer($alias, array $args = []) - { - if ($this->hasShared($alias, true)) { - return $this->inflectors->inflect($this->shared[$alias]); - } - - if (array_key_exists($alias, $this->sharedDefinitions)) { - $shared = $this->inflectors->inflect($this->sharedDefinitions[$alias]->build()); - $this->shared[$alias] = $shared; - return $shared; - } - - if (array_key_exists($alias, $this->definitions)) { - return $this->inflectors->inflect( - $this->definitions[$alias]->build($args) - ); - } - - return false; - } } From 3990a7c9e82d25e15036d03f61ec9bf25004182c Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Tue, 15 Mar 2016 20:29:02 -0700 Subject: [PATCH 17/34] Simplify service providers with SimpleServiceProvider.php. --- src/Container/SimpleServiceProvider.php | 49 ++++++++++++++++++++++++ src/Task/ApiGen/ServiceProvider.php | 16 ++++---- src/Task/Archive/ServiceProvider.php | 19 +++++---- src/Task/Assets/ServiceProvider.php | 25 ++++++------ src/Task/Base/ServiceProvider.php | 28 ++++++-------- src/Task/Bower/ServiceProvider.php | 19 +++++---- src/Task/Composer/ServiceProvider.php | 22 +++++------ src/Task/Development/ServiceProvider.php | 34 +++++++--------- src/Task/Docker/ServiceProvider.php | 34 +++++++--------- src/Task/File/ServiceProvider.php | 25 ++++++------ src/Task/FileSystem/ServiceProvider.php | 34 +++++++--------- src/Task/Gulp/ServiceProvider.php | 16 ++++---- src/Task/Npm/ServiceProvider.php | 19 +++++---- src/Task/Remote/ServiceProvider.php | 19 +++++---- src/Task/Testing/ServiceProvider.php | 22 +++++------ src/Task/Vcs/ServiceProvider.php | 19 +++++---- 16 files changed, 206 insertions(+), 194 deletions(-) create mode 100644 src/Container/SimpleServiceProvider.php diff --git a/src/Container/SimpleServiceProvider.php b/src/Container/SimpleServiceProvider.php new file mode 100644 index 000000000..b9a546d4a --- /dev/null +++ b/src/Container/SimpleServiceProvider.php @@ -0,0 +1,49 @@ +provides += $provides; + } + + /** + * @var array + */ + protected $provides = []; + + /** + * {@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/Task/ApiGen/ServiceProvider.php b/src/Task/ApiGen/ServiceProvider.php index be57cd76b..18f42cfdc 100644 --- a/src/Task/ApiGen/ServiceProvider.php +++ b/src/Task/ApiGen/ServiceProvider.php @@ -1,16 +1,16 @@ getContainer()->add('taskApiGen', ApiGen::class); + parent::__construct( + [ + 'taskApiGen' => ApiGen::class, + ] + ); } } diff --git a/src/Task/Archive/ServiceProvider.php b/src/Task/Archive/ServiceProvider.php index 3b7c85d53..6c5c23768 100644 --- a/src/Task/Archive/ServiceProvider.php +++ b/src/Task/Archive/ServiceProvider.php @@ -1,18 +1,17 @@ getContainer()->add('taskExtract', Extract::class); - $this->getContainer()->add('taskPack', Pack::class); + parent::__construct( + [ + 'taskExtract' => Extract::class, + 'taskPack' => Pack::class, + ] + ); } } diff --git a/src/Task/Assets/ServiceProvider.php b/src/Task/Assets/ServiceProvider.php index 661e9b58e..1569b56b6 100644 --- a/src/Task/Assets/ServiceProvider.php +++ b/src/Task/Assets/ServiceProvider.php @@ -1,22 +1,19 @@ getContainer()->add('taskMinify', Minify::class); - $this->getContainer()->add('taskImageMinify', ImageMinify::class); - $this->getContainer()->add('taskLess', Less::class); - $this->getContainer()->add('taskScss', Scss::class); + parent::__construct( + [ + 'taskMinify' => Minify::class, + 'taskImageMinify' => ImageMinify::class, + 'taskLess' => Less::class, + 'taskScss' => Scss::class, + ] + ); } } diff --git a/src/Task/Base/ServiceProvider.php b/src/Task/Base/ServiceProvider.php index a67144f67..a3a91a561 100644 --- a/src/Task/Base/ServiceProvider.php +++ b/src/Task/Base/ServiceProvider.php @@ -1,24 +1,20 @@ getContainer()->add('taskExec', Exec::class); - $this->getContainer()->add('taskExecStack', ExecStack::class); - $this->getContainer()->add('taskParallelExec', ParallelExec::class); - $this->getContainer()->add('taskSymfonyCommand', SymfonyCommand::class); - $this->getContainer()->add('taskWatch', Watch::class); + parent::__construct( + [ + 'taskExec' => Exec::class, + 'taskExecStack' => ExecStack::class, + 'taskParallelExec' => ParallelExec::class, + 'taskSymfonyCommand' => SymfonyCommand::class, + 'taskWatch' => Watch::class, + ] + ); } } diff --git a/src/Task/Bower/ServiceProvider.php b/src/Task/Bower/ServiceProvider.php index a85353a97..37b827c86 100644 --- a/src/Task/Bower/ServiceProvider.php +++ b/src/Task/Bower/ServiceProvider.php @@ -1,18 +1,17 @@ getContainer()->add('taskBowerInstall', Install::class); - $this->getContainer()->add('taskBowerUpdate', Update::class); + parent::__construct( + [ + 'taskBowerInstall' => Install::class, + 'taskBowerUpdate' => Update::class, + ] + ); } } diff --git a/src/Task/Composer/ServiceProvider.php b/src/Task/Composer/ServiceProvider.php index f27d7c506..e21dd5656 100644 --- a/src/Task/Composer/ServiceProvider.php +++ b/src/Task/Composer/ServiceProvider.php @@ -1,20 +1,18 @@ getContainer()->add('taskComposerInstall', Install::class); - $this->getContainer()->add('taskComposerUpdate', Update::class); - $this->getContainer()->add('taskComposerDumpAutoload', DumpAutoload::class); + parent::__construct( + [ + 'taskComposerInstall' => Install::class, + 'taskComposerUpdate' => Update::class, + 'taskComposerDumpAutoload' => DumpAutoload::class, + ] + ); } } diff --git a/src/Task/Development/ServiceProvider.php b/src/Task/Development/ServiceProvider.php index fb516132a..c770313b7 100644 --- a/src/Task/Development/ServiceProvider.php +++ b/src/Task/Development/ServiceProvider.php @@ -1,28 +1,22 @@ getContainer()->add('taskChangelog', Changelog::class); - $this->getContainer()->add('taskGenDoc', GenerateMarkdownDoc::class); - $this->getContainer()->add('taskSemVer', SemVer::class); - $this->getContainer()->add('taskServer', PhpServer::class); - $this->getContainer()->add('taskPackPhar', PackPhar::class); - $this->getContainer()->add('taskGitHubRelease', DumpAutoload::class); - $this->getContainer()->add('taskOpenBrowser', OpenBrowser::class); + parent::__construct( + [ + 'taskChangelog' => Changelog::class, + 'taskGenDoc' => GenerateMarkdownDoc::class, + 'taskSemVer' => SemVer::class, + 'taskServer' => PhpServer::class, + 'taskPackPhar' => PackPhar::class, + 'taskGitHubRelease' => GitHubRelease::class, + 'taskOpenBrowser' => OpenBrowser::class, + ] + ); } } diff --git a/src/Task/Docker/ServiceProvider.php b/src/Task/Docker/ServiceProvider.php index 2ac0a58c7..a94462b6c 100644 --- a/src/Task/Docker/ServiceProvider.php +++ b/src/Task/Docker/ServiceProvider.php @@ -1,28 +1,22 @@ getContainer()->add('taskDockerRun', Run::class); - $this->getContainer()->add('taskDockerPull', Pull::class); - $this->getContainer()->add('taskDockerBuild', Build::class); - $this->getContainer()->add('taskDockerStop', Stop::class); - $this->getContainer()->add('taskDockerCommit', Commit::class); - $this->getContainer()->add('taskDockerStart', Start::class); - $this->getContainer()->add('taskDockerRemove', Remove::class); + parent::__construct( + [ + 'taskDockerRun' => Run::class, + 'taskDockerPull' => Pull::class, + 'taskDockerBuild' => Build::class, + 'taskDockerStop' => Stop::class, + 'taskDockerCommit' => Commit::class, + 'taskDockerStart' => Start::class, + 'taskDockerRemove' => Remove::class, + ] + ); } } diff --git a/src/Task/File/ServiceProvider.php b/src/Task/File/ServiceProvider.php index 3361aa542..d61c2907f 100644 --- a/src/Task/File/ServiceProvider.php +++ b/src/Task/File/ServiceProvider.php @@ -1,22 +1,19 @@ getContainer()->add('taskConcat', Concat::class); - $this->getContainer()->add('taskReplaceInFile', Replace::class); - $this->getContainer()->add('taskWriteToFile', Write::class); - $this->getContainer()->add('taskTmpFile', TmpFile::class); + parent::__construct( + [ + 'taskConcat' => Concat::class, + 'taskReplaceInFile' => Replace::class, + 'taskWriteToFile' => Write::class, + 'taskTmpFile' => TmpFile::class, + ] + ); } } diff --git a/src/Task/FileSystem/ServiceProvider.php b/src/Task/FileSystem/ServiceProvider.php index 267f161e4..954f07699 100644 --- a/src/Task/FileSystem/ServiceProvider.php +++ b/src/Task/FileSystem/ServiceProvider.php @@ -1,28 +1,22 @@ getContainer()->add('taskCleanDir', CleanDir::class); - $this->getContainer()->add('taskDeleteDir', DeleteDir::class); - $this->getContainer()->add('taskTmpDir', TmpDir::class); - $this->getContainer()->add('taskCopyDir', CopyDir::class); - $this->getContainer()->add('taskMirrorDir', MirrorDir::class); - $this->getContainer()->add('taskFlattenDir', FlattenDir::class); - $this->getContainer()->add('taskFileSystemStack', FilesystemStack::class); + parent::__construct( + [ + 'taskCleanDir' => CleanDir::class, + 'taskDeleteDir' => DeleteDir::class, + 'taskTmpDir' => TmpDir::class, + 'taskCopyDir' => CopyDir::class, + 'taskMirrorDir' => MirrorDir::class, + 'taskFlattenDir' => FlattenDir::class, + 'taskFileSystemStack' => FilesystemStack::class, + ] + ); } } diff --git a/src/Task/Gulp/ServiceProvider.php b/src/Task/Gulp/ServiceProvider.php index 195b03221..bff71c7ca 100644 --- a/src/Task/Gulp/ServiceProvider.php +++ b/src/Task/Gulp/ServiceProvider.php @@ -1,16 +1,16 @@ getContainer()->add('taskGulpRun', Run::class); + parent::__construct( + [ + 'taskGulpRun' => Run::class, + ] + ); } } diff --git a/src/Task/Npm/ServiceProvider.php b/src/Task/Npm/ServiceProvider.php index e855527a2..96c9ae86c 100644 --- a/src/Task/Npm/ServiceProvider.php +++ b/src/Task/Npm/ServiceProvider.php @@ -1,18 +1,17 @@ getContainer()->add('taskNpmInstall', Install::class); - $this->getContainer()->add('taskNpmUpdate', Update::class); + parent::__construct( + [ + 'taskNpmInstall' => Install::class, + 'taskNpmUpdate' => Update::class, + ] + ); } } diff --git a/src/Task/Remote/ServiceProvider.php b/src/Task/Remote/ServiceProvider.php index bd03bd5de..4c7088a8d 100644 --- a/src/Task/Remote/ServiceProvider.php +++ b/src/Task/Remote/ServiceProvider.php @@ -1,18 +1,17 @@ getContainer()->add('taskRsync', Rsync::class); - $this->getContainer()->add('taskSshExec', Ssh::class); + parent::__construct( + [ + 'taskRsync' => Rsync::class, + 'taskSshExec' => Ssh::class, + ] + ); } } diff --git a/src/Task/Testing/ServiceProvider.php b/src/Task/Testing/ServiceProvider.php index 87978a72b..5bb28b7d5 100644 --- a/src/Task/Testing/ServiceProvider.php +++ b/src/Task/Testing/ServiceProvider.php @@ -1,20 +1,18 @@ getContainer()->add('taskCodecept', Codecept::class); - $this->getContainer()->add('taskPHPUnit', PHPUnit::class); - $this->getContainer()->add('taskPhpspec', Phpspec::class); + parent::__construct( + [ + 'taskCodecept' => Codecept::class, + 'taskPHPUnit' => PHPUnit::class, + 'taskPhpspec' => Phpspec::class, + ] + ); } } diff --git a/src/Task/Vcs/ServiceProvider.php b/src/Task/Vcs/ServiceProvider.php index 3d894a1ed..faca3bb18 100644 --- a/src/Task/Vcs/ServiceProvider.php +++ b/src/Task/Vcs/ServiceProvider.php @@ -1,18 +1,17 @@ getContainer()->add('taskSvnStack', SvnStack::class); - $this->getContainer()->add('taskGitStack', GitStack::class); + parent::__construct( + [ + 'taskSvnStack' => SvnStack::class, + 'taskGitStack' => GitStack::class, + ] + ); } } From f7ef6dcc77fb767cb71bf28a07c185e16018c9e3 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Tue, 15 Mar 2016 20:51:40 -0700 Subject: [PATCH 18/34] Fix NitPick style. --- RoboFile.php | 2 +- src/Container/SimpleServiceProvider.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 958cd18fb..07d9bc664 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -278,7 +278,7 @@ public function pharPublish() public function tryWatch() { - $this->task('Watch')->monitor(['composer.json', 'composer.lock'], function() { + $this->task('Watch')->monitor(['composer.json', 'composer.lock'], function () { $this->task('ComposerUpdate')->run(); })->run(); } diff --git a/src/Container/SimpleServiceProvider.php b/src/Container/SimpleServiceProvider.php index b9a546d4a..37dd54ae8 100644 --- a/src/Container/SimpleServiceProvider.php +++ b/src/Container/SimpleServiceProvider.php @@ -16,7 +16,8 @@ abstract class SimpleServiceProvider implements ServiceProviderInterface { use ContainerAwareTrait; - public function __construct($provides = []) { + public function __construct($provides = []) + { $this->provides += $provides; } From 8e40124fbd016af4432bc365c76178ed8a36ec90 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 10:22:14 -0700 Subject: [PATCH 19/34] Put back loadTasks traits. --- src/Task/ApiGen/loadTasks.php | 14 +++++ src/Task/Archive/loadTasks.php | 26 +++++++++ src/Task/Assets/loadTasks.php | 41 +++++++++++++ src/Task/Base/loadTasks.php | 44 ++++++++++++++ src/Task/Bower/loadTasks.php | 23 ++++++++ src/Task/Composer/loadTasks.php | 32 ++++++++++ src/Task/Development/loadTasks.php | 68 ++++++++++++++++++++++ src/Task/Docker/loadTasks.php | 39 +++++++++++++ src/Task/File/loadTasks.php | 45 ++++++++++++++ src/Task/FileSystem/ServiceProvider.php | 2 +- src/Task/FileSystem/loadTasks.php | 71 +++++++++++++++++++++++ src/Task/Gulp/loadTasks.php | 14 +++++ src/Task/Npm/loadTasks.php | 21 +++++++ src/Task/Remote/loadTasks.php | 23 ++++++++ src/Task/Testing/loadTasks.php | 32 ++++++++++ src/Task/Vcs/loadTasks.php | 25 ++++++++ src/Tasklib.php | 74 ++++++++++++++++++++++++ src/Tasks.php | 51 +--------------- tests/_helpers/CliGuy.php | 6 -- tests/_helpers/CliHelper.php | 33 +++++++++++ tests/cli/CleanDirCept.php | 2 +- tests/cli/CollectionCest.php | 24 ++++---- tests/cli/ConcatCept.php | 2 +- tests/cli/CopyDirCept.php | 2 +- tests/cli/CopyDirOverwritesFilesCept.php | 2 +- tests/cli/CopyDirRecursiveCept.php | 2 +- tests/cli/DeleteDirCept.php | 2 +- tests/cli/ExecCest.php | 2 +- tests/cli/FileSystemStackCest.php | 4 +- tests/cli/FlattenDirCept.php | 2 +- tests/cli/FlattenDirParentsCept.php | 2 +- tests/cli/PackExtractCept.php | 10 ++-- tests/cli/WriteFileCest.php | 10 ++-- 33 files changed, 660 insertions(+), 90 deletions(-) create mode 100644 src/Task/ApiGen/loadTasks.php create mode 100644 src/Task/Archive/loadTasks.php create mode 100644 src/Task/Assets/loadTasks.php create mode 100644 src/Task/Base/loadTasks.php create mode 100644 src/Task/Bower/loadTasks.php create mode 100644 src/Task/Composer/loadTasks.php create mode 100644 src/Task/Development/loadTasks.php create mode 100644 src/Task/Docker/loadTasks.php create mode 100644 src/Task/File/loadTasks.php create mode 100644 src/Task/FileSystem/loadTasks.php create mode 100644 src/Task/Gulp/loadTasks.php create mode 100644 src/Task/Npm/loadTasks.php create mode 100644 src/Task/Remote/loadTasks.php create mode 100644 src/Task/Testing/loadTasks.php create mode 100644 src/Task/Vcs/loadTasks.php create mode 100644 src/Tasklib.php diff --git a/src/Task/ApiGen/loadTasks.php b/src/Task/ApiGen/loadTasks.php new file mode 100644 index 000000000..98aa92c95 --- /dev/null +++ b/src/Task/ApiGen/loadTasks.php @@ -0,0 +1,14 @@ +task('ApiGen', $pathToApiGen); + } +} diff --git a/src/Task/Archive/loadTasks.php b/src/Task/Archive/loadTasks.php new file mode 100644 index 000000000..a95b16788 --- /dev/null +++ b/src/Task/Archive/loadTasks.php @@ -0,0 +1,26 @@ +task('Pack', $filename); + } + + /** + * @param $filename + * + * @return Extract + */ + protected function taskExtract($filename) + { + return $this->task('Extract', $filename); + } +} diff --git a/src/Task/Assets/loadTasks.php b/src/Task/Assets/loadTasks.php new file mode 100644 index 000000000..a703cbe73 --- /dev/null +++ b/src/Task/Assets/loadTasks.php @@ -0,0 +1,41 @@ +task('Minify', $input); + } + + /** + * @param $input + * @return ImageMinify + */ + protected function taskImageMinify($input) + { + return $this->task('ImageMinify', $input); + } + + /** + * @param $input + * @return Less + */ + protected function taskLess($input) + { + return $this->task('Less', $input); + } + + /** + * @param $input + * @return Scss + */ + protected function taskScss($input) + { + return $this->task('Scss', $input); + } +} diff --git a/src/Task/Base/loadTasks.php b/src/Task/Base/loadTasks.php new file mode 100644 index 000000000..37afabc1d --- /dev/null +++ b/src/Task/Base/loadTasks.php @@ -0,0 +1,44 @@ +task('Exec', $command); + } + + protected function taskExecStack() + { + return $this->task('ExecStack'); + } + + /** + * @return ParallelExec + */ + protected function taskParallelExec() + { + return $this->task('ParallelExec'); + } + + /** + * @param $command + * @return SymfonyCommand + */ + protected function taskSymfonyCommand($command) + { + return $this->task('SymfonyCommand', $command); + } + + /** + * @return Watch + */ + protected function taskWatch() + { + return $this->task('Watch', $this); + } +} diff --git a/src/Task/Bower/loadTasks.php b/src/Task/Bower/loadTasks.php new file mode 100644 index 000000000..ae6573690 --- /dev/null +++ b/src/Task/Bower/loadTasks.php @@ -0,0 +1,23 @@ +task('BowerInstall', $pathToBower); + } + + /** + * @param null $pathToBower + * @return Update + */ + protected function taskBowerUpdate($pathToBower = null) + { + return $this->task('BowerUpdate', $pathToBower); + } +} diff --git a/src/Task/Composer/loadTasks.php b/src/Task/Composer/loadTasks.php new file mode 100644 index 000000000..b130710e9 --- /dev/null +++ b/src/Task/Composer/loadTasks.php @@ -0,0 +1,32 @@ +task('ComposerInstall', $pathToComposer); + } + + /** + * @param null $pathToComposer + * @return Update + */ + protected function taskComposerUpdate($pathToComposer = null) + { + return $this->task('ComposerUpdate', $pathToComposer); + } + + /** + * @param null $pathToComposer + * @return DumpAutoload + */ + protected function taskComposerDumpAutoload($pathToComposer = null) + { + return $this->task('ComposerDumpAutoload', $pathToComposer); + } +} diff --git a/src/Task/Development/loadTasks.php b/src/Task/Development/loadTasks.php new file mode 100644 index 000000000..8b47be63a --- /dev/null +++ b/src/Task/Development/loadTasks.php @@ -0,0 +1,68 @@ +task('Changelog', $filename); + } + + /** + * @param $filename + * @return GenerateMarkdownDoc + */ + protected function taskGenDoc($filename) + { + return $this->task('GenDoc', $filename); + } + + /** + * @param string $pathToSemVer + * @return SemVer + */ + protected function taskSemVer($pathToSemVer = '.semver') + { + return $this->task('SemVer', $pathToSemVer); + } + + /** + * @param int $port + * @return PhpServer + */ + protected function taskServer($port = 8000) + { + return $this->task('Server', $port); + } + + /** + * @param $filename + * @return PackPhar + */ + protected function taskPackPhar($filename) + { + return $this->task('PackPhar', $filename); + } + + /** + * @param $tag + * @return GitHubRelease + */ + protected function taskGitHubRelease($tag) + { + return $this->task('GitHubRelease', $tag); + } + + /** + * @param string|array $url + * @return OpenBrowser + */ + protected function taskOpenBrowser($url) + { + return $this->task('OpenBrowser', $url); + } +} diff --git a/src/Task/Docker/loadTasks.php b/src/Task/Docker/loadTasks.php new file mode 100644 index 000000000..ddfe27386 --- /dev/null +++ b/src/Task/Docker/loadTasks.php @@ -0,0 +1,39 @@ +task('DockerRun', $image); + } + protected function taskDockerPull($image) + { + return $this->task('DockerPull', $image); + } + protected function taskDockerBuild($path = '.') + { + return $this->task('DockerBuild', $path); + } + protected function taskDockerStop($cidOrResult) + { + return $this->task('DockerStop', $cidOrResult); + } + protected function taskDockerCommit($cidOrResult) + { + return $this->task('DockerCommit', $cidOrResult); + } + protected function taskDockerStart($cidOrResult) + { + return $this->task('DockerStart', $cidOrResult); + } + protected function taskDockerRemove($cidOrResult) + { + return $this->task('DockerRemove', $cidOrResult); + } + + protected function taskDockerExec($cidOrResult) + { + return $this->task('DockerExec', $cidOrResult); + } +} diff --git a/src/Task/File/loadTasks.php b/src/Task/File/loadTasks.php new file mode 100644 index 000000000..5eac725ce --- /dev/null +++ b/src/Task/File/loadTasks.php @@ -0,0 +1,45 @@ +task('Concat', $files); + } + + /** + * @param $file + * @return Replace + */ + protected function taskReplaceInFile($file) + { + return $this->task('ReplaceInFile', $file); + } + + /** + * @param $file + * @return Write + */ + protected function taskWriteToFile($file) + { + return $this->task('WriteToFile', $file); + } + + /** + * @param $prefix + * @param $base + * @param $includeRandomPart + * @return TmpFile + */ + protected function taskTmpFile($filename = 'tmp', $extension = '', $baseDir = '', $includeRandomPart = true) + { + return $this->task('TmpFile', $filename, $extension, $baseDir, $includeRandomPart); + } +} diff --git a/src/Task/FileSystem/ServiceProvider.php b/src/Task/FileSystem/ServiceProvider.php index 954f07699..daf947eb7 100644 --- a/src/Task/FileSystem/ServiceProvider.php +++ b/src/Task/FileSystem/ServiceProvider.php @@ -15,7 +15,7 @@ public function __construct() 'taskCopyDir' => CopyDir::class, 'taskMirrorDir' => MirrorDir::class, 'taskFlattenDir' => FlattenDir::class, - 'taskFileSystemStack' => FilesystemStack::class, + 'taskFilesystemStack' => FilesystemStack::class, ] ); } diff --git a/src/Task/FileSystem/loadTasks.php b/src/Task/FileSystem/loadTasks.php new file mode 100644 index 000000000..fcc6d3f8a --- /dev/null +++ b/src/Task/FileSystem/loadTasks.php @@ -0,0 +1,71 @@ +task('CleanDir', $dirs); + } + + /** + * @param $dirs + * @return DeleteDir + */ + protected function taskDeleteDir($dirs) + { + return $this->task('DeleteDir', $dirs); + } + + /** + * @param $prefix + * @param $base + * @param $includeRandomPart + * @return TmpDir + */ + protected function taskTmpDir($prefix = 'tmp', $base = '', $includeRandomPart = true) + { + return $this->task('TmpDir', $prefix, $base, $includeRandomPart); + } + + /** + * @param $dirs + * @return CopyDir + */ + protected function taskCopyDir($dirs) + { + return $this->task('CopyDir', $dirs); + } + + /** + * @param $dirs + * @return MirrorDir + */ + protected function taskMirrorDir($dirs) + { + return $this->task('MirrorDir', $dirs); + } + + /** + * @param $dirs + * @return FlattenDir + */ + protected function taskFlattenDir($dirs) + { + return $this->task('FlattenDir', $dirs); + } + + /** + * @return FilesystemStack + */ + protected function taskFilesystemStack() + { + return $this->task('FilesystemStack'); + } +} diff --git a/src/Task/Gulp/loadTasks.php b/src/Task/Gulp/loadTasks.php new file mode 100644 index 000000000..eae5f34d1 --- /dev/null +++ b/src/Task/Gulp/loadTasks.php @@ -0,0 +1,14 @@ +task('GulpRun', $task,$pathToGulp); + } +} diff --git a/src/Task/Npm/loadTasks.php b/src/Task/Npm/loadTasks.php new file mode 100644 index 000000000..014277a5b --- /dev/null +++ b/src/Task/Npm/loadTasks.php @@ -0,0 +1,21 @@ +task('NpmInstall', $pathToNpm); + } + + /** + * @param null $pathToNpm + * @return Update + */ + protected function taskNpmUpdate($pathToNpm = null) { + return $this->task('NpmUpdate', $pathToNpm); + } +} diff --git a/src/Task/Remote/loadTasks.php b/src/Task/Remote/loadTasks.php new file mode 100644 index 000000000..31be715ce --- /dev/null +++ b/src/Task/Remote/loadTasks.php @@ -0,0 +1,23 @@ +task('Rsync'); + } + + /** + * @param null $hostname + * @param null $user + * @return Ssh + */ + protected function taskSshExec($hostname = null, $user = null) + { + return $this->task('Ssh', $hostname, $user); + } +} diff --git a/src/Task/Testing/loadTasks.php b/src/Task/Testing/loadTasks.php new file mode 100644 index 000000000..b5abaf737 --- /dev/null +++ b/src/Task/Testing/loadTasks.php @@ -0,0 +1,32 @@ +task('Codecept', $pathToCodeception); + } + + /** + * @param null $pathToPhpUnit + * @return PHPUnit + */ + protected function taskPhpUnit($pathToPhpUnit = null) + { + return $this->task('PHPUnit', $pathToPhpUnit); + } + + /** + * @param null $pathToPhpspec + * @return Phpspec + */ + protected function taskPhpspec($pathToPhpspec = null) + { + return $this->task('Phpspec', $pathToPhpspec); + } +} diff --git a/src/Task/Vcs/loadTasks.php b/src/Task/Vcs/loadTasks.php new file mode 100644 index 000000000..a1c11ad2b --- /dev/null +++ b/src/Task/Vcs/loadTasks.php @@ -0,0 +1,25 @@ +task('SvnStack', $username, $password, $pathToSvn); + } + + /** + * @param string $pathToGit + * @return GitStack + */ + protected function taskGitStack($pathToGit = 'git') + { + return $this->task('GitStack', $pathToGit); + } +} diff --git a/src/Tasklib.php b/src/Tasklib.php new file mode 100644 index 000000000..3ace6414f --- /dev/null +++ b/src/Tasklib.php @@ -0,0 +1,74 @@ +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); + return $this->getContainer()->get("task$name", $args); + } +} diff --git a/src/Tasks.php b/src/Tasks.php index 8483df110..12d8a98c7 100644 --- a/src/Tasks.php +++ b/src/Tasks.php @@ -8,60 +8,11 @@ class Tasks implements ContainerAwareInterface { use ContainerAwareTrait; + use Tasklib; use IO; - // shortcuts - use Task\Base\loadShortcuts; - use Task\FileSystem\loadShortcuts; - use Task\Vcs\loadShortcuts; - protected function stopOnFail($stopOnFail = true) { Result::$stopOnFail = $stopOnFail; } - - /** - * 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]); - */ - protected function task() - { - $args = func_get_args(); - $name = array_shift($args); - return $this->getContainer()->get("task$name", $args); - } - - /** - * Backwards compatibility: convert $this->taskFoo($a, $b) into - * $this->getContainer()->get('taskFoo', [$a, $b]); - */ - public function __call($functionName, $args) - { - if (preg_match('#^task#', $functionName)) { - $service = $this->getContainer()->get($functionName, $args); - if ($service) { - return $service; - } - } - throw new \Exception("No such method $functionName"); - } } diff --git a/tests/_helpers/CliGuy.php b/tests/_helpers/CliGuy.php index ab4e5f2c2..7aa44ab4e 100644 --- a/tests/_helpers/CliGuy.php +++ b/tests/_helpers/CliGuy.php @@ -28,10 +28,4 @@ class CliGuy extends \Codeception\Actor /** * Define custom actions here */ - public function task() - { - $args = func_get_args(); - $name = array_shift($args); - return $this->getContainer()->get("task$name", $args); - } } diff --git a/tests/_helpers/CliHelper.php b/tests/_helpers/CliHelper.php index 6518c2b52..573d0a93b 100644 --- a/tests/_helpers/CliHelper.php +++ b/tests/_helpers/CliHelper.php @@ -12,12 +12,45 @@ class CliHelper extends \Codeception\Module implements ContainerAwareInterface { use ContainerAwareTrait; + use \Robo\Task\Base\loadTasks { + 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\Task\Archive\loadTasks { + taskPack as public; + taskExtract as public; + } + + public function task() + { + $args = func_get_args(); + $name = array_shift($args); + return $this->getContainer()->get("task$name", $args); + } + public function seeDirFound($dir) { $this->assertTrue(is_dir($dir) && file_exists($dir), "Directory does not exist"); diff --git a/tests/cli/CleanDirCept.php b/tests/cli/CleanDirCept.php index 7cb2c5cb4..71e10b005 100644 --- a/tests/cli/CleanDirCept.php +++ b/tests/cli/CleanDirCept.php @@ -5,7 +5,7 @@ $I->wantTo('clean dir with DeleteDirTask'); $I->amInPath(codecept_data_dir()); $I->seeFileFound('robo.txt', 'sandbox'); -$I->task('CleanDir', ['sandbox']) +$I->taskCleanDir(['sandbox']) ->run(); $I->dontSeeFileFound('box', 'sandbox'); $I->dontSeeFileFound('robo.txt', 'sandbox'); diff --git a/tests/cli/CollectionCest.php b/tests/cli/CollectionCest.php index 458a3be5a..b868e8119 100644 --- a/tests/cli/CollectionCest.php +++ b/tests/cli/CollectionCest.php @@ -24,7 +24,7 @@ public function toCreateDirViaCollection(CliGuy $I) $collection = $I->getContainer()->get('collection'); // Set up a filesystem stack, but use addToCollection() to defer execution - $I->task('FileSystemStack') + $I->taskFileSystemStack() ->mkdir('log') ->touch('log/error.txt') ->addToCollection($collection); @@ -47,7 +47,7 @@ public function toUseATmpDirAndConfirmItIsDeleted(CliGuy $I) // 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 = $I->task('TmpDir') + $tmpPath = $I->taskTmpDir() ->addToCollection($collection) ->getPath(); @@ -60,13 +60,13 @@ public function toUseATmpDirAndConfirmItIsDeleted(CliGuy $I) $I->seeDirFound($tmpPath); // Set up a filesystem stack, but use addToCollection() to defer execution - $I->task('FileSystemStack') + $I->taskFileSystemStack() ->mkdir("$tmpPath/log") ->touch("$tmpPath/log/error.txt") ->addToCollection($collection); // Copy our tmp directory to a location that is not transient - $I->task('CopyDir', [$tmpPath => 'copied']) + $I->taskCopyDir([$tmpPath => 'copied']) ->addToCollection($collection); // FileSystemStack has not run yet, so no files should be found. @@ -94,7 +94,7 @@ public function toUseATmpDirAndChangeWorkingDirectory(CliGuy $I) // 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 = $I->task('TmpDir') + $tmpPath = $I->taskTmpDir() ->cwd() ->addToCollection($collection) ->getPath(); @@ -102,13 +102,13 @@ public function toUseATmpDirAndChangeWorkingDirectory(CliGuy $I) // Set up a filesystem stack, but use addToCollection() to defer execution. // Note that since we used 'cwd()' above, the relative file paths // used below will be inside the temporary directory. - $I->task('FileSystemStack') + $I->taskFileSystemStack() ->mkdir("log") ->touch("log/error.txt") ->addToCollection($collection); // Copy our tmp directory to a location that is not transient - $I->task('CopyDir', ['log' => "$cwd/copied2"]) + $I->taskCopyDir(['log' => "$cwd/copied2"]) ->addToCollection($collection); // FileSystemStack has not run yet, so no files should be found. @@ -140,13 +140,13 @@ public function toCreateATmpFileAndConfirmItIsDeleted(CliGuy $I) // Write to a temporary file. Note that we can get the path // to the tempoary file that will be created, even though the // the file is not created until the task collecction runs. - $tmpPath = $I->task('TmpFile', 'tmp', '.txt') + $tmpPath = $I->taskTmpFile('tmp', '.txt') ->line("This is a test file") ->addToCollection($collection) ->getPath(); // Copy our tmp directory to a location that is not transient - $I->task('FileSystemStack') + $I->taskFileSystemStack() ->copy($tmpPath, 'copied.txt') ->addToCollection($collection); @@ -173,7 +173,7 @@ public function toUseATmpDirWithAlternateSyntax(CliGuy $I) // We start off the same way, using addToCollection() to add our temporary // directory task to the collection, so that we have easy access to the // temporary directory's path via the getPath() method. - $tmpPath = $I->task('TmpDir') + $tmpPath = $I->taskTmpDir() ->addToCollection($collection) ->getPath(); @@ -182,8 +182,8 @@ public function toUseATmpDirWithAlternateSyntax(CliGuy $I) // via the add() method. $result = $collection->add( [ - $I->task('FileSystemStack')->mkdir("$tmpPath/log")->touch("$tmpPath/log/error.txt"), - $I->task('CopyDir', [$tmpPath => 'copied3']), + $I->taskFileSystemStack()->mkdir("$tmpPath/log")->touch("$tmpPath/log/error.txt"), + $I->taskCopyDir([$tmpPath => 'copied3']), ] )->run(); diff --git a/tests/cli/ConcatCept.php b/tests/cli/ConcatCept.php index 7319987ba..43b5479bb 100644 --- a/tests/cli/ConcatCept.php +++ b/tests/cli/ConcatCept.php @@ -4,7 +4,7 @@ $I->wantTo('concat files using Concat Task'); $I->amInPath(codecept_data_dir() . 'sandbox'); -$I->task('Concat', ['a.txt', 'b.txt']) +$I->taskConcat(['a.txt', 'b.txt']) ->to('merged.txt') ->run(); $I->seeFileFound('merged.txt'); diff --git a/tests/cli/CopyDirCept.php b/tests/cli/CopyDirCept.php index b09318a9a..c9d557aa4 100644 --- a/tests/cli/CopyDirCept.php +++ b/tests/cli/CopyDirCept.php @@ -4,7 +4,7 @@ $I->wantTo('copy dir with CopyDir task'); $I->amInPath(codecept_data_dir().'sandbox'); -$I->task('CopyDir', ['box' => 'bin']) +$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 292af2ffe..97b696494 100644 --- a/tests/cli/CopyDirOverwritesFilesCept.php +++ b/tests/cli/CopyDirOverwritesFilesCept.php @@ -6,7 +6,7 @@ $I->amInPath(codecept_data_dir() . 'sandbox'); $I->seeDirFound('some'); $I->seeFileFound('existing_file', 'some'); -$I->task('CopyDir', ['some' => 'some_destination']) +$I->taskCopyDir(['some' => 'some_destination']) ->run(); $I->seeFileFound('existing_file', 'some_destination/deeply'); $I->openFile('some_destination/deeply/existing_file'); diff --git a/tests/cli/CopyDirRecursiveCept.php b/tests/cli/CopyDirRecursiveCept.php index 8550d4580..b273e4fb9 100644 --- a/tests/cli/CopyDirRecursiveCept.php +++ b/tests/cli/CopyDirRecursiveCept.php @@ -6,7 +6,7 @@ $I->amInPath(codecept_data_dir() . 'sandbox'); $I->seeDirFound('some/deeply/nested'); $I->seeFileFound('structu.re', 'some/deeply/nested'); -$I->task('CopyDir', ['some/deeply' => 'some_destination/deeply']) +$I->taskCopyDir(['some/deeply' => 'some_destination/deeply']) ->run(); $I->seeDirFound('some_destination/deeply/nested'); $I->seeFileFound('structu.re', 'some_destination/deeply/nested'); diff --git a/tests/cli/DeleteDirCept.php b/tests/cli/DeleteDirCept.php index dcf7af588..de0aa5d02 100644 --- a/tests/cli/DeleteDirCept.php +++ b/tests/cli/DeleteDirCept.php @@ -6,7 +6,7 @@ $I->wantTo('delete dir with DeleteDirTask'); $I->amInPath(codecept_data_dir()); $I->seeFileFound('robo.txt', 'sandbox'); -$I->task('DeleteDir', ['sandbox/box']) +$I->taskDeleteDir(['sandbox/box']) ->run(); $I->dontSeeFileFound('box', 'sandbox'); $I->dontSeeFileFound('robo.txt', 'sandbox'); diff --git a/tests/cli/ExecCest.php b/tests/cli/ExecCest.php index 4cc3f0026..1f2f1f441 100644 --- a/tests/cli/ExecCest.php +++ b/tests/cli/ExecCest.php @@ -11,7 +11,7 @@ public function _before(CliGuy $I) public function toExecLsCommand(CliGuy $I) { $command = strncasecmp(PHP_OS, 'WIN', 3) == 0 ? 'dir' : 'ls'; - $res = $I->task('Exec', $command)->run(); + $res = $I->taskExec($command)->run(); verify($res->getMessage())->contains('src'); verify($res->getMessage())->contains('codeception.yml'); } diff --git a/tests/cli/FileSystemStackCest.php b/tests/cli/FileSystemStackCest.php index 5aba6d6e1..44ab38fab 100644 --- a/tests/cli/FileSystemStackCest.php +++ b/tests/cli/FileSystemStackCest.php @@ -10,7 +10,7 @@ public function _before(CliGuy $I) public function toCreateDir(CliGuy $I) { - $I->task('FileSystemStack') + $I->taskFileSystemStack() ->mkdir('log') ->touch('log/error.txt') ->run(); @@ -19,7 +19,7 @@ public function toCreateDir(CliGuy $I) public function toDeleteFile(CliGuy $I) { - $I->task('FileSystemStack') + $I->taskFileSystemStack() ->stopOnFail() ->remove('a.txt') ->run(); diff --git a/tests/cli/FlattenDirCept.php b/tests/cli/FlattenDirCept.php index 377fd2f27..98a5472f4 100644 --- a/tests/cli/FlattenDirCept.php +++ b/tests/cli/FlattenDirCept.php @@ -4,7 +4,7 @@ $I->wantTo('flatten dir with FlattenDir task'); $I->amInPath(codecept_data_dir().'sandbox'); -$I->task('FlattenDir', [ +$I->taskFlattenDir([ 'some/deeply/nested/*.re' => 'flattened', '*.txt' => 'flattened' ]) diff --git a/tests/cli/FlattenDirParentsCept.php b/tests/cli/FlattenDirParentsCept.php index 1f6c0a14f..247977690 100644 --- a/tests/cli/FlattenDirParentsCept.php +++ b/tests/cli/FlattenDirParentsCept.php @@ -4,7 +4,7 @@ $I->wantTo('flatten dir with FlattenDir task including parents'); $I->amInPath(codecept_data_dir().'sandbox'); -$I->task('FlattenDir', '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 b617ad25b..754d17f33 100644 --- a/tests/cli/PackExtractCept.php +++ b/tests/cli/PackExtractCept.php @@ -13,7 +13,7 @@ foreach (['zip', 'tar', 'tar.gz', 'tar.bz2', 'tgz'] as $archiveType) { // First, take everything from the folder 'some/deeply' and make // an archive for it located in 'deep' - $I->task('Pack', "deeply.$archiveType") + $I->taskPack("deeply.$archiveType") ->add(['deep' => 'some/deeply']) ->run(); $I->seeFileFound("deeply.$archiveType"); @@ -22,7 +22,7 @@ // for each archive type we test). We rely on the default behavior // of our extractor to remove the top-level directory in the archive // ("deeply"). - $I->task('Extract', "deeply.$archiveType") + $I->taskExtract("deeply.$archiveType") ->to("extracted-$archiveType") ->preserveTopDirectory(false) // this is the default ->run(); @@ -31,7 +31,7 @@ $I->seeFileFound('structu.re', "extracted-$archiveType/nested"); // Next, we'll extract the same archive again, this time preserving // the top-level folder. - $I->task('Extract', "deeply.$archiveType") + $I->taskExtract("deeply.$archiveType") ->to("preserved-$archiveType") ->preserveTopDirectory() ->run(); @@ -39,14 +39,14 @@ $I->seeDirFound("preserved-$archiveType/deep/nested"); $I->seeFileFound('structu.re', "preserved-$archiveType/deep/nested"); // Make another archive, this time composed of fanciful locations - $I->task('Pack', "composed.$archiveType") + $I->taskPack("composed.$archiveType") ->add(['a/b/existing_file' => 'some/deeply/existing_file']) ->add(['x/y/z/structu.re' => 'some/deeply/nested/structu.re']) ->run(); $I->seeFileFound("composed.$archiveType"); // Extract our composed archive, and see if the resulting file // structure matches expectations. - $I->task('Extract', "composed.$archiveType") + $I->taskExtract("composed.$archiveType") ->to("decomposed-$archiveType") ->preserveTopDirectory() ->run(); diff --git a/tests/cli/WriteFileCest.php b/tests/cli/WriteFileCest.php index e17c2f927..da2f35952 100644 --- a/tests/cli/WriteFileCest.php +++ b/tests/cli/WriteFileCest.php @@ -11,7 +11,7 @@ public function _before(CliGuy $I) public function writeFewLines(CliGuy $I) { $I->wantTo('write lines with WriteToFile task'); - $I->task('WriteToFile', 'blogpost.md') + $I->taskWriteToFile('blogpost.md') ->line('****') ->line('hello world') ->line('****') @@ -28,7 +28,7 @@ public function writeFewLines(CliGuy $I) public function appendToFile(CliGuy $I) { - $I->task('WriteToFile', 'a.txt') + $I->taskWriteToFile('a.txt') ->append() ->line('hello world') ->run(); @@ -42,7 +42,7 @@ public function appendToFile(CliGuy $I) public function insertFile(CliGuy $I) { - $I->task('WriteToFile', 'a.txt') + $I->taskWriteToFile('a.txt') ->line('****') ->textFromFile('b.txt') ->line("C") @@ -58,7 +58,7 @@ public function insertFile(CliGuy $I) public function replaceInFile(CliGuy $I) { - $I->task('ReplaceInFile', 'a.txt') + $I->taskReplaceInFile('a.txt') ->from('A') ->to('B') ->run(); @@ -69,7 +69,7 @@ public function replaceInFile(CliGuy $I) public function replaceMultipleInFile(CliGuy $I) { - $I->task('ReplaceInFile', 'box/robo.txt') + $I->taskReplaceInFile('box/robo.txt') ->from(array('HELLO', 'ROBO')) ->to(array('Hello ', 'robo.li!')) ->run(); From 729202a4d8a6924d630726080ac0527b292347dc Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 10:30:20 -0700 Subject: [PATCH 20/34] Simplify CliHelper to just use Tasklib (with appropriate remaps to 'public') --- tests/_helpers/CliHelper.php | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/tests/_helpers/CliHelper.php b/tests/_helpers/CliHelper.php index 573d0a93b..01e38a88e 100644 --- a/tests/_helpers/CliHelper.php +++ b/tests/_helpers/CliHelper.php @@ -12,45 +12,27 @@ class CliHelper extends \Codeception\Module implements ContainerAwareInterface { use ContainerAwareTrait; - use \Robo\Task\Base\loadTasks { + 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\Task\Archive\loadTasks { taskPack as public; taskExtract as public; } - public function task() - { - $args = func_get_args(); - $name = array_shift($args); - return $this->getContainer()->get("task$name", $args); - } - public function seeDirFound($dir) { $this->assertTrue(is_dir($dir) && file_exists($dir), "Directory does not exist"); From 8a014a86ddd02b29afbc84c2368a339374ad8cd1 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 10:32:00 -0700 Subject: [PATCH 21/34] Adjust spacing in Bower\loadTasks. --- src/Task/Bower/loadTasks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Task/Bower/loadTasks.php b/src/Task/Bower/loadTasks.php index ae6573690..cbac8ce18 100644 --- a/src/Task/Bower/loadTasks.php +++ b/src/Task/Bower/loadTasks.php @@ -9,7 +9,7 @@ trait loadTasks */ protected function taskBowerInstall($pathToBower = null) { - return $this->task('BowerInstall', $pathToBower); + return $this->task('BowerInstall', $pathToBower); } /** @@ -18,6 +18,6 @@ protected function taskBowerInstall($pathToBower = null) */ protected function taskBowerUpdate($pathToBower = null) { - return $this->task('BowerUpdate', $pathToBower); + return $this->task('BowerUpdate', $pathToBower); } } From 12b125528bcd3909cbd44b42402b35491676c059 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 10:42:50 -0700 Subject: [PATCH 22/34] Use __FUNCTION__ in loadTasks to ensure a strong corrolation between the function name and the service name. Service class name may vary. --- src/Task/ApiGen/loadTasks.php | 2 +- src/Task/Archive/loadTasks.php | 4 ++-- src/Task/Assets/loadTasks.php | 8 ++++---- src/Task/Base/loadTasks.php | 10 +++++----- src/Task/Bower/loadTasks.php | 4 ++-- src/Task/Composer/loadTasks.php | 6 +++--- src/Task/Development/loadTasks.php | 14 +++++++------- src/Task/Docker/loadTasks.php | 16 ++++++++-------- src/Task/File/loadTasks.php | 8 ++++---- src/Task/FileSystem/loadTasks.php | 14 +++++++------- src/Task/Gulp/loadTasks.php | 2 +- src/Task/Npm/loadTasks.php | 4 ++-- src/Task/Remote/loadTasks.php | 4 ++-- src/Task/Testing/loadTasks.php | 6 +++--- src/Task/Vcs/loadTasks.php | 4 ++-- src/Tasklib.php | 8 +++++++- 16 files changed, 60 insertions(+), 54 deletions(-) diff --git a/src/Task/ApiGen/loadTasks.php b/src/Task/ApiGen/loadTasks.php index 98aa92c95..9c63102c6 100644 --- a/src/Task/ApiGen/loadTasks.php +++ b/src/Task/ApiGen/loadTasks.php @@ -9,6 +9,6 @@ trait loadTasks */ protected function taskApiGen($pathToApiGen = null) { - return $this->task('ApiGen', $pathToApiGen); + return $this->task(__FUNCTION__, $pathToApiGen); } } diff --git a/src/Task/Archive/loadTasks.php b/src/Task/Archive/loadTasks.php index a95b16788..c4215f603 100644 --- a/src/Task/Archive/loadTasks.php +++ b/src/Task/Archive/loadTasks.php @@ -11,7 +11,7 @@ trait loadTasks */ protected function taskPack($filename) { - return $this->task('Pack', $filename); + return $this->task(__FUNCTION__, $filename); } /** @@ -21,6 +21,6 @@ protected function taskPack($filename) */ protected function taskExtract($filename) { - return $this->task('Extract', $filename); + return $this->task(__FUNCTION__, $filename); } } diff --git a/src/Task/Assets/loadTasks.php b/src/Task/Assets/loadTasks.php index a703cbe73..717cdab9b 100644 --- a/src/Task/Assets/loadTasks.php +++ b/src/Task/Assets/loadTasks.php @@ -9,7 +9,7 @@ trait loadTasks */ protected function taskMinify($input) { - return $this->task('Minify', $input); + return $this->task(__FUNCTION__, $input); } /** @@ -18,7 +18,7 @@ protected function taskMinify($input) */ protected function taskImageMinify($input) { - return $this->task('ImageMinify', $input); + return $this->task(__FUNCTION__, $input); } /** @@ -27,7 +27,7 @@ protected function taskImageMinify($input) */ protected function taskLess($input) { - return $this->task('Less', $input); + return $this->task(__FUNCTION__, $input); } /** @@ -36,6 +36,6 @@ protected function taskLess($input) */ protected function taskScss($input) { - return $this->task('Scss', $input); + return $this->task(__FUNCTION__, $input); } } diff --git a/src/Task/Base/loadTasks.php b/src/Task/Base/loadTasks.php index 37afabc1d..91520130c 100644 --- a/src/Task/Base/loadTasks.php +++ b/src/Task/Base/loadTasks.php @@ -9,12 +9,12 @@ trait loadTasks */ protected function taskExec($command) { - return $this->task('Exec', $command); + return $this->task(__FUNCTION__, $command); } protected function taskExecStack() { - return $this->task('ExecStack'); + return $this->task(__FUNCTION__); } /** @@ -22,7 +22,7 @@ protected function taskExecStack() */ protected function taskParallelExec() { - return $this->task('ParallelExec'); + return $this->task(__FUNCTION__); } /** @@ -31,7 +31,7 @@ protected function taskParallelExec() */ protected function taskSymfonyCommand($command) { - return $this->task('SymfonyCommand', $command); + return $this->task(__FUNCTION__, $command); } /** @@ -39,6 +39,6 @@ protected function taskSymfonyCommand($command) */ protected function taskWatch() { - return $this->task('Watch', $this); + return $this->task(__FUNCTION__, $this); } } diff --git a/src/Task/Bower/loadTasks.php b/src/Task/Bower/loadTasks.php index cbac8ce18..85b6d3dac 100644 --- a/src/Task/Bower/loadTasks.php +++ b/src/Task/Bower/loadTasks.php @@ -9,7 +9,7 @@ trait loadTasks */ protected function taskBowerInstall($pathToBower = null) { - return $this->task('BowerInstall', $pathToBower); + return $this->task(__FUNCTION__, $pathToBower); } /** @@ -18,6 +18,6 @@ protected function taskBowerInstall($pathToBower = null) */ protected function taskBowerUpdate($pathToBower = null) { - return $this->task('BowerUpdate', $pathToBower); + return $this->task(__FUNCTION__, $pathToBower); } } diff --git a/src/Task/Composer/loadTasks.php b/src/Task/Composer/loadTasks.php index b130710e9..b4035dd66 100644 --- a/src/Task/Composer/loadTasks.php +++ b/src/Task/Composer/loadTasks.php @@ -9,7 +9,7 @@ trait loadTasks */ protected function taskComposerInstall($pathToComposer = null) { - return $this->task('ComposerInstall', $pathToComposer); + return $this->task(__FUNCTION__, $pathToComposer); } /** @@ -18,7 +18,7 @@ protected function taskComposerInstall($pathToComposer = null) */ protected function taskComposerUpdate($pathToComposer = null) { - return $this->task('ComposerUpdate', $pathToComposer); + return $this->task(__FUNCTION__, $pathToComposer); } /** @@ -27,6 +27,6 @@ protected function taskComposerUpdate($pathToComposer = null) */ protected function taskComposerDumpAutoload($pathToComposer = null) { - return $this->task('ComposerDumpAutoload', $pathToComposer); + return $this->task(__FUNCTION__, $pathToComposer); } } diff --git a/src/Task/Development/loadTasks.php b/src/Task/Development/loadTasks.php index 8b47be63a..3f37f05a3 100644 --- a/src/Task/Development/loadTasks.php +++ b/src/Task/Development/loadTasks.php @@ -9,7 +9,7 @@ trait loadTasks */ protected function taskChangelog($filename = 'CHANGELOG.md') { - return $this->task('Changelog', $filename); + return $this->task(__FUNCTION__, $filename); } /** @@ -18,7 +18,7 @@ protected function taskChangelog($filename = 'CHANGELOG.md') */ protected function taskGenDoc($filename) { - return $this->task('GenDoc', $filename); + return $this->task(__FUNCTION__, $filename); } /** @@ -27,7 +27,7 @@ protected function taskGenDoc($filename) */ protected function taskSemVer($pathToSemVer = '.semver') { - return $this->task('SemVer', $pathToSemVer); + return $this->task(__FUNCTION__, $pathToSemVer); } /** @@ -36,7 +36,7 @@ protected function taskSemVer($pathToSemVer = '.semver') */ protected function taskServer($port = 8000) { - return $this->task('Server', $port); + return $this->task(__FUNCTION__, $port); } /** @@ -45,7 +45,7 @@ protected function taskServer($port = 8000) */ protected function taskPackPhar($filename) { - return $this->task('PackPhar', $filename); + return $this->task(__FUNCTION__, $filename); } /** @@ -54,7 +54,7 @@ protected function taskPackPhar($filename) */ protected function taskGitHubRelease($tag) { - return $this->task('GitHubRelease', $tag); + return $this->task(__FUNCTION__, $tag); } /** @@ -63,6 +63,6 @@ protected function taskGitHubRelease($tag) */ protected function taskOpenBrowser($url) { - return $this->task('OpenBrowser', $url); + return $this->task(__FUNCTION__, $url); } } diff --git a/src/Task/Docker/loadTasks.php b/src/Task/Docker/loadTasks.php index ddfe27386..e06c6ac6a 100644 --- a/src/Task/Docker/loadTasks.php +++ b/src/Task/Docker/loadTasks.php @@ -5,35 +5,35 @@ trait loadTasks { protected function taskDockerRun($image) { - return $this->task('DockerRun', $image); + return $this->task(__FUNCTION__, $image); } protected function taskDockerPull($image) { - return $this->task('DockerPull', $image); + return $this->task(__FUNCTION__, $image); } protected function taskDockerBuild($path = '.') { - return $this->task('DockerBuild', $path); + return $this->task(__FUNCTION__, $path); } protected function taskDockerStop($cidOrResult) { - return $this->task('DockerStop', $cidOrResult); + return $this->task(__FUNCTION__, $cidOrResult); } protected function taskDockerCommit($cidOrResult) { - return $this->task('DockerCommit', $cidOrResult); + return $this->task(__FUNCTION__, $cidOrResult); } protected function taskDockerStart($cidOrResult) { - return $this->task('DockerStart', $cidOrResult); + return $this->task(__FUNCTION__, $cidOrResult); } protected function taskDockerRemove($cidOrResult) { - return $this->task('DockerRemove', $cidOrResult); + return $this->task(__FUNCTION__, $cidOrResult); } protected function taskDockerExec($cidOrResult) { - return $this->task('DockerExec', $cidOrResult); + return $this->task(__FUNCTION__, $cidOrResult); } } diff --git a/src/Task/File/loadTasks.php b/src/Task/File/loadTasks.php index 5eac725ce..c84c26d2c 100644 --- a/src/Task/File/loadTasks.php +++ b/src/Task/File/loadTasks.php @@ -11,7 +11,7 @@ trait loadTasks */ protected function taskConcat($files) { - return $this->task('Concat', $files); + return $this->task(__FUNCTION__, $files); } /** @@ -20,7 +20,7 @@ protected function taskConcat($files) */ protected function taskReplaceInFile($file) { - return $this->task('ReplaceInFile', $file); + return $this->task(__FUNCTION__, $file); } /** @@ -29,7 +29,7 @@ protected function taskReplaceInFile($file) */ protected function taskWriteToFile($file) { - return $this->task('WriteToFile', $file); + return $this->task(__FUNCTION__, $file); } /** @@ -40,6 +40,6 @@ protected function taskWriteToFile($file) */ protected function taskTmpFile($filename = 'tmp', $extension = '', $baseDir = '', $includeRandomPart = true) { - return $this->task('TmpFile', $filename, $extension, $baseDir, $includeRandomPart); + return $this->task(__FUNCTION__, $filename, $extension, $baseDir, $includeRandomPart); } } diff --git a/src/Task/FileSystem/loadTasks.php b/src/Task/FileSystem/loadTasks.php index fcc6d3f8a..d395cb6b4 100644 --- a/src/Task/FileSystem/loadTasks.php +++ b/src/Task/FileSystem/loadTasks.php @@ -11,7 +11,7 @@ trait loadTasks */ protected function taskCleanDir($dirs) { - return $this->task('CleanDir', $dirs); + return $this->task(__FUNCTION__, $dirs); } /** @@ -20,7 +20,7 @@ protected function taskCleanDir($dirs) */ protected function taskDeleteDir($dirs) { - return $this->task('DeleteDir', $dirs); + return $this->task(__FUNCTION__, $dirs); } /** @@ -31,7 +31,7 @@ protected function taskDeleteDir($dirs) */ protected function taskTmpDir($prefix = 'tmp', $base = '', $includeRandomPart = true) { - return $this->task('TmpDir', $prefix, $base, $includeRandomPart); + return $this->task(__FUNCTION__, $prefix, $base, $includeRandomPart); } /** @@ -40,7 +40,7 @@ protected function taskTmpDir($prefix = 'tmp', $base = '', $includeRandomPart = */ protected function taskCopyDir($dirs) { - return $this->task('CopyDir', $dirs); + return $this->task(__FUNCTION__, $dirs); } /** @@ -49,7 +49,7 @@ protected function taskCopyDir($dirs) */ protected function taskMirrorDir($dirs) { - return $this->task('MirrorDir', $dirs); + return $this->task(__FUNCTION__, $dirs); } /** @@ -58,7 +58,7 @@ protected function taskMirrorDir($dirs) */ protected function taskFlattenDir($dirs) { - return $this->task('FlattenDir', $dirs); + return $this->task(__FUNCTION__, $dirs); } /** @@ -66,6 +66,6 @@ protected function taskFlattenDir($dirs) */ protected function taskFilesystemStack() { - return $this->task('FilesystemStack'); + return $this->task(__FUNCTION__); } } diff --git a/src/Task/Gulp/loadTasks.php b/src/Task/Gulp/loadTasks.php index eae5f34d1..cf9a88383 100644 --- a/src/Task/Gulp/loadTasks.php +++ b/src/Task/Gulp/loadTasks.php @@ -9,6 +9,6 @@ trait loadTasks * @return Run */ protected function taskGulpRun($task='default',$pathToGulp = null) { - return $this->task('GulpRun', $task,$pathToGulp); + return $this->task(__FUNCTION__, $task,$pathToGulp); } } diff --git a/src/Task/Npm/loadTasks.php b/src/Task/Npm/loadTasks.php index 014277a5b..57312fcb1 100644 --- a/src/Task/Npm/loadTasks.php +++ b/src/Task/Npm/loadTasks.php @@ -8,7 +8,7 @@ trait loadTasks * @return Install */ protected function taskNpmInstall($pathToNpm = null) { - return $this->task('NpmInstall', $pathToNpm); + return $this->task(__FUNCTION__, $pathToNpm); } /** @@ -16,6 +16,6 @@ protected function taskNpmInstall($pathToNpm = null) { * @return Update */ protected function taskNpmUpdate($pathToNpm = null) { - return $this->task('NpmUpdate', $pathToNpm); + return $this->task(__FUNCTION__, $pathToNpm); } } diff --git a/src/Task/Remote/loadTasks.php b/src/Task/Remote/loadTasks.php index 31be715ce..46a372c84 100644 --- a/src/Task/Remote/loadTasks.php +++ b/src/Task/Remote/loadTasks.php @@ -8,7 +8,7 @@ trait loadTasks */ protected function taskRsync() { - return $this->task('Rsync'); + return $this->task(__FUNCTION__); } /** @@ -18,6 +18,6 @@ protected function taskRsync() */ protected function taskSshExec($hostname = null, $user = null) { - return $this->task('Ssh', $hostname, $user); + return $this->task(__FUNCTION__, $hostname, $user); } } diff --git a/src/Task/Testing/loadTasks.php b/src/Task/Testing/loadTasks.php index b5abaf737..79104ef4f 100644 --- a/src/Task/Testing/loadTasks.php +++ b/src/Task/Testing/loadTasks.php @@ -9,7 +9,7 @@ trait loadTasks */ protected function taskCodecept($pathToCodeception = null) { - return $this->task('Codecept', $pathToCodeception); + return $this->task(__FUNCTION__, $pathToCodeception); } /** @@ -18,7 +18,7 @@ protected function taskCodecept($pathToCodeception = null) */ protected function taskPhpUnit($pathToPhpUnit = null) { - return $this->task('PHPUnit', $pathToPhpUnit); + return $this->task(__FUNCTION__, $pathToPhpUnit); } /** @@ -27,6 +27,6 @@ protected function taskPhpUnit($pathToPhpUnit = null) */ protected function taskPhpspec($pathToPhpspec = null) { - return $this->task('Phpspec', $pathToPhpspec); + return $this->task(__FUNCTION__, $pathToPhpspec); } } diff --git a/src/Task/Vcs/loadTasks.php b/src/Task/Vcs/loadTasks.php index a1c11ad2b..ab5864631 100644 --- a/src/Task/Vcs/loadTasks.php +++ b/src/Task/Vcs/loadTasks.php @@ -11,7 +11,7 @@ trait loadTasks */ protected function taskSvnStack($username = '', $password = '', $pathToSvn = 'svn') { - return $this->task('SvnStack', $username, $password, $pathToSvn); + return $this->task(__FUNCTION__, $username, $password, $pathToSvn); } /** @@ -20,6 +20,6 @@ protected function taskSvnStack($username = '', $password = '', $pathToSvn = 'sv */ protected function taskGitStack($pathToGit = 'git') { - return $this->task('GitStack', $pathToGit); + return $this->task(__FUNCTION__, $pathToGit); } } diff --git a/src/Tasklib.php b/src/Tasklib.php index 3ace6414f..a4cc6b406 100644 --- a/src/Tasklib.php +++ b/src/Tasklib.php @@ -69,6 +69,12 @@ protected function task() { $args = func_get_args(); $name = array_shift($args); - return $this->getContainer()->get("task$name", $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); } } From 426cf5f8c46c159da1496c1c0baa645616f2d139 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 10:46:03 -0700 Subject: [PATCH 23/34] Restore RoboFile to previous version (resume use of loadTask shortcuts). --- RoboFile.php | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 07d9bc664..65ad92974 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -75,7 +75,7 @@ public function release() $this->yell("Releasing Robo"); $this->docs(); - $this->task('GitStack') + $this->taskGitStack() ->add('-A') ->commit("auto-update") ->pull() @@ -85,7 +85,7 @@ public function release() $this->pharPublish(); $this->publish(); - $this->task('GitHubRelease', \Robo\Runner::VERSION) + $this->taskGitHubRelease(\Robo\Runner::VERSION) ->uri('Codegyre/Robo') ->askDescription() ->run(); @@ -95,14 +95,14 @@ public function release() public function test($args = "") { - return $this->task('Codecept') + return $this->taskCodecept() ->args($args) ->run(); } public function changed($addition) { - $this->task('Changelog') + $this->taskChangelog() ->version(\Robo\Runner::VERSION) ->change($addition) ->run(); @@ -115,7 +115,7 @@ public function versionBump($version = null) $versionParts[count($versionParts)-1]++; $version = implode('.', $versionParts); } - $this->task('ReplaceInFile', __DIR__.'/src/Runner.php') + $this->taskReplaceInFile(__DIR__.'/src/Runner.php') ->from("VERSION = '".\Robo\Runner::VERSION."'") ->to("VERSION = '".$version."'") ->run(); @@ -147,7 +147,7 @@ class_exists($class = "Robo\\Task\\$ns\\$class"); ksort($docs); foreach ($docs as $ns => $tasks) { - $taskGenerator = $this->task('GenDoc', "docs/tasks/$ns.md"); + $taskGenerator = $this->taskGenDoc("docs/tasks/$ns.md"); $taskGenerator->filterClasses(function (\ReflectionClass $r) { return !($r->isAbstract() or $r->isTrait()) and $r->implementsInterface('Robo\Contract\TaskInterface'); })->prepend("# $ns Tasks"); @@ -195,20 +195,20 @@ public function publish() $current_branch = exec('git rev-parse --abbrev-ref HEAD'); $collection = $this->collection(); - $this->task('GitStack') + $this->taskGitStack() ->checkout('site') ->merge('master') ->addToCollection($collection); - $this->task('GitStack') + $this->taskGitStack() ->checkout($current_branch) ->addAsCompletion($collection); - $this->task('FilesystemStack') + $this->taskFilesystemStack() ->copy('CHANGELOG.md', 'docs/changelog.md') ->addToCollection($collection); - $this->task('FilesystemStack') + $this->taskFilesystemStack() ->remove('docs/changelog.md') ->addAsCompletion($collection); - $this->task('Exec', 'mkdocs gh-deploy') + $this->taskExec('mkdocs gh-deploy') ->addToCollection($collection); $collection->run(); } @@ -217,12 +217,12 @@ public function pharBuild() { $collection = $this->collection(); - $this->task('ComposerInstall') + $this->taskComposerInstall() ->noDev() ->printed(false) ->addToCollection($collection); - $packer = $this->task('PackPhar', 'robo.phar'); + $packer = $this->taskPackPhar('robo.phar'); $files = Finder::create()->ignoreVCS(true) ->files() ->name('*.php') @@ -243,7 +243,7 @@ public function pharBuild() ->executable('robo') ->addToCollection($collection); - $this->task('ComposerInstall') + $this->taskComposerInstall() ->printed(false) ->addToCollection($collection); @@ -252,7 +252,7 @@ public function pharBuild() public function pharInstall() { - $this->task('Exec', 'sudo cp') + $this->taskExec('sudo cp') ->arg('robo.phar') ->arg('/usr/bin/robo') ->run(); @@ -263,12 +263,12 @@ public function pharPublish() $this->pharBuild(); $this->_rename('robo.phar', 'robo-release.phar'); - $this->task('GitStack')->checkout('gh-pages')->run(); - $this->task('FilesystemStack') + $this->taskGitStack()->checkout('gh-pages')->run(); + $this->taskFilesystemStack() ->remove('robo.phar') ->rename('robo-release.phar', 'robo.phar') ->run(); - $this->task('GitStack') + $this->taskGitStack() ->add('robo.phar') ->commit('robo.phar published') ->push('origin','gh-pages') @@ -278,8 +278,8 @@ public function pharPublish() public function tryWatch() { - $this->task('Watch')->monitor(['composer.json', 'composer.lock'], function () { - $this->task('ComposerUpdate')->run(); + $this->taskWatch()->monitor(['composer.json', 'composer.lock'], function() { + $this->taskComposerUpdate()->run(); })->run(); } @@ -301,7 +301,7 @@ public function tryInput() */ public function tryPara() { - $this->task('ParallelExec') + $this->taskParallelExec() ->process('php ~/demos/robotests/parascript.php hey') ->process('php ~/demos/robotests/parascript.php hoy') ->process('php ~/demos/robotests/parascript.php gou') @@ -316,7 +316,7 @@ public function tryOptbool($opts = ['silent|s' => false]) public function tryServer() { - $this->task('Server', 8000) + $this->taskServer(8000) ->dir('site') ->arg('site/index.php') ->run(); @@ -324,7 +324,7 @@ public function tryServer() public function tryOpenBrowser() { - $this->task('OpenBrowser', [ + $this->taskOpenBrowser([ 'http://robo.li', 'https://github.com/Codegyre/Robo' ]) @@ -339,11 +339,11 @@ public function tryInteractive() public function tryError() { - $result = $this->task('Exec', 'ls xyzzy' . date('U'))->dir('/tmp')->run(); + $result = $this->taskExec('ls xyzzy' . date('U'))->dir('/tmp')->run(); } public function trySuccess() { - $result = $this->task('Exec', 'pwd')->run(); + $result = $this->taskExec('pwd')->run(); } } From 3ee6235d62b13f041dcc25105ab756b07c8bab3c Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 12:59:06 -0700 Subject: [PATCH 24/34] Be more consistent with container use for object initialization. --- src/Collection/Collection.php | 10 ++++++++-- .../{TaskWrapper.php => CompletionWrapper.php} | 16 ++++++++-------- src/Collection/Temporary.php | 13 +------------ src/Common/TaskIO.php | 12 +++--------- src/Container/RoboContainer.php | 5 ++--- src/Contract/CompletionInterface.php | 9 --------- src/Runner.php | 2 ++ src/Task/BaseTask.php | 5 +++-- tests/_helpers/CodeHelper.php | 11 +++++------ tests/unit/Task/ApiGenTest.php | 6 ++---- tests/unit/Task/BowerTest.php | 6 ++---- tests/unit/Task/CodeceptionTest.php | 6 ++---- tests/unit/Task/CollectionTest.php | 6 ++---- tests/unit/Task/CommandStackTest.php | 6 ++---- tests/unit/Task/ComposerTest.php | 6 ++---- tests/unit/Task/ExecTaskTest.php | 6 ++---- tests/unit/Task/GitTest.php | 6 ++---- tests/unit/Task/GulpTest.php | 5 +---- tests/unit/Task/NpmTest.php | 6 ++---- tests/unit/Task/PHPServerTest.php | 6 ++---- tests/unit/Task/PHPUnitTest.php | 6 ++---- tests/unit/Task/ParallelExecTest.php | 6 ++---- tests/unit/Task/PhpspecTest.php | 6 ++---- tests/unit/Task/RsyncTest.php | 6 ++---- tests/unit/Task/SemVerTest.php | 6 ++---- tests/unit/Task/SshTest.php | 6 ++---- tests/unit/Task/SvnTest.php | 6 ++---- 27 files changed, 67 insertions(+), 123 deletions(-) rename src/Collection/{TaskWrapper.php => CompletionWrapper.php} (80%) diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php index 56675bf3c..f995c3f4e 100644 --- a/src/Collection/Collection.php +++ b/src/Collection/Collection.php @@ -4,6 +4,9 @@ use Robo\Result; use Robo\Contract\TaskInterface; +use League\Container\ContainerAwareInterface; +use League\Container\ContainerAwareTrait; + /** * Group tasks into a collection that run together. Supports * rollback operations for handling error conditions. @@ -30,8 +33,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. @@ -274,7 +279,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 80% rename from src/Collection/TaskWrapper.php rename to src/Collection/CompletionWrapper.php index a9187836f..4373d2eb3 100644 --- a/src/Collection/TaskWrapper.php +++ b/src/Collection/CompletionWrapper.php @@ -10,30 +10,30 @@ /** * 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 { 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 getTask 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. */ 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/Common/TaskIO.php b/src/Common/TaskIO.php index 86842f2b8..a5737459f 100644 --- a/src/Common/TaskIO.php +++ b/src/Common/TaskIO.php @@ -4,6 +4,8 @@ use Robo\Config; use Robo\TaskInfo; use Consolidation\Log\ConsoleLogLevel; +use Psr\Log\LoggerAwareTrait; +use Psr\Log\LoggerInterface; /** * Task input/output methods. TaskIO is 'used' in BaseTask, so any @@ -14,15 +16,7 @@ */ trait TaskIO { - /** - * @var \Psr\Log\LoggerInterface - */ - protected $logger; - - public function setLogger($logger) - { - $this->logger = $logger; - } + use LoggerAwareTrait; public function logger() { diff --git a/src/Container/RoboContainer.php b/src/Container/RoboContainer.php index 1cd5b9b11..a6231ada2 100644 --- a/src/Container/RoboContainer.php +++ b/src/Container/RoboContainer.php @@ -5,7 +5,6 @@ use Robo\Contract\CompletionInterface; use Robo\Collection\Temporary; -use Robo\Task\Simulator; use Robo\Contract\TaskInterface; use Robo\Collection\Collection; @@ -53,13 +52,13 @@ public function get($alias, array $args = []) // first. If the task is added to a collection, then its // complete method will be called after the collection completes. if ($service instanceof CompletionInterface) { - $service = Temporary::wrap($service); + $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 = new Simulator($service, $args); + $service = parent::get('simulator', [$service, $args]); } return $service; 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/Runner.php b/src/Runner.php index 5172a918c..3280509b4 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -132,6 +132,8 @@ public static function configureContainer($container, $input = null, $output = n ->withArgument('output') ->withMethodCall('setLogOutputStyler', ['logStyler']); $container->share('resultPrinter', \Robo\Log\ResultPrinter::class); + $container->add('simulator', \Robo\Task\Simulator::class); + $container->add('completionWrapper', \Robo\Collection\CompletionWrapper::class); // Register our various inflectors. $container->inflector(\Psr\Log\LoggerAwareInterface::class) 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/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/unit/Task/ApiGenTest.php b/tests/unit/Task/ApiGenTest.php index 07dc983f2..875722f96 100644 --- a/tests/unit/Task/ApiGenTest.php +++ b/tests/unit/Task/ApiGenTest.php @@ -1,7 +1,6 @@ new \Symfony\Component\Console\Output\NullOutput() ]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\ApiGen\ServiceProvider::class); } diff --git a/tests/unit/Task/BowerTest.php b/tests/unit/Task/BowerTest.php index 870bddfdc..ca139c2c2 100644 --- a/tests/unit/Task/BowerTest.php +++ b/tests/unit/Task/BowerTest.php @@ -1,7 +1,6 @@ baseBower = test::double('Robo\Task\Bower\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(Robo\Task\Bower\ServiceProvider::class); } // tests diff --git a/tests/unit/Task/CodeceptionTest.php b/tests/unit/Task/CodeceptionTest.php index 3ada89396..206202343 100644 --- a/tests/unit/Task/CodeceptionTest.php +++ b/tests/unit/Task/CodeceptionTest.php @@ -1,7 +1,6 @@ null, 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Testing\ServiceProvider::class); } diff --git a/tests/unit/Task/CollectionTest.php b/tests/unit/Task/CollectionTest.php index b144720e8..f5dae4aed 100644 --- a/tests/unit/Task/CollectionTest.php +++ b/tests/unit/Task/CollectionTest.php @@ -10,8 +10,7 @@ use Robo\Task\BaseTask; use Robo\Contract\TaskInterface; use Robo\Collection\Collection; -use Robo\Runner; -use Robo\Container\RoboContainer; +use Robo\Config; class CollectionTest extends \Codeception\TestCase\Test { @@ -19,8 +18,7 @@ class CollectionTest extends \Codeception\TestCase\Test protected function _before() { - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Collection\ServiceProvider::class); } diff --git a/tests/unit/Task/CommandStackTest.php b/tests/unit/Task/CommandStackTest.php index 70f6355b8..75e454053 100644 --- a/tests/unit/Task/CommandStackTest.php +++ b/tests/unit/Task/CommandStackTest.php @@ -1,7 +1,6 @@ container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); } public function testExecStackExecutableIsTrimmedFromCommand() diff --git a/tests/unit/Task/ComposerTest.php b/tests/unit/Task/ComposerTest.php index e8d2e1f17..2e9eac65e 100644 --- a/tests/unit/Task/ComposerTest.php +++ b/tests/unit/Task/ComposerTest.php @@ -1,7 +1,6 @@ baseComposer = test::double('Robo\Task\Composer\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Composer\ServiceProvider::class); } // tests diff --git a/tests/unit/Task/ExecTaskTest.php b/tests/unit/Task/ExecTaskTest.php index 77c6cdc0a..cccde164e 100644 --- a/tests/unit/Task/ExecTaskTest.php +++ b/tests/unit/Task/ExecTaskTest.php @@ -1,7 +1,6 @@ 0 ]); test::double('Robo\Task\Base\Exec', ['getOutput' => new \Symfony\Component\Console\Output\NullOutput()]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Base\ServiceProvider::class); } diff --git a/tests/unit/Task/GitTest.php b/tests/unit/Task/GitTest.php index ffe4050f2..688ed6093 100644 --- a/tests/unit/Task/GitTest.php +++ b/tests/unit/Task/GitTest.php @@ -1,8 +1,7 @@ new \AspectMock\Proxy\Anything(), 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Vcs\ServiceProvider::class); } // tests diff --git a/tests/unit/Task/GulpTest.php b/tests/unit/Task/GulpTest.php index 975a36417..106957ed5 100644 --- a/tests/unit/Task/GulpTest.php +++ b/tests/unit/Task/GulpTest.php @@ -1,8 +1,6 @@ baseGulp = test::double('Robo\Task\Gulp\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Gulp\ServiceProvider::class); } diff --git a/tests/unit/Task/NpmTest.php b/tests/unit/Task/NpmTest.php index 2ab8591e5..6a9a1b240 100644 --- a/tests/unit/Task/NpmTest.php +++ b/tests/unit/Task/NpmTest.php @@ -1,7 +1,6 @@ baseNpm = test::double('Robo\Task\Npm\Base', [ 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Npm\ServiceProvider::class); } diff --git a/tests/unit/Task/PHPServerTest.php b/tests/unit/Task/PHPServerTest.php index c9197be02..a474f3a89 100644 --- a/tests/unit/Task/PHPServerTest.php +++ b/tests/unit/Task/PHPServerTest.php @@ -1,8 +1,7 @@ 0 ]); test::double('Robo\Task\Development\PhpServer', ['getOutput' => new \Symfony\Component\Console\Output\NullOutput()]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Development\ServiceProvider::class); } diff --git a/tests/unit/Task/PHPUnitTest.php b/tests/unit/Task/PHPUnitTest.php index 7e9c14627..3f97cac08 100644 --- a/tests/unit/Task/PHPUnitTest.php +++ b/tests/unit/Task/PHPUnitTest.php @@ -1,7 +1,6 @@ null, 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Testing\ServiceProvider::class); } diff --git a/tests/unit/Task/ParallelExecTest.php b/tests/unit/Task/ParallelExecTest.php index d39938c43..67e6d60b6 100644 --- a/tests/unit/Task/ParallelExecTest.php +++ b/tests/unit/Task/ParallelExecTest.php @@ -1,7 +1,6 @@ 'Hello world', 'getExitCode' => 0 ]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Base\ServiceProvider::class); } diff --git a/tests/unit/Task/PhpspecTest.php b/tests/unit/Task/PhpspecTest.php index d7da1b9f7..ac28be077 100644 --- a/tests/unit/Task/PhpspecTest.php +++ b/tests/unit/Task/PhpspecTest.php @@ -1,7 +1,6 @@ null, 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Testing\ServiceProvider::class); } diff --git a/tests/unit/Task/RsyncTest.php b/tests/unit/Task/RsyncTest.php index f05c80842..901d0d825 100644 --- a/tests/unit/Task/RsyncTest.php +++ b/tests/unit/Task/RsyncTest.php @@ -1,8 +1,7 @@ container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Remote\ServiceProvider::class); } diff --git a/tests/unit/Task/SemVerTest.php b/tests/unit/Task/SemVerTest.php index c8f81f911..86c18f209 100644 --- a/tests/unit/Task/SemVerTest.php +++ b/tests/unit/Task/SemVerTest.php @@ -1,8 +1,7 @@ container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Development\ServiceProvider::class); } diff --git a/tests/unit/Task/SshTest.php b/tests/unit/Task/SshTest.php index e8a1a67c1..02bcb2a7d 100644 --- a/tests/unit/Task/SshTest.php +++ b/tests/unit/Task/SshTest.php @@ -1,8 +1,7 @@ container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Remote\ServiceProvider::class); } diff --git a/tests/unit/Task/SvnTest.php b/tests/unit/Task/SvnTest.php index 3cbf5a034..cb6bb7aca 100644 --- a/tests/unit/Task/SvnTest.php +++ b/tests/unit/Task/SvnTest.php @@ -1,8 +1,7 @@ new \Symfony\Component\Console\Output\NullOutput() ]); - $this->container = new RoboContainer(); - Runner::configureContainer($this->container); + $this->container = Config::getContainer(); $this->container->addServiceProvider(\Robo\Task\Vcs\ServiceProvider::class); } From 8388ce3402f766eab853224134a86c8fa26f5f54 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 14:15:19 -0700 Subject: [PATCH 25/34] Formalize wrapped tasks. --- src/Collection/CompletionWrapper.php | 9 +++++---- src/Collection/ServiceProvider.php | 2 ++ src/Contract/WrappedTaskInterface.php | 10 ++++++++++ src/Runner.php | 1 - src/Task/Simulator.php | 17 ++++++++++++++--- 5 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 src/Contract/WrappedTaskInterface.php diff --git a/src/Collection/CompletionWrapper.php b/src/Collection/CompletionWrapper.php index 4373d2eb3..a395ca8e4 100644 --- a/src/Collection/CompletionWrapper.php +++ b/src/Collection/CompletionWrapper.php @@ -6,6 +6,7 @@ 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 @@ -18,7 +19,7 @@ * * @see Robo\Task\FileSystem\loadTasks::taskTmpDir */ -class CompletionWrapper extends BaseTask +class CompletionWrapper extends BaseTask implements WrappedTaskInterface { private $collection; private $task; @@ -30,7 +31,7 @@ class CompletionWrapper extends BaseTask * 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 - * CompletionWrapper (via its getTask method), and then added to a + * CompletionWrapper (via its original() method), and then added to a * new CompletionWrapper for the collection it is added to. * * In this way, when the CompletionWrapper is finally executed, the @@ -40,11 +41,11 @@ class CompletionWrapper extends BaseTask 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 index 2198aadb7..b15f199de 100644 --- a/src/Collection/ServiceProvider.php +++ b/src/Collection/ServiceProvider.php @@ -7,10 +7,12 @@ class ServiceProvider extends AbstractServiceProvider { protected $provides = [ 'collection', + 'completionWrapper', ]; public function register() { $this->getContainer()->add('collection', Collection::class); + $this->getContainer()->add('completionWrapper', CompletionWrapper::class); } } 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 @@ +withMethodCall('setLogOutputStyler', ['logStyler']); $container->share('resultPrinter', \Robo\Log\ResultPrinter::class); $container->add('simulator', \Robo\Task\Simulator::class); - $container->add('completionWrapper', \Robo\Collection\CompletionWrapper::class); // Register our various inflectors. $container->inflector(\Psr\Log\LoggerAwareInterface::class) diff --git a/src/Task/Simulator.php b/src/Task/Simulator.php index cc106d674..02b389dba 100644 --- a/src/Task/Simulator.php +++ b/src/Task/Simulator.php @@ -5,8 +5,9 @@ use Robo\Result; use Robo\Contract\TaskInterface; use Robo\Log\RoboLogLevel; +use Robo\Contract\WrappedTaskInterface; -class Simulator extends BaseTask +class Simulator extends BaseTask implements WrappedTaskInterface { protected $task; protected $constructorParameters; @@ -14,10 +15,16 @@ class Simulator extends BaseTask public function __construct(TaskInterface $task, $constructorParameters) { - $this->task = $task; + $this->task = ($task instanceof WrappedTaskInterface) ? $task->original() : $task; + $this->constructorParameters = $constructorParameters; } + public function original() + { + return $this->task; + } + public function __call($function, $args) { $this->stack[] = array_merge([$function], $args); @@ -54,9 +61,13 @@ function ($item) { if (is_callable($item)) { return 'inline_function(...)'; } - if (is_array($item) || is_object($item)) { + 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'"; } From cd4fbedb3b281b4f913894907e448aec789ccd21 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 14:36:22 -0700 Subject: [PATCH 26/34] Do not wrap our wrappers. Do not unwrap the Simulator when adding to a collection. --- src/Container/RoboContainer.php | 13 +++++++++++-- src/Task/Simulator.php | 11 +++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Container/RoboContainer.php b/src/Container/RoboContainer.php index a6231ada2..f72649cbe 100644 --- a/src/Container/RoboContainer.php +++ b/src/Container/RoboContainer.php @@ -7,6 +7,8 @@ use Robo\Collection\Temporary; use Robo\Contract\TaskInterface; use Robo\Collection\Collection; +use Robo\Collection\CompletionWrapper; +use Robo\Task\Simulator; class RoboContainer extends Container { @@ -41,6 +43,11 @@ 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; @@ -49,8 +56,10 @@ public function get($alias, array $args = []) // 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 its - // complete method will be called after the collection completes. + // 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]); } diff --git a/src/Task/Simulator.php b/src/Task/Simulator.php index 02b389dba..6f3cf5577 100644 --- a/src/Task/Simulator.php +++ b/src/Task/Simulator.php @@ -5,9 +5,8 @@ use Robo\Result; use Robo\Contract\TaskInterface; use Robo\Log\RoboLogLevel; -use Robo\Contract\WrappedTaskInterface; -class Simulator extends BaseTask implements WrappedTaskInterface +class Simulator extends BaseTask { protected $task; protected $constructorParameters; @@ -15,16 +14,12 @@ class Simulator extends BaseTask implements WrappedTaskInterface public function __construct(TaskInterface $task, $constructorParameters) { + // TODO: If we ever want to convert the simulated task back into + // an executable task, then we should save the wrapped task. $this->task = ($task instanceof WrappedTaskInterface) ? $task->original() : $task; - $this->constructorParameters = $constructorParameters; } - public function original() - { - return $this->task; - } - public function __call($function, $args) { $this->stack[] = array_merge([$function], $args); From 9e0c4b0e6cf42ef3a26ff12e96ddbc9d041506c3 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 15:44:25 -0700 Subject: [PATCH 27/34] Ensure that logger is always configured for core Robo tasks. Emit a deprecation warning if an unconfigured task attempts to print anything. --- RoboFile.php | 42 ++++++++++++++++++++++++++++++++++ src/Common/TaskIO.php | 14 +++++++++++- src/Task/FileSystem/TmpDir.php | 9 ++++++-- tests/unit/Task/SvnTest.php | 9 ++++---- 4 files changed, 67 insertions(+), 7 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 65ad92974..5362a4aae 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -346,4 +346,46 @@ 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/src/Common/TaskIO.php b/src/Common/TaskIO.php index a5737459f..c2ef11bd5 100644 --- a/src/Common/TaskIO.php +++ b/src/Common/TaskIO.php @@ -18,9 +18,21 @@ trait TaskIO { use LoggerAwareTrait; + static $gaveDeprecationWarning = false; + public function logger() { - return $this->logger ?: Config::logger(); + // $this->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; } /** 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/tests/unit/Task/SvnTest.php b/tests/unit/Task/SvnTest.php index cb6bb7aca..2a31e55dd 100644 --- a/tests/unit/Task/SvnTest.php +++ b/tests/unit/Task/SvnTest.php @@ -14,13 +14,14 @@ class SvnTest extends \Codeception\TestCase\Test protected function _before() { + $this->container = Config::getContainer(); + $this->container->addServiceProvider(\Robo\Task\Vcs\ServiceProvider::class); + $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'), ]); - - $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Vcs\ServiceProvider::class); } // tests From bf25add64b38f1b5912be1c6a0ff7329fd0e933a Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 15:48:05 -0700 Subject: [PATCH 28/34] Use SimpleServiceProvider to register Collection services. --- src/Collection/ServiceProvider.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Collection/ServiceProvider.php b/src/Collection/ServiceProvider.php index b15f199de..9f7395793 100644 --- a/src/Collection/ServiceProvider.php +++ b/src/Collection/ServiceProvider.php @@ -1,18 +1,17 @@ getContainer()->add('collection', Collection::class); - $this->getContainer()->add('completionWrapper', CompletionWrapper::class); + parent::__construct( + [ + 'collection' => Collection::class, + 'completionWrapper' => CompletionWrapper::class, + ] + ); } } From ac88ae9b252dccdc3dc1ed5bc485744f93f580b6 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 15:54:21 -0700 Subject: [PATCH 29/34] SimpleServiceProvider does not need to be abstract. --- src/Container/SimpleServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Container/SimpleServiceProvider.php b/src/Container/SimpleServiceProvider.php index 37dd54ae8..7a2df42c8 100644 --- a/src/Container/SimpleServiceProvider.php +++ b/src/Container/SimpleServiceProvider.php @@ -12,7 +12,7 @@ * for each element is the service alias, and its corresponding value * is the name of the implementing service class. */ -abstract class SimpleServiceProvider implements ServiceProviderInterface +class SimpleServiceProvider implements ServiceProviderInterface { use ContainerAwareTrait; From 9b31b4e52eb68ff0d41a4caa28cc52743a7a4721 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 15:55:15 -0700 Subject: [PATCH 30/34] Move File ServiceProviders into loadTasks. --- src/Runner.php | 2 +- src/Task/File/ServiceProvider.php | 19 ------------------- src/Task/File/loadTasks.php | 16 ++++++++++++++++ src/Task/FileSystem/loadTasks.php | 18 ++++++++++++++++++ tests/cli/CollectionCest.php | 2 +- tests/cli/ConcatCept.php | 2 +- tests/cli/WriteFileCest.php | 2 +- 7 files changed, 38 insertions(+), 23 deletions(-) delete mode 100644 src/Task/File/ServiceProvider.php diff --git a/src/Runner.php b/src/Runner.php index 6045134ae..f139b1e0e 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -157,7 +157,7 @@ public static function addServiceProviders($container) $container->addServiceProvider(\Robo\Task\Composer\ServiceProvider::class); $container->addServiceProvider(\Robo\Task\Development\ServiceProvider::class); $container->addServiceProvider(\Robo\Task\Docker\ServiceProvider::class); - $container->addServiceProvider(\Robo\Task\File\ServiceProvider::class); + $container->addServiceProvider(\Robo\Task\File\loadTasks::getFileServices()); $container->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); $container->addServiceProvider(\Robo\Task\Remote\ServiceProvider::class); $container->addServiceProvider(\Robo\Task\Testing\ServiceProvider::class); diff --git a/src/Task/File/ServiceProvider.php b/src/Task/File/ServiceProvider.php deleted file mode 100644 index d61c2907f..000000000 --- a/src/Task/File/ServiceProvider.php +++ /dev/null @@ -1,19 +0,0 @@ - Concat::class, - 'taskReplaceInFile' => Replace::class, - 'taskWriteToFile' => Write::class, - 'taskTmpFile' => TmpFile::class, - ] - ); - } -} diff --git a/src/Task/File/loadTasks.php b/src/Task/File/loadTasks.php index c84c26d2c..138b64467 100644 --- a/src/Task/File/loadTasks.php +++ b/src/Task/File/loadTasks.php @@ -2,9 +2,25 @@ 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 diff --git a/src/Task/FileSystem/loadTasks.php b/src/Task/FileSystem/loadTasks.php index d395cb6b4..6aaa5df9a 100644 --- a/src/Task/FileSystem/loadTasks.php +++ b/src/Task/FileSystem/loadTasks.php @@ -5,6 +5,24 @@ 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 diff --git a/tests/cli/CollectionCest.php b/tests/cli/CollectionCest.php index b868e8119..f6deb44c7 100644 --- a/tests/cli/CollectionCest.php +++ b/tests/cli/CollectionCest.php @@ -12,7 +12,7 @@ class CollectionCest public function _before(CliGuy $I) { $I->getContainer()->addServiceProvider(\Robo\Collection\ServiceProvider::class); - $I->getContainer()->addServiceProvider(\Robo\Task\File\ServiceProvider::class); + $I->getContainer()->addServiceProvider(\Robo\Task\File\loadTasks::getFileServices()); $I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); $I->amInPath(codecept_data_dir().'sandbox'); diff --git a/tests/cli/ConcatCept.php b/tests/cli/ConcatCept.php index 43b5479bb..2b3ce7fcd 100644 --- a/tests/cli/ConcatCept.php +++ b/tests/cli/ConcatCept.php @@ -1,6 +1,6 @@ getContainer()->addServiceProvider(\Robo\Task\File\ServiceProvider::class); +$I->getContainer()->addServiceProvider(\Robo\Task\File\loadTasks::getFileServices()); $I->wantTo('concat files using Concat Task'); $I->amInPath(codecept_data_dir() . 'sandbox'); diff --git a/tests/cli/WriteFileCest.php b/tests/cli/WriteFileCest.php index da2f35952..d4194ce61 100644 --- a/tests/cli/WriteFileCest.php +++ b/tests/cli/WriteFileCest.php @@ -4,7 +4,7 @@ class WriteFileCest { public function _before(CliGuy $I) { - $I->getContainer()->addServiceProvider(\Robo\Task\File\ServiceProvider::class); + $I->getContainer()->addServiceProvider(\Robo\Task\File\loadTasks::getFileServices()); $I->amInPath(codecept_data_dir('sandbox')); } From a1515f6a7b5ce99306da6ab8b7911aca298af96c Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 17:16:15 -0700 Subject: [PATCH 31/34] Move all of the ServiceProvider classes into loadTasks. --- src/Collection/Collection.php | 14 +++++++++++++ src/Runner.php | 26 ++++++++++++------------ src/Task/ApiGen/ApiGen.php | 1 - src/Task/ApiGen/ServiceProvider.php | 16 --------------- src/Task/ApiGen/loadTasks.php | 14 +++++++++++++ src/Task/Archive/ServiceProvider.php | 17 ---------------- src/Task/Archive/loadTasks.php | 16 ++++++++++++++- src/Task/Assets/ServiceProvider.php | 19 ----------------- src/Task/Assets/loadTasks.php | 17 ++++++++++++++++ src/Task/Base/ServiceProvider.php | 20 ------------------ src/Task/Base/loadTasks.php | 18 ++++++++++++++++ src/Task/Bower/ServiceProvider.php | 17 ---------------- src/Task/Bower/loadTasks.php | 15 ++++++++++++++ src/Task/Composer/ServiceProvider.php | 18 ---------------- src/Task/Composer/loadTasks.php | 16 +++++++++++++++ src/Task/Development/ServiceProvider.php | 22 -------------------- src/Task/Development/loadTasks.php | 20 ++++++++++++++++++ src/Task/Docker/ServiceProvider.php | 22 -------------------- src/Task/Docker/loadTasks.php | 20 ++++++++++++++++++ src/Task/FileSystem/ServiceProvider.php | 22 -------------------- src/Task/FileSystem/loadTasks.php | 1 + src/Task/Gulp/ServiceProvider.php | 16 --------------- src/Task/Gulp/loadTasks.php | 14 +++++++++++++ src/Task/Npm/ServiceProvider.php | 17 ---------------- src/Task/Npm/loadTasks.php | 15 ++++++++++++++ src/Task/Remote/ServiceProvider.php | 17 ---------------- src/Task/Remote/loadTasks.php | 15 ++++++++++++++ src/Task/Testing/ServiceProvider.php | 18 ---------------- src/Task/Testing/loadTasks.php | 16 +++++++++++++++ src/Task/Vcs/ServiceProvider.php | 17 ---------------- src/Task/Vcs/loadTasks.php | 15 ++++++++++++++ tests/cli/CleanDirCept.php | 4 +++- tests/cli/CollectionCest.php | 4 ++-- tests/cli/ConcatCept.php | 1 + tests/cli/CopyDirCept.php | 3 ++- tests/cli/CopyDirOverwritesFilesCept.php | 2 +- tests/cli/CopyDirRecursiveCept.php | 2 +- tests/cli/DeleteDirCept.php | 2 +- tests/cli/ExecCest.php | 2 +- tests/cli/FileSystemStackCest.php | 2 +- tests/cli/FlattenDirCept.php | 2 +- tests/cli/FlattenDirParentsCept.php | 2 +- tests/cli/PackExtractCept.php | 2 +- tests/unit/Task/ApiGenTest.php | 2 +- tests/unit/Task/BowerTest.php | 2 +- tests/unit/Task/CodeceptionTest.php | 2 +- tests/unit/Task/CollectionTest.php | 2 +- tests/unit/Task/ComposerTest.php | 2 +- tests/unit/Task/ExecTaskTest.php | 2 +- tests/unit/Task/GitTest.php | 2 +- tests/unit/Task/GulpTest.php | 2 +- tests/unit/Task/NpmTest.php | 2 +- tests/unit/Task/PHPServerTest.php | 2 +- tests/unit/Task/PHPUnitTest.php | 2 +- tests/unit/Task/ParallelExecTest.php | 2 +- tests/unit/Task/PhpspecTest.php | 2 +- tests/unit/Task/RsyncTest.php | 2 +- tests/unit/Task/SemVerTest.php | 2 +- tests/unit/Task/SshTest.php | 2 +- tests/unit/Task/SvnTest.php | 2 +- 60 files changed, 271 insertions(+), 302 deletions(-) delete mode 100644 src/Task/ApiGen/ServiceProvider.php delete mode 100644 src/Task/Archive/ServiceProvider.php delete mode 100644 src/Task/Assets/ServiceProvider.php delete mode 100644 src/Task/Base/ServiceProvider.php delete mode 100644 src/Task/Bower/ServiceProvider.php delete mode 100644 src/Task/Composer/ServiceProvider.php delete mode 100644 src/Task/Development/ServiceProvider.php delete mode 100644 src/Task/Docker/ServiceProvider.php delete mode 100644 src/Task/FileSystem/ServiceProvider.php delete mode 100644 src/Task/Gulp/ServiceProvider.php delete mode 100644 src/Task/Npm/ServiceProvider.php delete mode 100644 src/Task/Remote/ServiceProvider.php delete mode 100644 src/Task/Testing/ServiceProvider.php delete mode 100644 src/Task/Vcs/ServiceProvider.php diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php index f995c3f4e..94a2a9e5c 100644 --- a/src/Collection/Collection.php +++ b/src/Collection/Collection.php @@ -3,6 +3,7 @@ use Robo\Result; use Robo\Contract\TaskInterface; +use Robo\Container\SimpleServiceProvider; use League\Container\ContainerAwareInterface; use League\Container\ContainerAwareTrait; @@ -47,6 +48,19 @@ class Collection implements TaskInterface, ContainerAwareInterface protected $completionStack = []; protected $previousResult; + /** + * Return services. + */ + public static function getCollectionServices() + { + return new SimpleServiceProvider( + [ + 'collection' => Collection::class, + 'completionWrapper' => CompletionWrapper::class, + ] + ); + } + /** * Constructor. */ diff --git a/src/Runner.php b/src/Runner.php index f139b1e0e..65766d075 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -148,20 +148,20 @@ public static function configureContainer($container, $input = null, $output = n */ public static function addServiceProviders($container) { - $container->addServiceProvider(\Robo\Collection\ServiceProvider::class); - $container->addServiceProvider(\Robo\Task\ApiGen\ServiceProvider::class); - $container->addServiceProvider(\Robo\Task\Archive\ServiceProvider::class); - $container->addServiceProvider(\Robo\Task\Assets\ServiceProvider::class); - $container->addServiceProvider(\Robo\Task\Base\ServiceProvider::class); - $container->addServiceProvider(\Robo\Task\Bower\ServiceProvider::class); - $container->addServiceProvider(\Robo\Task\Composer\ServiceProvider::class); - $container->addServiceProvider(\Robo\Task\Development\ServiceProvider::class); - $container->addServiceProvider(\Robo\Task\Docker\ServiceProvider::class); + $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\ServiceProvider::class); - $container->addServiceProvider(\Robo\Task\Remote\ServiceProvider::class); - $container->addServiceProvider(\Robo\Task\Testing\ServiceProvider::class); - $container->addServiceProvider(\Robo\Task\Vcs\ServiceProvider::class); + $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, - ] - ); - } -} diff --git a/src/Task/ApiGen/loadTasks.php b/src/Task/ApiGen/loadTasks.php index 9c63102c6..e75fdaf64 100644 --- a/src/Task/ApiGen/loadTasks.php +++ b/src/Task/ApiGen/loadTasks.php @@ -1,8 +1,22 @@ ApiGen::class, + ] + ); + } + /** * @param null $pathToApiGen * @return \Robo\Task\ApiGen\ApiGen diff --git a/src/Task/Archive/ServiceProvider.php b/src/Task/Archive/ServiceProvider.php deleted file mode 100644 index 6c5c23768..000000000 --- a/src/Task/Archive/ServiceProvider.php +++ /dev/null @@ -1,17 +0,0 @@ - Extract::class, - 'taskPack' => Pack::class, - ] - ); - } -} diff --git a/src/Task/Archive/loadTasks.php b/src/Task/Archive/loadTasks.php index c4215f603..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 * diff --git a/src/Task/Assets/ServiceProvider.php b/src/Task/Assets/ServiceProvider.php deleted file mode 100644 index 1569b56b6..000000000 --- a/src/Task/Assets/ServiceProvider.php +++ /dev/null @@ -1,19 +0,0 @@ - Minify::class, - 'taskImageMinify' => ImageMinify::class, - 'taskLess' => Less::class, - 'taskScss' => Scss::class, - ] - ); - } -} diff --git a/src/Task/Assets/loadTasks.php b/src/Task/Assets/loadTasks.php index 717cdab9b..4eb69f248 100644 --- a/src/Task/Assets/loadTasks.php +++ b/src/Task/Assets/loadTasks.php @@ -1,8 +1,25 @@ Minify::class, + 'taskImageMinify' => ImageMinify::class, + 'taskLess' => Less::class, + 'taskScss' => Scss::class, + ] + ); + } + /** * @param $input * @return Minify diff --git a/src/Task/Base/ServiceProvider.php b/src/Task/Base/ServiceProvider.php deleted file mode 100644 index a3a91a561..000000000 --- a/src/Task/Base/ServiceProvider.php +++ /dev/null @@ -1,20 +0,0 @@ - Exec::class, - 'taskExecStack' => ExecStack::class, - 'taskParallelExec' => ParallelExec::class, - 'taskSymfonyCommand' => SymfonyCommand::class, - 'taskWatch' => Watch::class, - ] - ); - } -} diff --git a/src/Task/Base/loadTasks.php b/src/Task/Base/loadTasks.php index 91520130c..bee7a0451 100644 --- a/src/Task/Base/loadTasks.php +++ b/src/Task/Base/loadTasks.php @@ -1,8 +1,26 @@ Exec::class, + 'taskExecStack' => ExecStack::class, + 'taskParallelExec' => ParallelExec::class, + 'taskSymfonyCommand' => SymfonyCommand::class, + 'taskWatch' => Watch::class, + ] + ); + } + /** * @param $command * @return Exec diff --git a/src/Task/Bower/ServiceProvider.php b/src/Task/Bower/ServiceProvider.php deleted file mode 100644 index 37b827c86..000000000 --- a/src/Task/Bower/ServiceProvider.php +++ /dev/null @@ -1,17 +0,0 @@ - Install::class, - 'taskBowerUpdate' => Update::class, - ] - ); - } -} diff --git a/src/Task/Bower/loadTasks.php b/src/Task/Bower/loadTasks.php index 85b6d3dac..91b382ded 100644 --- a/src/Task/Bower/loadTasks.php +++ b/src/Task/Bower/loadTasks.php @@ -1,8 +1,23 @@ Install::class, + 'taskBowerUpdate' => Update::class, + ] + ); + } + /** * @param null $pathToBower * @return Install diff --git a/src/Task/Composer/ServiceProvider.php b/src/Task/Composer/ServiceProvider.php deleted file mode 100644 index e21dd5656..000000000 --- a/src/Task/Composer/ServiceProvider.php +++ /dev/null @@ -1,18 +0,0 @@ - Install::class, - 'taskComposerUpdate' => Update::class, - 'taskComposerDumpAutoload' => DumpAutoload::class, - ] - ); - } -} diff --git a/src/Task/Composer/loadTasks.php b/src/Task/Composer/loadTasks.php index b4035dd66..aa32e3767 100644 --- a/src/Task/Composer/loadTasks.php +++ b/src/Task/Composer/loadTasks.php @@ -1,8 +1,24 @@ Install::class, + 'taskComposerUpdate' => Update::class, + 'taskComposerDumpAutoload' => DumpAutoload::class, + ] + ); + } + /** * @param null $pathToComposer * @return Install diff --git a/src/Task/Development/ServiceProvider.php b/src/Task/Development/ServiceProvider.php deleted file mode 100644 index c770313b7..000000000 --- a/src/Task/Development/ServiceProvider.php +++ /dev/null @@ -1,22 +0,0 @@ - Changelog::class, - 'taskGenDoc' => GenerateMarkdownDoc::class, - 'taskSemVer' => SemVer::class, - 'taskServer' => PhpServer::class, - 'taskPackPhar' => PackPhar::class, - 'taskGitHubRelease' => GitHubRelease::class, - 'taskOpenBrowser' => OpenBrowser::class, - ] - ); - } -} diff --git a/src/Task/Development/loadTasks.php b/src/Task/Development/loadTasks.php index 3f37f05a3..b7cd1f242 100644 --- a/src/Task/Development/loadTasks.php +++ b/src/Task/Development/loadTasks.php @@ -1,8 +1,28 @@ 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 diff --git a/src/Task/Docker/ServiceProvider.php b/src/Task/Docker/ServiceProvider.php deleted file mode 100644 index a94462b6c..000000000 --- a/src/Task/Docker/ServiceProvider.php +++ /dev/null @@ -1,22 +0,0 @@ - Run::class, - 'taskDockerPull' => Pull::class, - 'taskDockerBuild' => Build::class, - 'taskDockerStop' => Stop::class, - 'taskDockerCommit' => Commit::class, - 'taskDockerStart' => Start::class, - 'taskDockerRemove' => Remove::class, - ] - ); - } -} diff --git a/src/Task/Docker/loadTasks.php b/src/Task/Docker/loadTasks.php index e06c6ac6a..e0aedca74 100644 --- a/src/Task/Docker/loadTasks.php +++ b/src/Task/Docker/loadTasks.php @@ -1,8 +1,28 @@ 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 $this->task(__FUNCTION__, $image); diff --git a/src/Task/FileSystem/ServiceProvider.php b/src/Task/FileSystem/ServiceProvider.php deleted file mode 100644 index daf947eb7..000000000 --- a/src/Task/FileSystem/ServiceProvider.php +++ /dev/null @@ -1,22 +0,0 @@ - CleanDir::class, - 'taskDeleteDir' => DeleteDir::class, - 'taskTmpDir' => TmpDir::class, - 'taskCopyDir' => CopyDir::class, - 'taskMirrorDir' => MirrorDir::class, - 'taskFlattenDir' => FlattenDir::class, - 'taskFilesystemStack' => FilesystemStack::class, - ] - ); - } -} diff --git a/src/Task/FileSystem/loadTasks.php b/src/Task/FileSystem/loadTasks.php index 6aaa5df9a..fd3cb3351 100644 --- a/src/Task/FileSystem/loadTasks.php +++ b/src/Task/FileSystem/loadTasks.php @@ -2,6 +2,7 @@ namespace Robo\Task\FileSystem; use Robo\Collection\Temporary; +use Robo\Container\SimpleServiceProvider; trait loadTasks { diff --git a/src/Task/Gulp/ServiceProvider.php b/src/Task/Gulp/ServiceProvider.php deleted file mode 100644 index bff71c7ca..000000000 --- a/src/Task/Gulp/ServiceProvider.php +++ /dev/null @@ -1,16 +0,0 @@ - Run::class, - ] - ); - } -} diff --git a/src/Task/Gulp/loadTasks.php b/src/Task/Gulp/loadTasks.php index cf9a88383..1f7725481 100644 --- a/src/Task/Gulp/loadTasks.php +++ b/src/Task/Gulp/loadTasks.php @@ -1,8 +1,22 @@ Run::class, + ] + ); + } + /** * @param $task * @param null $pathToGulp diff --git a/src/Task/Npm/ServiceProvider.php b/src/Task/Npm/ServiceProvider.php deleted file mode 100644 index 96c9ae86c..000000000 --- a/src/Task/Npm/ServiceProvider.php +++ /dev/null @@ -1,17 +0,0 @@ - Install::class, - 'taskNpmUpdate' => Update::class, - ] - ); - } -} diff --git a/src/Task/Npm/loadTasks.php b/src/Task/Npm/loadTasks.php index 57312fcb1..49c866615 100644 --- a/src/Task/Npm/loadTasks.php +++ b/src/Task/Npm/loadTasks.php @@ -1,8 +1,23 @@ Install::class, + 'taskNpmUpdate' => Update::class, + ] + ); + } + /** * @param null $pathToNpm * @return Install diff --git a/src/Task/Remote/ServiceProvider.php b/src/Task/Remote/ServiceProvider.php deleted file mode 100644 index 4c7088a8d..000000000 --- a/src/Task/Remote/ServiceProvider.php +++ /dev/null @@ -1,17 +0,0 @@ - Rsync::class, - 'taskSshExec' => Ssh::class, - ] - ); - } -} diff --git a/src/Task/Remote/loadTasks.php b/src/Task/Remote/loadTasks.php index 46a372c84..85450b029 100644 --- a/src/Task/Remote/loadTasks.php +++ b/src/Task/Remote/loadTasks.php @@ -1,8 +1,23 @@ Rsync::class, + 'taskSshExec' => Ssh::class, + ] + ); + } + /** * @return Rsync */ diff --git a/src/Task/Testing/ServiceProvider.php b/src/Task/Testing/ServiceProvider.php deleted file mode 100644 index 5bb28b7d5..000000000 --- a/src/Task/Testing/ServiceProvider.php +++ /dev/null @@ -1,18 +0,0 @@ - Codecept::class, - 'taskPHPUnit' => PHPUnit::class, - 'taskPhpspec' => Phpspec::class, - ] - ); - } -} diff --git a/src/Task/Testing/loadTasks.php b/src/Task/Testing/loadTasks.php index 79104ef4f..94809323d 100644 --- a/src/Task/Testing/loadTasks.php +++ b/src/Task/Testing/loadTasks.php @@ -1,8 +1,24 @@ Codecept::class, + 'taskPHPUnit' => PHPUnit::class, + 'taskPhpspec' => Phpspec::class, + ] + ); + } + /** * @param null $pathToCodeception * @return Codecept diff --git a/src/Task/Vcs/ServiceProvider.php b/src/Task/Vcs/ServiceProvider.php deleted file mode 100644 index faca3bb18..000000000 --- a/src/Task/Vcs/ServiceProvider.php +++ /dev/null @@ -1,17 +0,0 @@ - SvnStack::class, - 'taskGitStack' => GitStack::class, - ] - ); - } -} diff --git a/src/Task/Vcs/loadTasks.php b/src/Task/Vcs/loadTasks.php index ab5864631..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 diff --git a/tests/cli/CleanDirCept.php b/tests/cli/CleanDirCept.php index 71e10b005..83cc5485c 100644 --- a/tests/cli/CleanDirCept.php +++ b/tests/cli/CleanDirCept.php @@ -1,6 +1,6 @@ getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); +$I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); $I->wantTo('clean dir with DeleteDirTask'); $I->amInPath(codecept_data_dir()); @@ -10,3 +10,5 @@ $I->dontSeeFileFound('box', 'sandbox'); $I->dontSeeFileFound('robo.txt', 'sandbox'); $I->dontSeeFileFound('a.txt' , 'sandbox'); + + diff --git a/tests/cli/CollectionCest.php b/tests/cli/CollectionCest.php index f6deb44c7..f155964c6 100644 --- a/tests/cli/CollectionCest.php +++ b/tests/cli/CollectionCest.php @@ -11,9 +11,9 @@ class CollectionCest { public function _before(CliGuy $I) { - $I->getContainer()->addServiceProvider(\Robo\Collection\ServiceProvider::class); + $I->getContainer()->addServiceProvider(\Robo\Collection\Collection::getCollectionServices()); $I->getContainer()->addServiceProvider(\Robo\Task\File\loadTasks::getFileServices()); - $I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); + $I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); $I->amInPath(codecept_data_dir().'sandbox'); } diff --git a/tests/cli/ConcatCept.php b/tests/cli/ConcatCept.php index 2b3ce7fcd..eb78bd207 100644 --- a/tests/cli/ConcatCept.php +++ b/tests/cli/ConcatCept.php @@ -9,3 +9,4 @@ ->run(); $I->seeFileFound('merged.txt'); $I->seeFileContentsEqual("A\nB\n"); + diff --git a/tests/cli/CopyDirCept.php b/tests/cli/CopyDirCept.php index c9d557aa4..3dfb487a0 100644 --- a/tests/cli/CopyDirCept.php +++ b/tests/cli/CopyDirCept.php @@ -1,6 +1,6 @@ getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); +$I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); $I->wantTo('copy dir with CopyDir task'); $I->amInPath(codecept_data_dir().'sandbox'); @@ -8,3 +8,4 @@ ->run(); $I->seeDirFound('bin'); $I->seeFileFound('robo.txt', 'bin'); + diff --git a/tests/cli/CopyDirOverwritesFilesCept.php b/tests/cli/CopyDirOverwritesFilesCept.php index 97b696494..2318bf70d 100644 --- a/tests/cli/CopyDirOverwritesFilesCept.php +++ b/tests/cli/CopyDirOverwritesFilesCept.php @@ -1,6 +1,6 @@ getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); +$I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); $I->wantTo('overwrite a file with CopyDir task'); $I->amInPath(codecept_data_dir() . 'sandbox'); diff --git a/tests/cli/CopyDirRecursiveCept.php b/tests/cli/CopyDirRecursiveCept.php index b273e4fb9..d6eb0bfee 100644 --- a/tests/cli/CopyDirRecursiveCept.php +++ b/tests/cli/CopyDirRecursiveCept.php @@ -1,6 +1,6 @@ getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); +$I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); $I->wantTo('copy dir recursively with CopyDir task'); $I->amInPath(codecept_data_dir() . 'sandbox'); diff --git a/tests/cli/DeleteDirCept.php b/tests/cli/DeleteDirCept.php index de0aa5d02..f63095c3e 100644 --- a/tests/cli/DeleteDirCept.php +++ b/tests/cli/DeleteDirCept.php @@ -1,7 +1,7 @@ getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); +$I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); $I->wantTo('delete dir with DeleteDirTask'); $I->amInPath(codecept_data_dir()); diff --git a/tests/cli/ExecCest.php b/tests/cli/ExecCest.php index 1f2f1f441..f71ef968c 100644 --- a/tests/cli/ExecCest.php +++ b/tests/cli/ExecCest.php @@ -4,7 +4,7 @@ class ExecCest { public function _before(CliGuy $I) { - $I->getContainer()->addServiceProvider(\Robo\Task\Base\ServiceProvider::class); + $I->getContainer()->addServiceProvider(\Robo\Task\Base\loadTasks::getBaseServices()); } // tests diff --git a/tests/cli/FileSystemStackCest.php b/tests/cli/FileSystemStackCest.php index 44ab38fab..603ce12f0 100644 --- a/tests/cli/FileSystemStackCest.php +++ b/tests/cli/FileSystemStackCest.php @@ -4,7 +4,7 @@ class FileSystemStackCest { public function _before(CliGuy $I) { - $I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); + $I->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 98a5472f4..44079c217 100644 --- a/tests/cli/FlattenDirCept.php +++ b/tests/cli/FlattenDirCept.php @@ -1,6 +1,6 @@ getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); +$I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); $I->wantTo('flatten dir with FlattenDir task'); $I->amInPath(codecept_data_dir().'sandbox'); diff --git a/tests/cli/FlattenDirParentsCept.php b/tests/cli/FlattenDirParentsCept.php index 247977690..ba822396d 100644 --- a/tests/cli/FlattenDirParentsCept.php +++ b/tests/cli/FlattenDirParentsCept.php @@ -1,6 +1,6 @@ getContainer()->addServiceProvider(\Robo\Task\FileSystem\ServiceProvider::class); +$I->getContainer()->addServiceProvider(\Robo\Task\FileSystem\loadTasks::getFileSystemServices()); $I->wantTo('flatten dir with FlattenDir task including parents'); $I->amInPath(codecept_data_dir().'sandbox'); diff --git a/tests/cli/PackExtractCept.php b/tests/cli/PackExtractCept.php index 754d17f33..691ed3719 100644 --- a/tests/cli/PackExtractCept.php +++ b/tests/cli/PackExtractCept.php @@ -1,7 +1,7 @@ getContainer()->addServiceProvider(\Robo\Task\Archive\ServiceProvider::class); +$I->getContainer()->addServiceProvider(\Robo\Task\Archive\loadTasks::getArchiveServices()); $I->wantTo('archive directory and then extract it again with Archive and Extract tasks'); $I->amInPath(codecept_data_dir().'sandbox'); diff --git a/tests/unit/Task/ApiGenTest.php b/tests/unit/Task/ApiGenTest.php index 875722f96..e27a25835 100644 --- a/tests/unit/Task/ApiGenTest.php +++ b/tests/unit/Task/ApiGenTest.php @@ -19,7 +19,7 @@ protected function _before() ]); $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\ApiGen\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\ApiGen\loadTasks::getApiGenServices()); } // tests diff --git a/tests/unit/Task/BowerTest.php b/tests/unit/Task/BowerTest.php index ca139c2c2..7d1c687ac 100644 --- a/tests/unit/Task/BowerTest.php +++ b/tests/unit/Task/BowerTest.php @@ -17,7 +17,7 @@ protected function _before() 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); $this->container = Config::getContainer(); - $this->container->addServiceProvider(Robo\Task\Bower\ServiceProvider::class); + $this->container->addServiceProvider(Robo\Task\Bower\loadTasks::getBowerServices()); } // tests public function testBowerInstall() diff --git a/tests/unit/Task/CodeceptionTest.php b/tests/unit/Task/CodeceptionTest.php index 206202343..b2f5b8617 100644 --- a/tests/unit/Task/CodeceptionTest.php +++ b/tests/unit/Task/CodeceptionTest.php @@ -25,7 +25,7 @@ protected function _before() 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Testing\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Testing\loadTasks::getTestingServices()); } // tests diff --git a/tests/unit/Task/CollectionTest.php b/tests/unit/Task/CollectionTest.php index f5dae4aed..c5b90170a 100644 --- a/tests/unit/Task/CollectionTest.php +++ b/tests/unit/Task/CollectionTest.php @@ -19,7 +19,7 @@ class CollectionTest extends \Codeception\TestCase\Test protected function _before() { $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Collection\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Collection\Collection::getCollectionServices()); } public function testBeforeAndAfterFilters() diff --git a/tests/unit/Task/ComposerTest.php b/tests/unit/Task/ComposerTest.php index 2e9eac65e..38ef3c57f 100644 --- a/tests/unit/Task/ComposerTest.php +++ b/tests/unit/Task/ComposerTest.php @@ -17,7 +17,7 @@ protected function _before() 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Composer\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Composer\loadTasks::getComposerServices()); } // tests public function testComposerInstall() diff --git a/tests/unit/Task/ExecTaskTest.php b/tests/unit/Task/ExecTaskTest.php index cccde164e..39dff9859 100644 --- a/tests/unit/Task/ExecTaskTest.php +++ b/tests/unit/Task/ExecTaskTest.php @@ -21,7 +21,7 @@ protected function _before() ]); test::double('Robo\Task\Base\Exec', ['getOutput' => new \Symfony\Component\Console\Output\NullOutput()]); $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Base\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Base\loadTasks::getBaseServices()); } public function testExec() diff --git a/tests/unit/Task/GitTest.php b/tests/unit/Task/GitTest.php index 688ed6093..54ce03c88 100644 --- a/tests/unit/Task/GitTest.php +++ b/tests/unit/Task/GitTest.php @@ -19,7 +19,7 @@ protected function _before() 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Vcs\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Vcs\loadTasks::getVcsServices()); } // tests public function testGitStackRun() diff --git a/tests/unit/Task/GulpTest.php b/tests/unit/Task/GulpTest.php index 106957ed5..18a238b7a 100644 --- a/tests/unit/Task/GulpTest.php +++ b/tests/unit/Task/GulpTest.php @@ -17,7 +17,7 @@ protected function _before() 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Gulp\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Gulp\loadTasks::getGulpServices()); } // tests diff --git a/tests/unit/Task/NpmTest.php b/tests/unit/Task/NpmTest.php index 6a9a1b240..751b260d3 100644 --- a/tests/unit/Task/NpmTest.php +++ b/tests/unit/Task/NpmTest.php @@ -17,7 +17,7 @@ protected function _before() 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Npm\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Npm\loadTasks::getNpmServices()); } // tests diff --git a/tests/unit/Task/PHPServerTest.php b/tests/unit/Task/PHPServerTest.php index a474f3a89..ff44d2b0a 100644 --- a/tests/unit/Task/PHPServerTest.php +++ b/tests/unit/Task/PHPServerTest.php @@ -22,7 +22,7 @@ protected function _before() ]); test::double('Robo\Task\Development\PhpServer', ['getOutput' => new \Symfony\Component\Console\Output\NullOutput()]); $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Development\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Development\loadTasks::getDevelopmentServices()); } public function testServerBackgroundRun() diff --git a/tests/unit/Task/PHPUnitTest.php b/tests/unit/Task/PHPUnitTest.php index 3f97cac08..f1cc4190a 100644 --- a/tests/unit/Task/PHPUnitTest.php +++ b/tests/unit/Task/PHPUnitTest.php @@ -18,7 +18,7 @@ protected function _before() 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Testing\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Testing\loadTasks::getTestingServices()); } // tests diff --git a/tests/unit/Task/ParallelExecTest.php b/tests/unit/Task/ParallelExecTest.php index 67e6d60b6..a9b544dc3 100644 --- a/tests/unit/Task/ParallelExecTest.php +++ b/tests/unit/Task/ParallelExecTest.php @@ -26,7 +26,7 @@ protected function _before() 'getExitCode' => 0 ]); $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Base\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Base\loadTasks::getBaseServices()); } public function testParallelExec() diff --git a/tests/unit/Task/PhpspecTest.php b/tests/unit/Task/PhpspecTest.php index ac28be077..798d7e0ad 100644 --- a/tests/unit/Task/PhpspecTest.php +++ b/tests/unit/Task/PhpspecTest.php @@ -18,7 +18,7 @@ protected function _before() 'getOutput' => new \Symfony\Component\Console\Output\NullOutput() ]); $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Testing\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Testing\loadTasks::getTestingServices()); } // tests diff --git a/tests/unit/Task/RsyncTest.php b/tests/unit/Task/RsyncTest.php index 901d0d825..545315188 100644 --- a/tests/unit/Task/RsyncTest.php +++ b/tests/unit/Task/RsyncTest.php @@ -15,7 +15,7 @@ class RsyncTest extends \Codeception\TestCase\Test protected function _before() { $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Remote\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Remote\loadTasks::getRemoteServices()); } // tests diff --git a/tests/unit/Task/SemVerTest.php b/tests/unit/Task/SemVerTest.php index 86c18f209..599455d53 100644 --- a/tests/unit/Task/SemVerTest.php +++ b/tests/unit/Task/SemVerTest.php @@ -10,7 +10,7 @@ class SemVerTest extends \Codeception\TestCase\Test protected function _before() { $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Development\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Development\loadTasks::getDevelopmentServices()); } public function testSemver() diff --git a/tests/unit/Task/SshTest.php b/tests/unit/Task/SshTest.php index 02bcb2a7d..d6f358b32 100644 --- a/tests/unit/Task/SshTest.php +++ b/tests/unit/Task/SshTest.php @@ -10,7 +10,7 @@ class SshTest extends \Codeception\TestCase\Test protected function _before() { $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Remote\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Remote\loadTasks::getRemoteServices()); } // tests diff --git a/tests/unit/Task/SvnTest.php b/tests/unit/Task/SvnTest.php index 2a31e55dd..686ae580c 100644 --- a/tests/unit/Task/SvnTest.php +++ b/tests/unit/Task/SvnTest.php @@ -15,7 +15,7 @@ class SvnTest extends \Codeception\TestCase\Test protected function _before() { $this->container = Config::getContainer(); - $this->container->addServiceProvider(\Robo\Task\Vcs\ServiceProvider::class); + $this->container->addServiceProvider(\Robo\Task\Vcs\loadTasks::getVcsServices()); $this->svn = test::double('Robo\Task\Vcs\SvnStack', [ 'executeCommand' => new \AspectMock\Proxy\Anything(), From d141895b702d4419d9ce00cef1d5a1e8c306decf Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 16 Mar 2016 20:08:00 -0700 Subject: [PATCH 32/34] Fix a couple of style problems. --- RoboFile.php | 6 ++---- src/Common/TaskIO.php | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index 5362a4aae..5c5835ec7 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -373,8 +373,7 @@ public function tryTmpDir() if (is_dir($tmpPath)) { $this->say("Created a temporary directory at $tmpPath"); - } - else { + } else { $this->say("Requested a temporary directory at $tmpPath, but it was not created"); } @@ -383,8 +382,7 @@ public function tryTmpDir() if (is_dir($tmpPath)) { $this->say("The temporary directory at $tmpPath was not cleaned up after the collection completed."); - } - else { + } else { $this->say("The temporary directory at $tmpPath was automatically deleted."); } } diff --git a/src/Common/TaskIO.php b/src/Common/TaskIO.php index c2ef11bd5..6be7049dc 100644 --- a/src/Common/TaskIO.php +++ b/src/Common/TaskIO.php @@ -18,7 +18,7 @@ trait TaskIO { use LoggerAwareTrait; - static $gaveDeprecationWarning = false; + private static $gaveDeprecationWarning = false; public function logger() { From 699d3888a97dd45bb910fa751b92d0748838eb47 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Thu, 17 Mar 2016 09:08:43 -0700 Subject: [PATCH 33/34] Use AbstractSignatureServiceProvider in SimpleServiceProvider so that multiple providers may be registered. --- composer.json | 2 +- composer.lock | 22 ++++++++++++---------- src/Container/SimpleServiceProvider.php | 22 ++++++++++++---------- tests/cli/PackExtractCept.php | 3 +++ 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index 44fb1ddf1..a921a8a9c 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "symfony/console": "~2.5|~3.0", "symfony/process": "~2.5|~3.0", "symfony/filesystem": "~2.5|~3.0", - "league/container": "~2.1" + "league/container": "dev-master" }, "require-dev": { "patchwork/jsqueeze": "~1.0", diff --git a/composer.lock b/composer.lock index 83a67261c..75cf9dddf 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "15d62a29b192b8970d071cff5ce71350", - "content-hash": "37b5fc93d771c0b587e3413af833b2e3", + "hash": "9c54c76d0a06954f830009874e36f2ba", + "content-hash": "7d0df9389baa0ec268c11f86122c168e", "packages": [ { "name": "consolidation/log", @@ -87,16 +87,16 @@ }, { "name": "league/container", - "version": "2.1.0", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/thephpleague/container.git", - "reference": "bf916eb2023c4cc73724e945d264a4ae5eb4df38" + "reference": "c0e7d947b690891f700dc4967ead7bdb3d6708c1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/container/zipball/bf916eb2023c4cc73724e945d264a4ae5eb4df38", - "reference": "bf916eb2023c4cc73724e945d264a4ae5eb4df38", + "url": "https://api.github.com/repos/thephpleague/container/zipball/c0e7d947b690891f700dc4967ead7bdb3d6708c1", + "reference": "c0e7d947b690891f700dc4967ead7bdb3d6708c1", "shasum": "" }, "require": { @@ -115,8 +115,8 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1-dev", - "dev-1.x": "1.5-dev" + "dev-master": "2.x-dev", + "dev-1.x": "1.x-dev" } }, "autoload": { @@ -147,7 +147,7 @@ "provider", "service" ], - "time": "2016-03-15 08:17:43" + "time": "2016-03-17 11:07:59" }, { "name": "psr/log", @@ -2652,7 +2652,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "league/container": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Container/SimpleServiceProvider.php b/src/Container/SimpleServiceProvider.php index 7a2df42c8..f3f67b6dd 100644 --- a/src/Container/SimpleServiceProvider.php +++ b/src/Container/SimpleServiceProvider.php @@ -2,9 +2,7 @@ namespace Robo\Container; -use League\Container\ContainerAwareInterface; -use League\Container\ContainerAwareTrait; -use League\Container\ServiceProvider\ServiceProviderInterface; +use League\Container\ServiceProvider\AbstractSignatureServiceProvider; /** * This works like a League\Container\AbstractServiceProvider, except that @@ -12,20 +10,24 @@ * for each element is the service alias, and its corresponding value * is the name of the implementing service class. */ -class SimpleServiceProvider implements ServiceProviderInterface +class SimpleServiceProvider extends AbstractSignatureServiceProvider { - use ContainerAwareTrait; - - public function __construct($provides = []) - { - $this->provides += $provides; - } + /** + * @var string + */ + protected $signature; /** * @var array */ protected $provides = []; + public function __construct($provides = []) + { + $this->provides += $provides; + $this->signature = array_keys($provides)[0]; + } + /** * {@inheritdoc} */ diff --git a/tests/cli/PackExtractCept.php b/tests/cli/PackExtractCept.php index 691ed3719..20bfa7831 100644 --- a/tests/cli/PackExtractCept.php +++ b/tests/cli/PackExtractCept.php @@ -2,6 +2,9 @@ $I = new CliGuy($scenario); $I->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'); From cf079a1e6a34790ebf48ceffca7c21f2a372b886 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Thu, 17 Mar 2016 09:30:44 -0700 Subject: [PATCH 34/34] Use league/container 2.2 --- composer.json | 2 +- composer.lock | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index a921a8a9c..cdfaa91c6 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "symfony/console": "~2.5|~3.0", "symfony/process": "~2.5|~3.0", "symfony/filesystem": "~2.5|~3.0", - "league/container": "dev-master" + "league/container": "~2.2" }, "require-dev": { "patchwork/jsqueeze": "~1.0", diff --git a/composer.lock b/composer.lock index 75cf9dddf..8b5445a2c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "9c54c76d0a06954f830009874e36f2ba", - "content-hash": "7d0df9389baa0ec268c11f86122c168e", + "hash": "144b0cbc221523a48a63dab2017a27cf", + "content-hash": "607979e772abdfbc17aa7bff75f0b476", "packages": [ { "name": "consolidation/log", @@ -87,7 +87,7 @@ }, { "name": "league/container", - "version": "dev-master", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/thephpleague/container.git", @@ -2652,9 +2652,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "league/container": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": {