From 75cab1acb43b69eb19f394397ea2c4f687422796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Andor?= Date: Wed, 8 Dec 2021 18:28:05 +0100 Subject: [PATCH] Issue #1079 - Fix PHPCS problems --- RoboFile.php | 66 ++++++++++--- .../Robo/Plugin/Commands/ExampleCommands.php | 14 ++- phpcs.xml.dist | 48 +++++++++ src/Application.php | 26 ++++- .../RelativeNamespaceDiscovery.php | 2 +- src/Collection/Collection.php | 9 +- src/Collection/CollectionBuilder.php | 27 ++++-- src/Common/CommandReceiver.php | 5 +- src/Common/ProcessExecutor.php | 6 +- src/Common/TaskIO.php | 6 +- src/Log/RoboLogStyle.php | 13 ++- src/Result.php | 6 +- src/Robo.php | 39 ++++++-- src/Runner.php | 32 ++++-- src/Task/Archive/Extract.php | 11 ++- src/Task/Archive/Pack.php | 26 ++++- src/Task/Assets/ImageMinify.php | 48 +++++++-- src/Task/Base/ParallelExec.php | 24 ++++- src/Task/Base/Watch.php | 2 + src/Task/BaseTask.php | 9 +- src/Task/Composer/Base.php | 5 +- src/Task/Development/GenerateMarkdownDoc.php | 8 +- src/Task/Development/GenerateTask.php | 24 ++++- src/Task/Development/OpenBrowser.php | 4 +- src/Task/Development/SemVer.php | 2 + src/Task/File/Replace.php | 12 ++- src/Task/Filesystem/FilesystemStack.php | 7 +- src/Task/Filesystem/FlattenDir.php | 12 ++- src/Task/Filesystem/WorkDir.php | 8 +- src/Task/Gulp/Run.php | 8 +- src/Task/Simulator.php | 5 +- src/Task/StackBasedTask.php | 8 +- src/Task/Testing/Atoum.php | 5 +- src/Task/Testing/PHPUnit.php | 5 +- src/Task/Testing/Phpspec.php | 5 +- tests/_helpers/CliHelper.php | 6 +- tests/integration/AssetsTest.php | 12 ++- tests/integration/CleanDirTest.php | 1 - tests/integration/CollectionTest.php | 7 +- tests/integration/ConcatTest.php | 3 - tests/integration/CopyDirTest.php | 1 - tests/integration/DeleteDirTest.php | 1 - tests/integration/ExecTest.php | 18 ++-- tests/integration/FilesystemStackTest.php | 1 - tests/integration/FlattenDirTest.php | 1 - tests/integration/GenerateMarkdownDocTest.php | 1 - tests/integration/GenerateTaskTest.php | 6 +- tests/integration/PackExtractTest.php | 3 +- tests/integration/PackPharTest.php | 6 +- tests/integration/RunnerTest.php | 4 +- tests/integration/SimulatedTest.php | 3 - tests/integration/WriteFileTest.php | 2 - tests/phpunit/Common/CommandArgumentsTest.php | 3 +- tests/phpunit/Task/RsyncTest.php | 34 ++++++- tests/src/Fixtures.php | 5 +- tests/src/Task/CollectionTestTask.php | 1 - tests/unit/ApplicationTest.php | 27 ++++-- tests/unit/ConfigurationTest.php | 36 ++++--- tests/unit/ResultTest.php | 3 +- tests/unit/Task/ApiGenTest.php | 34 ++++++- tests/unit/Task/AtoumTest.php | 30 ++++-- tests/unit/Task/BehatTest.php | 22 ++++- tests/unit/Task/BowerTest.php | 9 +- tests/unit/Task/CodeceptionTest.php | 28 ++++-- tests/unit/Task/ComposerTest.php | 97 +++++++++++++++++-- tests/unit/Task/DockerTest.php | 73 ++++++++++++-- tests/unit/Task/ExecTaskTest.php | 8 +- tests/unit/Task/GitTest.php | 64 +++++++++++- tests/unit/Task/GulpTest.php | 28 ++++-- tests/unit/Task/HgTest.php | 34 ++++++- tests/unit/Task/NpmTest.php | 1 - tests/unit/Task/PHPServerTest.php | 7 +- tests/unit/Task/PHPUnitTest.php | 18 +++- tests/unit/Task/PhpspecTest.php | 20 +++- tests/unit/Task/SemVerTest.php | 21 ++-- tests/unit/Task/SvnTest.php | 26 ++++- 76 files changed, 1010 insertions(+), 232 deletions(-) create mode 100644 phpcs.xml.dist diff --git a/RoboFile.php b/RoboFile.php index e3245d22f..e2ea05c32 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -1,9 +1,10 @@ false, 'coverage' => false - ]) - { + ] + ) { $io->warning("Deprecated: use 'composer test' instead. Codeception-based tests will fail."); $collection = $this->collectionBuilder($io); @@ -37,7 +40,7 @@ public function test(ConsoleIO $io, array $args, $options = } return $collection; - } + } /** * Code sniffer. @@ -52,25 +55,63 @@ public function test(ConsoleIO $io, array $args, $options = */ public function sniff( ConsoleIO $io, - $file = 'src/', + $file = '', $options = [ 'autofix' => false, 'strict' => false, ] ) { - $strict = $options['strict'] ? '' : '-n'; - $result = $this->collectionBuilder($io)->taskExec("./vendor/bin/phpcs --standard=PSR2 {$strict} {$file}")->run(); + $command = $this->getPhpcsCommand($file, $options); + + $result = $this->collectionBuilder($io)->taskExec($command)->run(); if (!$result->wasSuccessful()) { if (!$options['autofix']) { $options['autofix'] = $this->confirm('Would you like to run phpcbf to fix the reported errors?'); } if ($options['autofix']) { - $result = $this->taskExec("./vendor/bin/phpcbf --standard=PSR2 {$file}")->run(); + $result = $this->taskExec($this->getPhpcbfCommand($file))->run(); } } return $result; } + /** + * @param string $file + * @param array $options + * + * @return string + */ + protected function getPhpcsCommand($file = '', array $options = []) + { + $options += [ + 'strict' => false, + ]; + + $cmdPattern = './vendor/bin/phpcs'; + $cmdArgs = []; + + if ($options['strict']) { + $cmdPattern .= ' -n'; + } + + if ($file !== '') { + $cmdPattern .= ' %s'; + $cmdArgs[] = escapeshellarg($file); + } + + return vsprintf($cmdPattern, $cmdArgs); + } + + /** + * @param string $file + * + * @return string + */ + protected function getPhpcbfCommand($file = '') + { + return './vendor/bin/phpcbf' . ($file !== '' ? ' ' . escapeshellarg($file) : ''); + } + /** * Generate a new Robo task that wraps an existing utility class. * @@ -95,8 +136,7 @@ public function release(ConsoleIO $io, $opts = ['beta' => false]) $stable = !$opts['beta']; if ($stable) { $version = preg_replace('/-.*/', '', $version); - } - else { + } else { $version = $this->incrementVersion($version, 'beta'); } $this->writeVersion($this->collectionBuilder($io), $version); diff --git a/examples/src/Robo/Plugin/Commands/ExampleCommands.php b/examples/src/Robo/Plugin/Commands/ExampleCommands.php index e56556d4e..8ab5a6a10 100644 --- a/examples/src/Robo/Plugin/Commands/ExampleCommands.php +++ b/examples/src/Robo/Plugin/Commands/ExampleCommands.php @@ -102,8 +102,14 @@ public function tryInput(ConsoleIO $io) * configuration via the configuration key command.try.config.options.opt. * @option show-all Also print out the value of all configuration options */ - public function tryConfig(ConsoleIO $io, $key = 'options.progress-delay', $options = ['opt' => '0', 'show-all' => false]) - { + public function tryConfig( + ConsoleIO $io, + $key = 'options.progress-delay', + $options = [ + 'opt' => '0', + 'show-all' => false + ] + ) { $value = \Robo\Robo::config()->get($key); $io->say("The value of $key is " . var_export($value, true)); @@ -373,10 +379,12 @@ public function tryFormatters($somthing = 'default', $options = ['format' => 'ta public function tryWrap() { $data = [ + // phpcs:disable Generic.Files.LineLength.TooLong [ 'first' => 'This is a really long cell that contains a lot of data. When it is rendered, it should be wrapped across multiple lines.', 'second' => 'This is the second column of the same table. It is also very long, and should be wrapped across multiple lines, just like the first column.', ] + // phpcs:enable Generic.Files.LineLength.TooLong ]; return new RowsOfFields($data); } @@ -557,7 +565,7 @@ public function tryProgress(ConsoleIO $io, $options = ['delay' => 500]) ->taskForEach($processList) ->iterationMessage('Processing {value}') ->call( - function ($value) use($delay) { + function ($value) use ($delay) { // TaskForEach::call should only be used to do // non-Robo operations. To use Robo tasks in an // iterator, @see TaskForEach::withBuilder. diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 000000000..0ce5b29af --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,48 @@ + + + + ./examples/ + ./src/ + ./tests/ + ./tests/_data/ + ./tests/_helpers/_generated/ + ./tests/_log/ + ./tests/_bootstrap.php + ./RoboFile.php + + + + + ./tests/ + + + ./src/Task/Base/Shortcuts.php + ./src/Task/Filesystem/FilesystemStack.php + ./src/Task/Filesystem/Shortcuts.php + ./src/Task/Logfile/Shortcuts.php + ./src/Task/Vcs/Shortcuts.php + + + + + ./tests/ + ./RoboFile.php + + + + ./examples/src/Robo/Plugin/Commands/ExampleCommands.php + ./tests/unit/ConfigurationTest.php + ./tests/unit/ResultTest.php + + + + ./tests/unit/ApplicationTest.php + + + + ./tests/unit/AAA_RunnerErrorTest.php + + diff --git a/src/Application.php b/src/Application.php index 867776eed..f1adf5018 100644 --- a/src/Application.php +++ b/src/Application.php @@ -21,16 +21,33 @@ public function __construct($name, $version) $this->getDefinition() ->addOption( - new InputOption('--simulate', null, InputOption::VALUE_NONE, 'Run in simulated mode (show what would have happened).') + new InputOption( + '--simulate', + null, + InputOption::VALUE_NONE, + 'Run in simulated mode (show what would have happened).' + ) ); $this->getDefinition() ->addOption( - new InputOption('--progress-delay', null, InputOption::VALUE_REQUIRED, 'Number of seconds before progress bar is displayed in long-running task collections. Default: 2s.', Config::DEFAULT_PROGRESS_DELAY) + new InputOption( + '--progress-delay', + null, + InputOption::VALUE_REQUIRED, + 'Number of seconds before progress bar is displayed in long-running task collections. Default: 2s.', + Config::DEFAULT_PROGRESS_DELAY + ) ); $this->getDefinition() ->addOption( - new InputOption('--define', '-D', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Define a configuration item value.', []) + new InputOption( + '--define', + '-D', + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'Define a configuration item value.', + [] + ) ); } @@ -43,8 +60,9 @@ public function addInitRoboFileCommand($roboFile, $roboClass) $createRoboFile = new Command('init'); $createRoboFile->setDescription("Intitalizes basic RoboFile in current dir"); $createRoboFile->setCode(function (InputInterface $input, OutputInterface $output) use ($roboClass, $roboFile) { + $roboFileBaseName = basename($roboFile); $output->writeln(" ~~~ Welcome to Robo! ~~~~ "); - $output->writeln(" " . basename($roboFile) . " will be created in the current directory "); + $output->writeln(" $roboFileBaseName will be created in the current directory "); file_put_contents( $roboFile, 'search($directories, $this->searchPattern) as $file) { $relativePathName = $file->getRelativePathname(); - $classes[] = $baseNamespace . $this->convertPathToNamespace($relativePath . '/' . $relativePathName); + $classes[] = $baseNamespace . $this->convertPathToNamespace("$relativePath/$relativePathName"); } } } diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php index 339899205..4ffb683a9 100644 --- a/src/Collection/Collection.php +++ b/src/Collection/Collection.php @@ -505,7 +505,10 @@ public function getCommand() return $task->getCommand(); } - throw new TaskException($task, get_class($task) . " does not implement CommandInterface, so can't be used to provide a command"); + throw new TaskException( + $task, + get_class($task) . " does not implement CommandInterface, so can't be used to provide a command" + ); } /** @@ -648,9 +651,13 @@ protected function runRollbackTasks() } /** + * phpcs:disable Generic.Files.LineLength.TooLong + * * @param \Robo\Contract\TaskInterface|\Robo\Collection\NestedCollectionInterface|\Robo\Contract\WrappedTaskInterface $task * * @return \Robo\Result + * + * phpcs:enable Generic.Files.LineLength.TooLongs */ protected function runSubtask($task) { diff --git a/src/Collection/CollectionBuilder.php b/src/Collection/CollectionBuilder.php index d805393f1..e217dcd3b 100644 --- a/src/Collection/CollectionBuilder.php +++ b/src/Collection/CollectionBuilder.php @@ -48,7 +48,12 @@ * In the example above, the `taskDeleteDir` will be called if * ``` */ -class CollectionBuilder extends BaseTask implements NestedCollectionInterface, WrappedTaskInterface, CommandInterface, StateAwareInterface, InputAwareInterface +class CollectionBuilder extends BaseTask implements + NestedCollectionInterface, + WrappedTaskInterface, + CommandInterface, + StateAwareInterface, + InputAwareInterface { use StateAwareTrait; use InputAwareTrait; // BaseTask has OutputAwareTrait @@ -339,7 +344,9 @@ public function defer($callback) */ protected function callCollectionStateFunction($functionName, $args) { - $currentTask = ($this->currentTask instanceof WrappedTaskInterface) ? $this->currentTask->original() : $this->currentTask; + $currentTask = $this->currentTask instanceof WrappedTaskInterface ? + $this->currentTask->original() + : $this->currentTask; array_unshift($args, $currentTask); $collection = $this->getCollection(); @@ -369,7 +376,9 @@ protected function callCollectionStateFuntion($functionName, $args) */ public function setVerbosityThreshold($verbosityThreshold) { - $currentTask = ($this->currentTask instanceof WrappedTaskInterface) ? $this->currentTask->original() : $this->currentTask; + $currentTask = $this->currentTask instanceof WrappedTaskInterface ? + $this->currentTask->original() + : $this->currentTask; if ($currentTask) { $currentTask->setVerbosityThreshold($verbosityThreshold); return $this; @@ -455,7 +464,9 @@ public function __call($fn, $args) $temporaryBuilder = $this->commandFile->getBuiltTask($fn, $args); $this->commandFile->setBuilder($saveBuilder); if (!$temporaryBuilder) { - throw new \BadMethodCallException("No such method $fn: task does not exist in " . get_class($this->commandFile)); + throw new \BadMethodCallException( + "No such method $fn: task does not exist in " . get_class($this->commandFile) + ); } $temporaryBuilder->getCollection()->transferTasks($this); return $this; @@ -468,7 +479,9 @@ public function __call($fn, $args) $result = call_user_func_array([$this->currentTask, $fn], $args); // If something other than a setter method is called, then return its result. - $currentTask = ($this->currentTask instanceof WrappedTaskInterface) ? $this->currentTask->original() : $this->currentTask; + $currentTask = $this->currentTask instanceof WrappedTaskInterface ? + $this->currentTask->original() + : $this->currentTask; if (isset($result) && ($result !== $currentTask)) { return $result; } @@ -644,7 +657,9 @@ public function getCollection() $this->collection = new Collection(); $this->collection->inflect($this); $this->collection->setState($this->getState()); - $this->collection->setProgressBarAutoDisplayInterval($this->getConfig()->get(Config::PROGRESS_BAR_AUTO_DISPLAY_INTERVAL)); + $this->collection->setProgressBarAutoDisplayInterval( + $this->getConfig()->get(Config::PROGRESS_BAR_AUTO_DISPLAY_INTERVAL) + ); if (isset($this->currentTask)) { $this->collection->add($this->currentTask); diff --git a/src/Common/CommandReceiver.php b/src/Common/CommandReceiver.php index 091aa6c5c..133d41311 100644 --- a/src/Common/CommandReceiver.php +++ b/src/Common/CommandReceiver.php @@ -25,7 +25,10 @@ protected function receiveCommand($command) if ($command instanceof CommandInterface) { return $command->getCommand(); } else { - throw new TaskException($this, get_class($command) . " does not implement CommandInterface, so can't be passed into this task"); + throw new TaskException( + $this, + get_class($command) . " does not implement CommandInterface, so can't be passed into this task" + ); } } } diff --git a/src/Common/ProcessExecutor.php b/src/Common/ProcessExecutor.php index 849efb916..27590e358 100644 --- a/src/Common/ProcessExecutor.php +++ b/src/Common/ProcessExecutor.php @@ -8,7 +8,11 @@ use Robo\Contract\VerbosityThresholdInterface; use Symfony\Component\Process\Process; -class ProcessExecutor implements ConfigAwareInterface, LoggerAwareInterface, OutputAwareInterface, VerbosityThresholdInterface +class ProcessExecutor implements + ConfigAwareInterface, + LoggerAwareInterface, + OutputAwareInterface, + VerbosityThresholdInterface { use ExecTrait; use TaskIO; // uses LoggerAwareTrait and ConfigAwareTrait diff --git a/src/Common/TaskIO.php b/src/Common/TaskIO.php index 4664520cb..2e1a5576b 100644 --- a/src/Common/TaskIO.php +++ b/src/Common/TaskIO.php @@ -67,7 +67,11 @@ public function logger() static $gaveDeprecationWarning = false; if (!$gaveDeprecationWarning) { - trigger_error('No logger set for ' . get_class($this) . '. Use $this->task(Foo::class) rather than new Foo() in Tasks to ensure the builder can initialize task the task, or use $this->collectionBuilder()->taskFoo() if creating one task from within another.', E_USER_DEPRECATED); + trigger_error( + // phpcs:ignore + 'No logger set for ' . get_class($this) . '. Use $this->task(Foo::class) rather than new Foo() in Tasks to ensure the builder can initialize task the task, or use $this->collectionBuilder()->taskFoo() if creating one task from within another.', + E_USER_DEPRECATED + ); $gaveDeprecationWarning = true; } return Robo::logger(); diff --git a/src/Log/RoboLogStyle.php b/src/Log/RoboLogStyle.php index 2c1b71ee8..7b6ffdda0 100644 --- a/src/Log/RoboLogStyle.php +++ b/src/Log/RoboLogStyle.php @@ -46,7 +46,13 @@ protected function formatMessageByLevel($level, $message, $context) if (array_key_exists('name', $context)) { $label = $context['name']; } - return $this->formatMessage($label, $message, $context, $this->labelStyles[$level], $this->messageStyles[$level]); + return $this->formatMessage( + $label, + $message, + $context, + $this->labelStyles[$level], + $this->messageStyles[$level] + ); } /** @@ -65,7 +71,10 @@ protected function formatMessage($label, $message, $context, $taskNameStyle, $me { $message = parent::formatMessage($label, $message, $context, $taskNameStyle, $messageStyle); - if (array_key_exists('time', $context) && !empty($context['time']) && array_key_exists('timer-label', $context)) { + if (array_key_exists('time', $context) + && !empty($context['time']) + && array_key_exists('timer-label', $context) + ) { $duration = TimeKeeper::formatDuration($context['time']); $message .= ' ' . $context['timer-label'] . ' ' . $this->wrapFormatString($duration, 'fg=yellow'); } diff --git a/src/Result.php b/src/Result.php index 6c9ea7812..6393c4585 100644 --- a/src/Result.php +++ b/src/Result.php @@ -70,7 +70,11 @@ public static function ensureResult($task, $result) if (is_array($result)) { return static::success($task, '', $result); } - throw new \Exception(sprintf('Task %s returned a %s instead of a \Robo\Result.', get_class($task), get_class($result))); + throw new \Exception(sprintf( + 'Task %s returned a %s instead of a \Robo\Result.', + get_class($task), + get_class($result) + )); } protected function printResult() diff --git a/src/Robo.php b/src/Robo.php index d8ae97d9b..f25ac6b43 100644 --- a/src/Robo.php +++ b/src/Robo.php @@ -3,9 +3,12 @@ namespace Robo; use Composer\Autoload\ClassLoader; +use Consolidation\AnnotatedCommand\Options\AlterOptionsCommandEvent; +use Consolidation\AnnotatedCommand\Options\PrepareTerminalWidthOption; use League\Container\Container; use League\Container\Definition\DefinitionInterface; use Psr\Container\ContainerInterface; +use Robo\ClassDiscovery\RelativeNamespaceDiscovery; use Robo\Common\ProcessExecutor; use Consolidation\Config\ConfigInterface; use Consolidation\Config\Loader\ConfigProcessor; @@ -43,8 +46,14 @@ class Robo * * @return int */ - public static function run($argv, $commandClasses, $appName = null, $appVersion = null, $output = null, $repository = null) - { + public static function run( + $argv, + $commandClasses, + $appName = null, + $appVersion = null, + $output = null, + $repository = null + ) { $runner = new \Robo\Runner($commandClasses); $runner->setSelfUpdateRepository($repository); $statusCode = $runner->execute($argv, $appName, $appVersion, $output); @@ -80,6 +89,7 @@ public static function unsetContainer() public static function getContainer() { if (static::$container === null) { + // phpcs:ignore throw new \RuntimeException('container is not initialized yet. \Robo\Robo::setContainer() must be called with a real container.'); } return static::$container; @@ -183,8 +193,13 @@ public static function createContainer($app = null, $config = null, $classLoader * * @return \Psr\Container\ContainerInterface */ - public static function createDefaultContainer($input = null, $output = null, $app = null, $config = null, $classLoader = null) - { + public static function createDefaultContainer( + $input = null, + $output = null, + $app = null, + $config = null, + $classLoader = null + ) { // Do not allow this function to be called more than once. if (static::hasContainer()) { return static::getContainer(); @@ -254,8 +269,14 @@ public static function addShared(ContainerInterface $container, string $id, $con * @param null|\Symfony\Component\Console\Output\OutputInterface $output * @param null|\Composer\Autoload\ClassLoader $classLoader */ - public static function configureContainer(ContainerInterface $container, SymfonyApplication $app, ConfigInterface $config, $input = null, $output = null, $classLoader = null) - { + public static function configureContainer( + ContainerInterface $container, + SymfonyApplication $app, + ConfigInterface $config, + $input = null, + $output = null, + $classLoader = null + ) { // Self-referential container refernce for the inflector $container->add('container', $container); static::setContainer($container); @@ -304,7 +325,7 @@ public static function configureContainer(ContainerInterface $container, Symfony ->addArgument('config') ->addMethodCall('setApplication', ['application']); self::addShared($container, 'collectionProcessHook', \Robo\Collection\CollectionProcessHook::class); - self::addShared($container, 'alterOptionsCommandEvent', \Consolidation\AnnotatedCommand\Options\AlterOptionsCommandEvent::class) + self::addShared($container, 'alterOptionsCommandEvent', AlterOptionsCommandEvent::class) ->addArgument('application'); self::addShared($container, 'hookManager', \Consolidation\AnnotatedCommand\Hooks\HookManager::class) ->addMethodCall('addCommandEvent', ['alterOptionsCommandEvent']) @@ -316,7 +337,7 @@ public static function configureContainer(ContainerInterface $container, Symfony self::addShared($container, 'formatterManager', \Consolidation\OutputFormatters\FormatterManager::class) ->addMethodCall('addDefaultFormatters', []) ->addMethodCall('addDefaultSimplifiers', []); - self::addShared($container, 'prepareTerminalWidthOption', \Consolidation\AnnotatedCommand\Options\PrepareTerminalWidthOption::class) + self::addShared($container, 'prepareTerminalWidthOption', PrepareTerminalWidthOption::class) ->addMethodCall('setApplication', ['application']); self::addShared($container, 'symfonyStyleInjector', \Robo\Symfony\SymfonyStyleInjector::class); self::addShared($container, 'consoleIOInjector', \Robo\Symfony\ConsoleIOInjector::class); @@ -343,7 +364,7 @@ function ($output, $message) use ($container) { // Public methods from the class Robo\Commo\IO that should not be // added as available commands. ->addMethodCall('addIgnoredCommandsRegexp', ['/^currentState$|^restoreState$/']); - self::addShared($container, 'relativeNamespaceDiscovery', \Robo\ClassDiscovery\RelativeNamespaceDiscovery::class) + self::addShared($container, 'relativeNamespaceDiscovery', RelativeNamespaceDiscovery::class) ->addArgument('classLoader'); // Deprecated: favor using collection builders to direct use of collections. diff --git a/src/Runner.php b/src/Runner.php index d8803ebeb..6e1330707 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -117,7 +117,10 @@ protected function loadRoboFile($output) return true; } if (!file_exists($this->dir)) { - $this->errorCondition("Path `{$this->dir}` is invalid; please provide a valid absolute path to the Robofile to load.", 'red'); + $this->errorCondition( + "Path `{$this->dir}` is invalid; please provide a valid absolute path to the Robofile to load.", + 'red' + ); return false; } @@ -126,7 +129,11 @@ protected function loadRoboFile($output) $roboFilePath = $realDir . DIRECTORY_SEPARATOR . $this->roboFile; if (!file_exists($roboFilePath)) { $requestedRoboFilePath = $this->dir . DIRECTORY_SEPARATOR . $this->roboFile; - $this->errorCondition("Requested RoboFile `$requestedRoboFilePath` is invalid, please provide valid absolute path to load Robofile.", 'red'); + $this->errorCondition( + // phpcs:ignore + "Requested RoboFile `$requestedRoboFilePath` is invalid, please provide valid absolute path to load Robofile.", + 'red' + ); return false; } require_once $roboFilePath; @@ -181,8 +188,13 @@ public function execute($argv, $appName = null, $appVersion = null, $output = nu * @return \Robo\Application * Initialized application based on passed configuration and command classes. */ - public function getAppForTesting($appName = null, $appVersion = null, $commandFile = null, $config = null, $classLoader = null) - { + public function getAppForTesting( + $appName = null, + $appVersion = null, + $commandFile = null, + $config = null, + $classLoader = null + ) { $app = Robo::createDefaultApplication($appName, $appVersion); $output = new NullOutput(); $container = Robo::createDefaultContainer(null, $output, $app, $config, $classLoader); @@ -265,7 +277,10 @@ public function run($input = null, $output = null, $app = null, $commandFiles = if ($app instanceof \Robo\Application) { $app->addSelfUpdateCommand($this->getSelfUpdateRepository()); if (!isset($commandFiles)) { - $this->errorCondition("Robo is not initialized here. Please run `robo init` to create a new RoboFile.", 'yellow'); + $this->errorCondition( + "Robo is not initialized here. Please run `robo init` to create a new RoboFile.", + 'yellow' + ); $app->addInitRoboFileCommand($this->roboFile, $this->roboClass); $commandFiles = []; } @@ -558,7 +573,12 @@ public function shutdown() if (!is_array($error)) { return; } - $this->writeln(sprintf("ERROR: %s \nin %s:%d\n", $error['message'], $error['file'], $error['line'])); + $this->writeln(sprintf( + "ERROR: %s \nin %s:%d\n", + $error['message'], + $error['file'], + $error['line'] + )); } /** diff --git a/src/Task/Archive/Extract.php b/src/Task/Archive/Extract.php index e99a0fcd6..30350aac3 100644 --- a/src/Task/Archive/Extract.php +++ b/src/Task/Archive/Extract.php @@ -88,13 +88,16 @@ public function preserveTopDirectory($preserve = true) */ public function run() { + $messageArgs = [ + 'filename' => $this->filename, + ]; if (!file_exists($this->filename)) { - $this->printTaskError("File {filename} does not exist", ['filename' => $this->filename]); + $this->printTaskError("File {filename} does not exist", $messageArgs); return false; } if (!($mimetype = static::archiveType($this->filename))) { - $this->printTaskError("Could not determine type of archive for {filename}", ['filename' => $this->filename]); + $this->printTaskError("Could not determine type of archive for {filename}", $messageArgs); return false; } @@ -112,11 +115,11 @@ public function run() $this->startTimer(); - $this->printTaskInfo("Extracting {filename}", ['filename' => $this->filename]); + $this->printTaskInfo("Extracting {filename}", $messageArgs); $result = $this->extractAppropriateType($mimetype, $extractLocation); if ($result->wasSuccessful()) { - $this->printTaskInfo("{filename} extracted", ['filename' => $this->filename]); + $this->printTaskInfo("{filename} extracted", $messageArgs); // Now, we want to move the extracted files to $this->to. There // are two possibilities that we must consider: // diff --git a/src/Task/Archive/Pack.php b/src/Task/Archive/Pack.php index a398a31ff..ca489e04a 100644 --- a/src/Task/Archive/Pack.php +++ b/src/Task/Archive/Pack.php @@ -171,7 +171,10 @@ public function run() $fileInfo = new \SplFileInfo($this->archiveFile); $extension = strtolower($fileInfo->getExtension()); if (empty($extension)) { - return Result::error($this, "Archive filename must use an extension (e.g. '.zip') to specify the kind of archive to create."); + return Result::error( + $this, + "Archive filename must use an extension (e.g. '.zip') to specify the kind of archive to create." + ); } try { @@ -184,7 +187,14 @@ public function run() } $this->printTaskSuccess("{filename} created.", ['filename' => $this->archiveFile]); } catch (\Exception $e) { - $this->printTaskError("Could not create {filename}. {exception}", ['filename' => $this->archiveFile, 'exception' => $e->getMessage(), '_style' => ['exception' => '']]); + $this->printTaskError( + "Could not create {filename}. {exception}", + [ + 'filename' => $this->archiveFile, + 'exception' => $e->getMessage(), + '_style' => ['exception' => ''], + ] + ); $result = Result::error($this, sprintf('Could not create %s. %s', $this->archiveFile, $e->getMessage())); } $this->stopTimer(); @@ -217,7 +227,11 @@ protected function archiveTar($archiveFile, $items) $p_remove_dir = dirname($filesystemLocation); $p_add_dir = dirname($placementLocation); if (basename($filesystemLocation) != basename($placementLocation)) { - return Result::error($this, "Tar archiver does not support renaming files during extraction; could not add $filesystemLocation as $placementLocation."); + return Result::error( + $this, + // phpcs:ignore + "Tar archiver does not support renaming files during extraction; could not add $filesystemLocation as $placementLocation." + ); } } @@ -274,7 +288,11 @@ protected function addItemsToZip($zip, $items) $relativePathname = str_replace('\\', '/', $file->getRelativePathname()); if (!$zip->addFile($file->getRealpath(), "{$placementLocation}/{$relativePathname}")) { - return Result::error($this, "Could not add directory $filesystemLocation to the archive; error adding {$file->getRealpath()}."); + return Result::error( + $this, + // phpcs:ignore + "Could not add directory $filesystemLocation to the archive; error adding {$file->getRealpath()}." + ); } } } elseif (is_file($filesystemLocation)) { diff --git a/src/Task/Assets/ImageMinify.php b/src/Task/Assets/ImageMinify.php index 5d62d4983..be7181521 100644 --- a/src/Task/Assets/ImageMinify.php +++ b/src/Task/Assets/ImageMinify.php @@ -176,10 +176,12 @@ class ImageMinify extends BaseTask // JPG 'jpegtran' => 'https://github.com/imagemin/jpegtran-bin', 'jpegoptim' => 'https://github.com/imagemin/jpegoptim-bin', - 'cjpeg' => 'https://github.com/imagemin/mozjpeg-bin', // note: we do not support this minifier because it creates JPG from non-JPG files + // note: we do not support this minifier because it creates JPG from non-JPG files + 'cjpeg' => 'https://github.com/imagemin/mozjpeg-bin', 'jpeg-recompress' => 'https://github.com/imagemin/jpeg-recompress-bin', // WebP - 'cwebp' => 'https://github.com/imagemin/cwebp-bin', // note: we do not support this minifier because it creates WebP from non-WebP files + // note: we do not support this minifier because it creates WebP from non-WebP files + 'cwebp' => 'https://github.com/imagemin/cwebp-bin', ]; /** @@ -217,7 +219,11 @@ public function run() $amount = (count($files) == 1 ? 'image' : 'images'); $message = "Minified {filecount} out of {filetotal} $amount into {destination}"; - $context = ['filecount' => count($this->results['success']), 'filetotal' => count($files), 'destination' => $this->to]; + $context = [ + 'filecount' => count($this->results['success']), + 'filetotal' => count($files), + 'destination' => $this->to, + ]; if (count($this->results['success']) == count($files)) { $this->printTaskSuccess($message, $context); @@ -333,7 +339,13 @@ protected function findFiles($dirs) $files[$file->getRealpath()] = $this->getTarget($file->getRealPath(), $to); } $fileNoun = count($finder) == 1 ? ' file' : ' files'; - $this->printTaskInfo("Found {filecount} $fileNoun in {dir}", ['filecount' => count($finder), 'dir' => $dir]); + $this->printTaskInfo( + "Found {filecount} $fileNoun in {dir}", + [ + 'filecount' => count($finder), + 'dir' => $dir, + ] + ); } return $files; @@ -415,7 +427,13 @@ protected function minify($files) } // launch the command - $this->printTaskInfo('Minifying {filepath} with {minifier}', ['filepath' => $from, 'minifier' => $minifier]); + $this->printTaskInfo( + 'Minifying {filepath} with {minifier}', + [ + 'filepath' => $from, + 'minifier' => $minifier, + ] + ); $result = $this->executeCommand($command); // check the return code @@ -434,7 +452,13 @@ protected function minify($files) $command = $this->{$minifier}($from, $to); } // launch the command - $this->printTaskInfo('Minifying {filepath} with {minifier}', ['filepath' => $from, 'minifier' => $minifier]); + $this->printTaskInfo( + 'Minifying {filepath} with {minifier}', + [ + 'filepath' => $from, + 'minifier' => $minifier, + ] + ); $result = $this->executeCommand($command); } else { $this->printTaskError($result->getMessage()); @@ -519,7 +543,12 @@ protected function installFromImagemin($executable) return Result::error($this, $message); } - $this->printTaskInfo('Downloading the {executable} executable from the imagemin repository', ['executable' => $executable]); + $this->printTaskInfo( + 'Downloading the {executable} executable from the imagemin repository', + [ + 'executable' => $executable, + ] + ); $os = $this->getOS(); $url = $this->imageminRepos[$executable] . '/blob/main/vendor/' . $os . '/' . $executable . '?raw=true'; @@ -558,7 +587,10 @@ protected function installFromImagemin($executable) if (!is_dir($this->executableTargetDir)) { // create and check access rights (directory created, but not readable) if (!mkdir($this->executableTargetDir) && !is_dir($this->executableTargetDir)) { - $message = sprintf('Can not create target directory for executables in %s', $this->executableTargetDir); + $message = sprintf( + 'Can not create target directory for executables in %s', + $this->executableTargetDir + ); return Result::error($this, $message); } diff --git a/src/Task/Base/ParallelExec.php b/src/Task/Base/ParallelExec.php index 4930915b2..6a2f2cee2 100644 --- a/src/Task/Base/ParallelExec.php +++ b/src/Task/Base/ParallelExec.php @@ -174,12 +174,25 @@ public function run() try { $process->checkTimeout(); } catch (ProcessTimedOutException $e) { - $this->printTaskWarning("Process timed out for {command}", ['command' => $process->getCommandLine(), '_style' => ['command' => 'fg=white;bg=magenta']]); + $this->printTaskWarning( + "Process timed out for {command}", + [ + 'command' => $process->getCommandLine(), + '_style' => ['command' => 'fg=white;bg=magenta'], + ] + ); } if (!$process->isRunning()) { $this->advanceProgressIndicator(); if ($this->isPrinted) { - $this->printTaskInfo("Output for {command}:\n\n{output}", ['command' => $process->getCommandLine(), 'output' => $process->getOutput(), '_style' => ['command' => 'fg=white;bg=magenta']]); + $this->printTaskInfo( + "Output for {command}:\n\n{output}", + [ + 'command' => $process->getCommandLine(), + 'output' => $process->getOutput(), + '_style' => ['command' => 'fg=white;bg=magenta'], + ] + ); $errorOutput = $process->getErrorOutput(); if ($errorOutput) { $this->printTaskError(rtrim($errorOutput)); @@ -205,7 +218,12 @@ public function run() $exitCode = max($exitCode, $p->getExitCode()); } if (!$errorMessage) { - $this->printTaskSuccess('{process-count} processes finished running', ['process-count' => count($this->processes)]); + $this->printTaskSuccess( + '{process-count} processes finished running', + [ + 'process-count' => count($this->processes), + ] + ); } return new Result($this, $exitCode, $errorMessage, ['time' => $this->getExecutionTime()]); diff --git a/src/Task/Base/Watch.php b/src/Task/Base/Watch.php index 6eeca6b47..07fe61bce 100644 --- a/src/Task/Base/Watch.php +++ b/src/Task/Base/Watch.php @@ -6,6 +6,7 @@ use Robo\Result; use Robo\Task\BaseTask; +// phpcs:disable Generic.Files.LineLength.TooLong /** * Runs task when specified file or dir was changed. * Uses Lurker library. @@ -59,6 +60,7 @@ */ class Watch extends BaseTask { + // phpcs:enable Generic.Files.LineLength.TooLong /** * @var \Closure */ diff --git a/src/Task/BaseTask.php b/src/Task/BaseTask.php index ec380e402..e81a6be62 100644 --- a/src/Task/BaseTask.php +++ b/src/Task/BaseTask.php @@ -13,7 +13,14 @@ use Psr\Log\LoggerAwareInterface; use Robo\Contract\OutputAwareInterface; -abstract class BaseTask implements TaskInterface, LoggerAwareInterface, VerbosityThresholdInterface, ConfigAwareInterface, ProgressIndicatorAwareInterface, InflectionInterface, OutputAwareInterface +abstract class BaseTask implements + TaskInterface, + LoggerAwareInterface, + VerbosityThresholdInterface, + ConfigAwareInterface, + ProgressIndicatorAwareInterface, + InflectionInterface, + OutputAwareInterface { use TaskIO; // uses LoggerAwareTrait, OutputAwareTrait, VerbosityThresholdTrait and ConfigAwareTrait use ProgressIndicatorAwareTrait; diff --git a/src/Task/Composer/Base.php b/src/Task/Composer/Base.php index ba50c0cb3..118d00b9a 100644 --- a/src/Task/Composer/Base.php +++ b/src/Task/Composer/Base.php @@ -60,7 +60,10 @@ public function __construct($pathToComposer = null) $this->command = $this->findExecutablePhar('composer'); } if (!$this->command) { - throw new TaskException(__CLASS__, "Neither local composer.phar nor global composer installation could be found."); + throw new TaskException( + __CLASS__, + "Neither local composer.phar nor global composer installation could be found." + ); } } diff --git a/src/Task/Development/GenerateMarkdownDoc.php b/src/Task/Development/GenerateMarkdownDoc.php index 01487eead..f5d8e86a7 100644 --- a/src/Task/Development/GenerateMarkdownDoc.php +++ b/src/Task/Development/GenerateMarkdownDoc.php @@ -458,7 +458,13 @@ public function run() ->line($this->append) ->run(); - $this->printTaskSuccess('{filename} created. {class-count} classes documented', ['filename' => $this->filename, 'class-count' => count($this->docClass)]); + $this->printTaskSuccess( + '{filename} created. {class-count} classes documented', + [ + 'filename' => $this->filename, + 'class-count' => count($this->docClass), + ] + ); return new Result($this, $result->getExitCode(), $result->getMessage(), $this->textForClass); } diff --git a/src/Task/Development/GenerateTask.php b/src/Task/Development/GenerateTask.php index 2ea5ca01a..3c90b5172 100644 --- a/src/Task/Development/GenerateTask.php +++ b/src/Task/Development/GenerateTask.php @@ -59,7 +59,7 @@ public function run() $argDescription = '$' . $arg->name; $argNameList[] = $argDescription; if ($arg->isOptional()) { - $argDescription = $argDescription . ' = ' . str_replace("\n", "", var_export($arg->getDefaultValue(), true)); + $argDescription .= ' = ' . str_replace("\n", "", var_export($arg->getDefaultValue(), true)); // We will create wrapper methods for any method that // has default parameters. $needsImplementation = true; @@ -73,12 +73,28 @@ public function run() $methodDescriptions[] = "@method $methodName($argPrototypeString)"; if ($getter) { - $immediateMethods[] = " public function $methodName($argPrototypeString)\n {\n return \$this->delegate->$methodName($argNameListString);\n }"; + $immediateMethods[] = implode("\n", [ + " public function $methodName($argPrototypeString)", + ' {', + " return \$this->delegate->$methodName($argNameListString);", + ' }', + ]); } elseif ($setter) { - $immediateMethods[] = " public function $methodName($argPrototypeString)\n {\n \$this->delegate->$methodName($argNameListString);\n return \$this;\n }"; + $immediateMethods[] = implode("\n", [ + " public function $methodName($argPrototypeString)", + ' {', + " \$this->delegate->$methodName($argNameListString);", + " return \$this;", + ' }', + ]); } elseif ($needsImplementation) { // Include an implementation for the wrapper method if necessary - $methodImplementations[] = " protected function _$methodName($argPrototypeString)\n {\n \$this->delegate->$methodName($argNameListString);\n }"; + $methodImplementations[] = implode("\n", [ + " protected function _$methodName($argPrototypeString)", + ' {', + " \$this->delegate->$methodName($argNameListString);", + ' }', + ]); } } } diff --git a/src/Task/Development/OpenBrowser.php b/src/Task/Development/OpenBrowser.php index ac3840bad..eadb48e15 100644 --- a/src/Task/Development/OpenBrowser.php +++ b/src/Task/Development/OpenBrowser.php @@ -7,8 +7,8 @@ use Robo\Result; /** - * Opens the default's user browser - * code inspired from openBrowser() function in https://github.com/composer/composer/blob/master/src/Composer/Command/HomeCommand.php + * Opens the default's user browser code inspired from openBrowser() function in + * https://github.com/composer/composer/blob/master/src/Composer/Command/HomeCommand.php * * ``` php * [0-9]+)\.(?[0-9]+)\.(?[0-9]+)(|-(?[0-9a-zA-Z.]+))(|\+(?[0-9a-zA-Z.]+))$/'; /** diff --git a/src/Task/File/Replace.php b/src/Task/File/Replace.php index e3f222862..b6b9d3590 100644 --- a/src/Task/File/Replace.php +++ b/src/Task/File/Replace.php @@ -145,14 +145,20 @@ public function run() } else { $text = str_replace($this->from, $this->to, $text, $count); } + + $messageArgs = [ + 'filename' => $this->filename, + 'count' => $count, + ]; + if ($count > 0) { $res = file_put_contents($this->filename, $text); if ($res === false) { - return Result::error($this, "Error writing to file {filename}.", ['filename' => $this->filename]); + return Result::error($this, "Error writing to file {filename}.", $messageArgs); } - $this->printTaskSuccess("{filename} updated. {count} items replaced", ['filename' => $this->filename, 'count' => $count]); + $this->printTaskSuccess("{filename} updated. {count} items replaced", $messageArgs); } else { - $this->printTaskInfo("{filename} unchanged. {count} items replaced", ['filename' => $this->filename, 'count' => $count]); + $this->printTaskInfo("{filename} unchanged. {count} items replaced", $messageArgs); } return Result::success($this, '', ['replaced' => $count]); } diff --git a/src/Task/Filesystem/FilesystemStack.php b/src/Task/Filesystem/FilesystemStack.php index adc7e8aac..2bb19e61a 100644 --- a/src/Task/Filesystem/FilesystemStack.php +++ b/src/Task/Filesystem/FilesystemStack.php @@ -113,7 +113,12 @@ protected function _rename($origin, $target, $overwrite = false) { // we check that target does not exist if ((!$overwrite && is_readable($target)) || (file_exists($target) && !is_writable($target))) { - throw new IOException(sprintf('Cannot rename because the target "%s" already exists.', $target), 0, null, $target); + throw new IOException( + sprintf('Cannot rename because the target "%s" already exists.', $target), + 0, + null, + $target + ); } // Due to a bug (limitation) in PHP, cross-volume renames do not work. diff --git a/src/Task/Filesystem/FlattenDir.php b/src/Task/Filesystem/FlattenDir.php index 7fa486b32..669d4f4aa 100644 --- a/src/Task/Filesystem/FlattenDir.php +++ b/src/Task/Filesystem/FlattenDir.php @@ -109,7 +109,13 @@ public function run() $this->copyFiles($files); $fileNoun = count($files) == 1 ? ' file' : ' files'; - $this->printTaskSuccess("Copied {count} $fileNoun to {destination}", ['count' => count($files), 'destination' => $this->to]); + $this->printTaskSuccess( + "Copied {count} $fileNoun to {destination}", + [ + 'count' => count($files), + 'destination' => $this->to, + ] + ); return Result::success($this); } @@ -269,7 +275,9 @@ protected function getTarget($file, $to) $parts = explode('/', rtrim($rel_path, '/')); $prefix_dir = ''; $prefix_dir .= ($this->parents[0] > 0 ? implode('/', array_slice($parts, 0, $this->parents[0])) . '/' : ''); - $prefix_dir .= ($this->parents[1] > 0 ? implode('/', array_slice($parts, (0 - $this->parents[1]), $this->parents[1])) : ''); + $prefix_dir .= $this->parents[1] > 0 ? + implode('/', array_slice($parts, (0 - $this->parents[1]), $this->parents[1])) + : ''; $prefix_dir = rtrim($prefix_dir, '/'); $target = $to . '/' . $prefix_dir . '/' . basename($file); } diff --git a/src/Task/Filesystem/WorkDir.php b/src/Task/Filesystem/WorkDir.php index 4b75c6ed2..df41f251b 100644 --- a/src/Task/Filesystem/WorkDir.php +++ b/src/Task/Filesystem/WorkDir.php @@ -63,7 +63,13 @@ public function run() // move it out of the way before placing our results there. if (is_dir($this->finalDestination)) { if (!is_writable($this->finalDestination)) { - return Result::error($this, "Destination directory {dir} exists and cannot be overwritten.", ['dir' => $this->finalDestination]); + return Result::error( + $this, + "Destination directory {dir} exists and cannot be overwritten.", + [ + 'dir' => $this->finalDestination, + ] + ); } } diff --git a/src/Task/Gulp/Run.php b/src/Task/Gulp/Run.php index 84a2506ab..d1153a4a1 100644 --- a/src/Task/Gulp/Run.php +++ b/src/Task/Gulp/Run.php @@ -27,7 +27,13 @@ class Run extends Base implements CommandInterface public function run() { if (strlen($this->arguments)) { - $this->printTaskInfo('Running Gulp task: {gulp_task} with arguments: {arguments}', ['gulp_task' => $this->task, 'arguments' => $this->arguments]); + $this->printTaskInfo( + 'Running Gulp task: {gulp_task} with arguments: {arguments}', + [ + 'gulp_task' => $this->task, + 'arguments' => $this->arguments, + ] + ); } else { $this->printTaskInfo('Running Gulp task: {gulp_task} without arguments', ['gulp_task' => $this->task]); } diff --git a/src/Task/Simulator.php b/src/Task/Simulator.php index d4d9b2e14..462e4076e 100644 --- a/src/Task/Simulator.php +++ b/src/Task/Simulator.php @@ -104,7 +104,10 @@ public function run() public function getCommand() { if (!$this->task instanceof CommandInterface) { - throw new TaskException($this->task, 'Simulated task that is not a CommandInterface used as a CommandInterface.'); + throw new TaskException( + $this->task, + 'Simulated task that is not a CommandInterface used as a CommandInterface.' + ); } return $this->task->getCommand(); } diff --git a/src/Task/StackBasedTask.php b/src/Task/StackBasedTask.php index edff15219..48e591b5e 100644 --- a/src/Task/StackBasedTask.php +++ b/src/Task/StackBasedTask.php @@ -115,7 +115,13 @@ protected function getDelegateCommandList($function) */ protected function printTaskProgress($command, $action) { - $this->printTaskInfo('{command} {action}', ['command' => "{$command[1]}", 'action' => json_encode($action, JSON_UNESCAPED_SLASHES)]); + $this->printTaskInfo( + '{command} {action}', + [ + 'command' => "{$command[1]}", + 'action' => json_encode($action, JSON_UNESCAPED_SLASHES), + ] + ); } /** diff --git a/src/Task/Testing/Atoum.php b/src/Task/Testing/Atoum.php index 31c434de9..86b73fa52 100644 --- a/src/Task/Testing/Atoum.php +++ b/src/Task/Testing/Atoum.php @@ -43,7 +43,10 @@ public function __construct($pathToAtoum = null) $this->command = $this->findExecutable('atoum'); } if (!$this->command) { - throw new \Robo\Exception\TaskException(__CLASS__, "Neither local atoum nor global composer installation not found"); + throw new \Robo\Exception\TaskException( + __CLASS__, + "Neither local atoum nor global composer installation not found" + ); } } diff --git a/src/Task/Testing/PHPUnit.php b/src/Task/Testing/PHPUnit.php index c1b382031..fe5e9fa31 100644 --- a/src/Task/Testing/PHPUnit.php +++ b/src/Task/Testing/PHPUnit.php @@ -51,7 +51,10 @@ public function __construct($pathToPhpUnit = null) $this->command = $this->findExecutablePhar('phpunit'); } if (!$this->command) { - throw new \Robo\Exception\TaskException(__CLASS__, "Neither local phpunit nor global composer installation not found"); + throw new \Robo\Exception\TaskException( + __CLASS__, + "Neither local phpunit nor global composer installation not found" + ); } } diff --git a/src/Task/Testing/Phpspec.php b/src/Task/Testing/Phpspec.php index abce74868..11e867086 100644 --- a/src/Task/Testing/Phpspec.php +++ b/src/Task/Testing/Phpspec.php @@ -55,7 +55,10 @@ public function __construct($pathToPhpspec = null) $this->command = $this->findExecutable('phpspec'); } if (!$this->command) { - throw new \Robo\Exception\TaskException(__CLASS__, "Neither composer nor phar installation of Phpspec found"); + throw new \Robo\Exception\TaskException( + __CLASS__, + "Neither composer nor phar installation of Phpspec found" + ); } $this->arg('run'); } diff --git a/tests/_helpers/CliHelper.php b/tests/_helpers/CliHelper.php index f16d7ffbc..5db4f8570 100644 --- a/tests/_helpers/CliHelper.php +++ b/tests/_helpers/CliHelper.php @@ -54,7 +54,8 @@ public function seeDirFound($dir) $this->assertTrue(is_dir($dir) && file_exists($dir), "Directory does not exist"); } - public function _before(\Codeception\TestCase $test) { + public function _before(\Codeception\TestCase $test) + { $container = new \League\Container\Container(); $this->initSeeInOutputTrait($container); Robo::setContainer($container); @@ -63,7 +64,8 @@ public function _before(\Codeception\TestCase $test) { $this->getModule('Filesystem')->copyDir(codecept_data_dir().'claypit', codecept_data_dir().'sandbox'); } - public function _after(\Codeception\TestCase $test) { + public function _after(\Codeception\TestCase $test) + { $this->getModule('Filesystem')->deleteDir(codecept_data_dir().'sandbox'); $this->getContainer()->add('output', new ConsoleOutput()); chdir(codecept_root_dir()); diff --git a/tests/integration/AssetsTest.php b/tests/integration/AssetsTest.php index 9506eeaf3..f3f6fecae 100644 --- a/tests/integration/AssetsTest.php +++ b/tests/integration/AssetsTest.php @@ -46,8 +46,16 @@ public function testCssMinification() $this->assertLessThan($initialFileSize, $minifiedFileSize, 'Minified file is smaller than the source file'); $this->assertGreaterThan(0, $minifiedFileSize, 'Minified file is not empty'); - $this->assertStringContainsString('body', $outputCssContents, 'Minified file has some content from the source file'); - $this->assertStringNotContainsString('Sample css file', $outputCssContents, 'Minified file does not contain comment from source file'); + $this->assertStringContainsString( + 'body', + $outputCssContents, + 'Minified file has some content from the source file' + ); + $this->assertStringNotContainsString( + 'Sample css file', + $outputCssContents, + 'Minified file does not contain comment from source file' + ); } public function testImageMinification() diff --git a/tests/integration/CleanDirTest.php b/tests/integration/CleanDirTest.php index 0a9c4e465..bfdd691ce 100644 --- a/tests/integration/CleanDirTest.php +++ b/tests/integration/CleanDirTest.php @@ -33,5 +33,4 @@ public function testCleanDir() $this->assertFileDoesNotExist('box/robo.txt'); $this->assertFileExists('a.txt'); } - } diff --git a/tests/integration/CollectionTest.php b/tests/integration/CollectionTest.php index 150be6d07..93a77c97d 100644 --- a/tests/integration/CollectionTest.php +++ b/tests/integration/CollectionTest.php @@ -526,7 +526,9 @@ public function testChainData() ->provideMessage('2nd') ->storeState('two') ->taskValueProvider() - ->deferTaskConfiguration('provideItem', 'one') // Same as ->proivdeItem($state['one']), but runs immediately before this task's run() method. + // Same as ->proivdeItem($state['one']), + // but runs immediately before this task's run() method. + ->deferTaskConfiguration('provideItem', 'one') ->deferTaskConfiguration('provideMessage', 'two') ->storeState('final') ->run(); @@ -538,7 +540,4 @@ public function testChainData() $this->assertEquals('1st', $state['item']); $this->assertEquals('2nd', $state['final']); } - } - - diff --git a/tests/integration/ConcatTest.php b/tests/integration/ConcatTest.php index 020b17a3f..ff650c71b 100644 --- a/tests/integration/ConcatTest.php +++ b/tests/integration/ConcatTest.php @@ -34,8 +34,5 @@ public function testConcat() $expected = "A\nB\n"; $actual = file_get_contents('merged.txt'); $this->assertEquals($expected, $actual); - - } - } diff --git a/tests/integration/CopyDirTest.php b/tests/integration/CopyDirTest.php index d89688522..96ffc531c 100644 --- a/tests/integration/CopyDirTest.php +++ b/tests/integration/CopyDirTest.php @@ -86,7 +86,6 @@ public function testCopyRecursive() $this->assertTrue($result->wasSuccessful()); $this->assertFileExists('some_destination/deeply/nested'); $this->assertFileExists('some_destination/deeply/nested/structu.re'); - } public function testCopyRecursiveWithExcludedFile() diff --git a/tests/integration/DeleteDirTest.php b/tests/integration/DeleteDirTest.php index 7f0261677..0366955e8 100644 --- a/tests/integration/DeleteDirTest.php +++ b/tests/integration/DeleteDirTest.php @@ -34,5 +34,4 @@ public function testDeleteDir() $this->assertFileDoesNotExist('box'); $this->assertFileDoesNotExist('box/robo.txt'); } - } diff --git a/tests/integration/ExecTest.php b/tests/integration/ExecTest.php index ab2791a63..dbbe757da 100644 --- a/tests/integration/ExecTest.php +++ b/tests/integration/ExecTest.php @@ -21,10 +21,12 @@ public function testExecLsCommand() $this->assertTrue($res->wasSuccessful()); $this->assertStringContainsString( 'src', - $res->getMessage()); + $res->getMessage() + ); $this->assertStringContainsString( 'codeception.yml', - $res->getMessage()); + $res->getMessage() + ); } public function testMultipleEnvVars() @@ -37,10 +39,12 @@ public function testMultipleEnvVars() // Verify that the text contains our environment variable. $this->assertStringContainsString( 'FOO=BAR', - $result->getMessage()); + $result->getMessage() + ); $this->assertStringContainsString( 'BAR=BAZ', - $result->getMessage()); + $result->getMessage() + ); // Now verify that we can reset a value that was previously set. $task = $this->taskExec('env')->interactive(false); @@ -51,7 +55,8 @@ public function testMultipleEnvVars() // Verify that the text contains the most recent environment variable. $this->assertStringContainsString( 'FOO=BAZ', - $result->getMessage()); + $result->getMessage() + ); } public function testInheritEnv() @@ -78,7 +83,8 @@ public function testInheritEnv() $this->assertTrue($result->wasSuccessful()); $this->assertEquals( $start_count, - (int) $result->getMessage()); + (int) $result->getMessage() + ); // Now run the same command, but this time add another environment // variable, and see if our count increases by one. diff --git a/tests/integration/FilesystemStackTest.php b/tests/integration/FilesystemStackTest.php index 884610025..de50da8bf 100644 --- a/tests/integration/FilesystemStackTest.php +++ b/tests/integration/FilesystemStackTest.php @@ -87,5 +87,4 @@ public function testCrossVolumeRename() $this->assertFileDoesNotExist('log/error.txt'); $this->assertFileExists('logfiles/error.txt'); } - } diff --git a/tests/integration/FlattenDirTest.php b/tests/integration/FlattenDirTest.php index 70f09a183..0eb9f4776 100644 --- a/tests/integration/FlattenDirTest.php +++ b/tests/integration/FlattenDirTest.php @@ -51,6 +51,5 @@ public function testFlattenDirIncludingParents() $this->assertFileExists('flattened/deeply/nested'); $this->assertFileExists('flattened/deeply/nested/structu.re'); - } } diff --git a/tests/integration/GenerateMarkdownDocTest.php b/tests/integration/GenerateMarkdownDocTest.php index 98e400201..5b40b85c5 100644 --- a/tests/integration/GenerateMarkdownDocTest.php +++ b/tests/integration/GenerateMarkdownDocTest.php @@ -96,5 +96,4 @@ function (\ReflectionMethod $m, $text) { $this->assertStringContainsString('taskTestedRoboTask', $contents); $this->assertStringContainsString('Set the destination file', $contents); } - } diff --git a/tests/integration/GenerateTaskTest.php b/tests/integration/GenerateTaskTest.php index 38eb0f975..9475322b4 100644 --- a/tests/integration/GenerateTaskTest.php +++ b/tests/integration/GenerateTaskTest.php @@ -20,8 +20,8 @@ public function testTaskGeneration() $result = $this->taskGenTask('Symfony\Component\Filesystem\Filesystem', 'FilesystemStack')->run(); $this->assertTrue($result->wasSuccessful(), $result->getMessage()); $this->assertStringContainsString( - 'protected function _chgrp($files, $group, $recursive = false)', - $result->getMessage()); + 'protected function _chgrp($files, $group, $recursive = false)', + $result->getMessage() + ); } - } diff --git a/tests/integration/PackExtractTest.php b/tests/integration/PackExtractTest.php index 8a80f2720..44701240b 100644 --- a/tests/integration/PackExtractTest.php +++ b/tests/integration/PackExtractTest.php @@ -41,7 +41,7 @@ public function archiveTypeProvider() public function testPackExtract($archiveType) { if ((version_compare(PHP_VERSION, '7.4.0') >= 0) && (getenv('TRAVIS'))) { - $this->markTestSkipped('Zip libraries apparently not available on Travis CI with PHP 7.4 image.'); + $this->markTestSkipped('Zip libraries apparently not available on Travis CI with PHP 7.4 image.'); } // Archive directory and then extract it again with Archive and Extract tasks @@ -112,6 +112,5 @@ public function testPackExtract($archiveType) $this->assertFileDoesNotExist("decomposed-$archiveType/missing_files/structu32.re"); $this->assertDirectoryExists("decomposed-$archiveType/a/b"); $this->assertFileExists("decomposed-$archiveType/a/b/existing_file"); - } } diff --git a/tests/integration/PackPharTest.php b/tests/integration/PackPharTest.php index 70f0c89bf..d57bc4675 100644 --- a/tests/integration/PackPharTest.php +++ b/tests/integration/PackPharTest.php @@ -31,10 +31,12 @@ public function testAddStrippedFileContainingAnnotation() $this->fixtures->createAndCdToSandbox(); $pharFile = 'test.phar'; - $this->taskPackPhar($pharFile) + $this + ->taskPackPhar($pharFile) ->addStripped( 'annotated.php', - $this->fixtures->dataFile('TestedRoboFile.php')) + $this->fixtures->dataFile('TestedRoboFile.php') + ) ->run(); $phar = new \Phar($pharFile); diff --git a/tests/integration/RunnerTest.php b/tests/integration/RunnerTest.php index 89872c518..5458f6b54 100644 --- a/tests/integration/RunnerTest.php +++ b/tests/integration/RunnerTest.php @@ -194,7 +194,9 @@ public function testInvalidRoboDirectory() $argv = ['placeholder', 'no-such-command', '-f', 'no-such-directory']; $result = $runnerWithNoRoboFile->execute($argv, null, null, $this->capturedOutputStream()); - $this->assertOutputContains('Path `no-such-directory` is invalid; please provide a valid absolute path to the Robofile to load.'); + $this->assertOutputContains( + 'Path `no-such-directory` is invalid; please provide a valid absolute path to the Robofile to load.' + ); } public function testUnloadableRoboFile() diff --git a/tests/integration/SimulatedTest.php b/tests/integration/SimulatedTest.php index aa9ed8fb3..f0a6c0cbb 100644 --- a/tests/integration/SimulatedTest.php +++ b/tests/integration/SimulatedTest.php @@ -43,7 +43,4 @@ public function testSimulateDirCreation() $this->assertFileDoesNotExist('simulatedir/error.txt'); $this->assertOutputContains('[Simulator] Simulating Filesystem\FilesystemStack()'); } - } - - diff --git a/tests/integration/WriteFileTest.php b/tests/integration/WriteFileTest.php index 6dde12f27..be9380ef0 100644 --- a/tests/integration/WriteFileTest.php +++ b/tests/integration/WriteFileTest.php @@ -121,7 +121,6 @@ public function replaceInFile() $this->assertFileExists('a.txt'); $contents = file_get_contents('a.txt'); $this->assertStringContainsString('B', $contents); - } public function replaceMultipleInFile() @@ -136,4 +135,3 @@ public function replaceMultipleInFile() $this->assertStringContainsString('Hello robo.li!', $contents); } } - diff --git a/tests/phpunit/Common/CommandArgumentsTest.php b/tests/phpunit/Common/CommandArgumentsTest.php index 0a5c189ea..89e8154ac 100644 --- a/tests/phpunit/Common/CommandArgumentsTest.php +++ b/tests/phpunit/Common/CommandArgumentsTest.php @@ -10,7 +10,8 @@ */ class CommandArgumentsTest extends TestCase { - public function casesArgs() { + public function casesArgs() + { return [ 'no arguments' => [ ' ', diff --git a/tests/phpunit/Task/RsyncTest.php b/tests/phpunit/Task/RsyncTest.php index 48db2b9d3..d333077ad 100644 --- a/tests/phpunit/Task/RsyncTest.php +++ b/tests/phpunit/Task/RsyncTest.php @@ -7,9 +7,37 @@ class RsyncTest extends TestCase // tests public function testRsync() { - $linuxCmd = 'rsync --recursive --exclude .git --exclude .svn --exclude .hg --checksum --whole-file --verbose --progress --human-readable --stats src/ \'dev@localhost:/var/www/html/app/\''; - - $winCmd = 'rsync --recursive --exclude .git --exclude .svn --exclude .hg --checksum --whole-file --verbose --progress --human-readable --stats src/ "dev@localhost:/var/www/html/app/"'; + $linuxCmd = implode(' ', [ + 'rsync', + '--recursive', + '--exclude .git', + '--exclude .svn', + '--exclude .hg', + '--checksum', + '--whole-file', + '--verbose', + '--progress', + '--human-readable', + '--stats', + 'src/', + "'dev@localhost:/var/www/html/app/'", + ]); + + $winCmd = implode(' ', [ + 'rsync', + '--recursive', + '--exclude .git', + '--exclude .svn', + '--exclude .hg', + '--checksum', + '--whole-file', + '--verbose', + '--progress', + '--human-readable', + '--stats', + 'src/', + '"dev@localhost:/var/www/html/app/"', + ]); $cmd = stripos(PHP_OS, 'WIN') === 0 ? $winCmd : $linuxCmd; diff --git a/tests/src/Fixtures.php b/tests/src/Fixtures.php index 35b908b4a..6c1dded3a 100644 --- a/tests/src/Fixtures.php +++ b/tests/src/Fixtures.php @@ -27,8 +27,7 @@ public function cleanup() foreach ($this->tmpDirs as $tmpDir) { try { $fs->remove($tmpDir); - } - catch (\Exception $e) { + } catch (\Exception $e) { // Ignore problems with removing fixtures. } } @@ -43,7 +42,7 @@ public function cleanup() */ public function mktmpdir($basedir = false) { - $tempfile = tempnam($basedir ?: $this->testDir ?: sys_get_temp_dir(),'robo-tests'); + $tempfile = tempnam($basedir ?: $this->testDir ?: sys_get_temp_dir(), 'robo-tests'); unlink($tempfile); mkdir($tempfile); $this->tmpDirs[] = $tempfile; diff --git a/tests/src/Task/CollectionTestTask.php b/tests/src/Task/CollectionTestTask.php index ccdd35ac9..68e86e2cc 100644 --- a/tests/src/Task/CollectionTestTask.php +++ b/tests/src/Task/CollectionTestTask.php @@ -46,4 +46,3 @@ public function emphasizer() return $this->getValue(); } } - diff --git a/tests/unit/ApplicationTest.php b/tests/unit/ApplicationTest.php index 5ce06bff7..b2c0755f3 100644 --- a/tests/unit/ApplicationTest.php +++ b/tests/unit/ApplicationTest.php @@ -53,14 +53,17 @@ public function testTaskAccessor() $collectionBuilder = $method->invoke($this->roboCommandFileInstance, 'Robo\Task\Base\Exec', 'ls'); $this->assertEquals( 'Robo\Collection\CollectionBuilder', - get_class($collectionBuilder)); + get_class($collectionBuilder) + ); $task = $collectionBuilder->getCollectionBuilderCurrentTask(); $this->assertEquals( 'Robo\Task\Base\Exec', - get_class($task)); + get_class($task) + ); $this->assertEquals( 'Robo\Task\Base\Exec', - get_class($task)); + get_class($task) + ); } public function testAllowEmptyValuesAsDefaultsToOptionalOptions() @@ -84,7 +87,8 @@ public function testCommandDocumentation() $this->assertEquals( 'Calculate the fibonacci sequence between two numbers.', - $command->getDescription()); + $command->getDescription() + ); } public function testCommandCompactDocumentation() @@ -93,7 +97,8 @@ public function testCommandCompactDocumentation() $this->assertEquals( 'Compact doc comment', - $command->getDescription()); + $command->getDescription() + ); } public function testCommandArgumentDocumentation() @@ -104,13 +109,15 @@ public function testCommandArgumentDocumentation() $this->assertEquals( 'Number to start from', - $start->getDescription()); + $start->getDescription() + ); $steps = $command->getDefinition()->getArgument('steps'); $this->assertEquals( 'Number of steps to perform', - $steps->getDescription()); + $steps->getDescription() + ); } public function testCommandOptionDocumentation() @@ -121,7 +128,8 @@ public function testCommandOptionDocumentation() $this->assertEquals( 'Display the sequence graphically using cube representation', - $graphic->getDescription()); + $graphic->getDescription() + ); } public function testCommandHelpDocumentation() @@ -130,7 +138,8 @@ public function testCommandHelpDocumentation() $this->assertContains( '+----+---+', - $command->getHelp()); + $command->getHelp() + ); } public function testCommandNaming() diff --git a/tests/unit/ConfigurationTest.php b/tests/unit/ConfigurationTest.php index cb1d8cd06..62d3e1e63 100644 --- a/tests/unit/ConfigurationTest.php +++ b/tests/unit/ConfigurationTest.php @@ -18,13 +18,15 @@ public function testDifferentTasksCanHaveSameConfigKeys() $taskA->setConfig(Robo::config()); $this->assertEquals( 'value-a', - $taskA->run()); + $taskA->run() + ); $taskB = new ConfigurationTestTaskB(); $taskB->setConfig(Robo::config()); $this->assertEquals( 'value-b', - $taskB->run()); + $taskB->run() + ); } public function testConfigurationWithCrossFileReferences() @@ -38,22 +40,27 @@ public function testConfigurationWithCrossFileReferences() $sources = $processor->sources(); $this->assertEquals( dirname(__DIR__) . '/_data/config-3.yml', - $sources['a']); + $sources['a'] + ); $this->assertEquals( dirname(__DIR__) . '/_data/config-2.yml', - $sources['b']); + $sources['b'] + ); $this->assertEquals( dirname(__DIR__) . '/_data/config-1.yml', - $sources['c']); + $sources['c'] + ); \Robo\Robo::config()->import($processor->export()); $this->assertEquals( '3', - implode(',', \Robo\Robo::config()->get('m'))); + implode(',', \Robo\Robo::config()->get('m')) + ); $this->assertEquals( 'foobarbaz', - \Robo\Robo::config()->get('a')); + \Robo\Robo::config()->get('a') + ); } public function testConfigurationWithReverseOrderCrossFileReferences() @@ -67,19 +74,23 @@ public function testConfigurationWithReverseOrderCrossFileReferences() $sources = $processor->sources(); $this->assertEquals( dirname(__DIR__) . '/_data/config-3.yml', - $sources['a']); + $sources['a'] + ); $this->assertEquals( dirname(__DIR__) . '/_data/config-2.yml', - $sources['b']); + $sources['b'] + ); $this->assertEquals( dirname(__DIR__) . '/_data/config-1.yml', - $sources['c']); + $sources['c'] + ); \Robo\Robo::config()->import($processor->export()); $this->assertEquals( '1', - implode(',', \Robo\Robo::config()->get('m'))); + implode(',', \Robo\Robo::config()->get('m')) + ); if (strpos(\Robo\Robo::config()->get('a'), '$') !== false) { throw new \PHPUnit_Framework_SkippedTestError( @@ -88,7 +99,8 @@ public function testConfigurationWithReverseOrderCrossFileReferences() } $this->assertEquals( 'foobarbaz', - \Robo\Robo::config()->get('a')); + \Robo\Robo::config()->get('a') + ); } } diff --git a/tests/unit/ResultTest.php b/tests/unit/ResultTest.php index 02fc322e4..24ba84bea 100644 --- a/tests/unit/ResultTest.php +++ b/tests/unit/ResultTest.php @@ -2,7 +2,8 @@ use Robo\Result; use Robo\Exception\TaskExitException; -class ResultTest extends \Codeception\TestCase\Test { +class ResultTest extends \Codeception\TestCase\Test +{ /** * @var \CodeGuy diff --git a/tests/unit/Task/ApiGenTest.php b/tests/unit/Task/ApiGenTest.php index 802fd2462..b413ad422 100644 --- a/tests/unit/Task/ApiGenTest.php +++ b/tests/unit/Task/ApiGenTest.php @@ -43,9 +43,39 @@ public function testPHPUnitCommand() ->tree('Y') // boolean as string ->debug('n'); - $linuxCmd = 'apigen generate --config ./apigen.neon --source src --extensions php --exclude test --exclude tmp --skip-doc-path a --skip-doc-path b --charset \'utf8,iso88591\' --internal no --php yes --tree yes --debug no'; + $linuxCmd = implode(' ', [ + 'apigen', + 'generate', + '--config ./apigen.neon', + '--source src', + '--extensions php', + '--exclude test', + '--exclude tmp', + '--skip-doc-path a', + '--skip-doc-path b', + "--charset 'utf8,iso88591'", + '--internal no', + '--php yes', + '--tree yes', + '--debug no', + ]); - $winCmd = 'apigen generate --config ./apigen.neon --source src --extensions php --exclude test --exclude tmp --skip-doc-path a --skip-doc-path b --charset "utf8,iso88591" --internal no --php yes --tree yes --debug no'; + $winCmd = implode(' ', [ + 'apigen', + 'generate', + '--config ./apigen.neon', + '--source src', + '--extensions php', + '--exclude test', + '--exclude tmp', + '--skip-doc-path a', + '--skip-doc-path b', + '--charset "utf8,iso88591"', + '--internal no', + '--php yes', + '--tree yes', + '--debug no', + ]); $cmd = stripos(PHP_OS, 'WIN') === 0 ? $winCmd : $linuxCmd; diff --git a/tests/unit/Task/AtoumTest.php b/tests/unit/Task/AtoumTest.php index e5815beeb..da0269c6e 100644 --- a/tests/unit/Task/AtoumTest.php +++ b/tests/unit/Task/AtoumTest.php @@ -19,6 +19,20 @@ protected function _before() public function testAtoumCommand() { + $expectedCommand = implode(' ', [ + 'atoum', + '--bootstrap bootstrap.php', + '--tags needDb', + '--use-light-report', + '--use-tap-report', + '--bootstrap tests/bootstrap.php', + '-c config/dev.php', + '--debug', + '--f path/to/file1.php', + '--f path/to/file2.php', + '--directories tests/units', + ]); + $task = (new \Robo\Task\Testing\Atoum('atoum')) ->bootstrap('bootstrap.php') ->tags("needDb") @@ -28,12 +42,16 @@ public function testAtoumCommand() ->configFile("config/dev.php") ->debug() ->files(array("path/to/file1.php", "path/to/file2.php")) - ->directories("tests/units") - ; - $this->assertEquals( - 'atoum --bootstrap bootstrap.php --tags needDb --use-light-report --use-tap-report --bootstrap tests/bootstrap.php -c config/dev.php --debug --f path/to/file1.php --f path/to/file2.php --directories tests/units', - $task->getCommand()); + ->directories("tests/units"); + + $this->assertEquals($expectedCommand, $task->getCommand()); + $task->run(); - $this->atoum->verifyInvoked('executeCommand', ['atoum --bootstrap bootstrap.php --tags needDb --use-light-report --use-tap-report --bootstrap tests/bootstrap.php -c config/dev.php --debug --f path/to/file1.php --f path/to/file2.php --directories tests/units']); + $this->atoum->verifyInvoked( + 'executeCommand', + [ + $expectedCommand, + ] + ); } } diff --git a/tests/unit/Task/BehatTest.php b/tests/unit/Task/BehatTest.php index e3feb9d75..5f819ce2b 100644 --- a/tests/unit/Task/BehatTest.php +++ b/tests/unit/Task/BehatTest.php @@ -20,7 +20,14 @@ protected function _before() // tests public function testBehatRun() { - $behat = test::double('Robo\Task\Testing\Behat', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $behat = test::double( + 'Robo\Task\Testing\Behat', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger(), + ] + ); (new \Robo\Task\Testing\Behat('behat'))->run(); $behat->verifyInvoked('executeCommand'); @@ -28,7 +35,14 @@ public function testBehatRun() public function testBehatCommand() { - $behat = test::double('Robo\Task\Testing\Behat', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $behat = test::double( + 'Robo\Task\Testing\Behat', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger(), + ] + ); $task = (new \Robo\Task\Testing\Behat('behat')) ->stopOnFail() @@ -36,9 +50,9 @@ public function testBehatCommand() ->colors(); $this->assertEquals( 'behat --stop-on-failure --no-interaction --colors', - $task->getCommand()); + $task->getCommand() + ); $task->run(); $behat->verifyInvoked('executeCommand', ['behat --stop-on-failure --no-interaction --colors']); } - } diff --git a/tests/unit/Task/BowerTest.php b/tests/unit/Task/BowerTest.php index 2500ad555..374f18f06 100644 --- a/tests/unit/Task/BowerTest.php +++ b/tests/unit/Task/BowerTest.php @@ -20,7 +20,13 @@ protected function _before() // tests public function testBowerInstall() { - $bower = test::double('Robo\Task\Bower\Install', ['executeCommand' => null, 'logger' => new \Psr\Log\NullLogger(),]); + $bower = test::double( + 'Robo\Task\Bower\Install', + [ + 'executeCommand' => null, + 'logger' => new \Psr\Log\NullLogger(), + ] + ); (new \Robo\Task\Bower\Install('bower'))->run(); $bower->verifyInvoked('executeCommand', ['bower install']); } @@ -57,5 +63,4 @@ public function testBowerInstallCommand() ->getCommand() ); } - } diff --git a/tests/unit/Task/CodeceptionTest.php b/tests/unit/Task/CodeceptionTest.php index 29863d411..1e817be6a 100644 --- a/tests/unit/Task/CodeceptionTest.php +++ b/tests/unit/Task/CodeceptionTest.php @@ -23,7 +23,8 @@ public function testCodeceptionCommand() { $this->assertEquals( 'codecept.phar run', - trim((new \Robo\Task\Testing\Codecept('codecept.phar'))->getCommand())); + trim((new \Robo\Task\Testing\Codecept('codecept.phar'))->getCommand()) + ); } public function testCodeceptionRun() @@ -50,6 +51,7 @@ public function testCodeceptOptions() $failGroupName = 'failed1'; $this->assertRegExp( + // phpcs:ignore "|^codecept run tests/unit/Codeception -c ~/Codeception --xml result\\.xml --html --no-rebuild --override ['\"]extensions: config: Codeception\\\\Extension\\\\RunFailed: fail-group: {$failGroupName}['\"]$|", (new \Robo\Task\Testing\Codecept('codecept')) ->test('tests/unit/Codeception') @@ -63,26 +65,34 @@ public function testCodeceptOptions() $this->assertContains( ' --debug', - (new \Robo\Task\Testing\Codecept('codecept.phar'))->debug()->getCommand()); + (new \Robo\Task\Testing\Codecept('codecept.phar'))->debug()->getCommand() + ); $this->assertContains( ' --silent', - (new \Robo\Task\Testing\Codecept('codecept.phar'))->silent()->getCommand()); + (new \Robo\Task\Testing\Codecept('codecept.phar'))->silent()->getCommand() + ); $this->assertContains( ' --skip-group g', - (new \Robo\Task\Testing\Codecept('codecept.phar'))->excludeGroup('g')->getCommand()); + (new \Robo\Task\Testing\Codecept('codecept.phar'))->excludeGroup('g')->getCommand() + ); $this->assertContains( '--tap', - (new \Robo\Task\Testing\Codecept('codecept.phar'))->tap()->getCommand()); + (new \Robo\Task\Testing\Codecept('codecept.phar'))->tap()->getCommand() + ); $this->assertContains( '--json', - (new \Robo\Task\Testing\Codecept('codecept.phar'))->json()->getCommand()); + (new \Robo\Task\Testing\Codecept('codecept.phar'))->json()->getCommand() + ); $this->assertContains( '--no-rebuild', - (new \Robo\Task\Testing\Codecept('codecept.phar'))->noRebuild()->getCommand()); + (new \Robo\Task\Testing\Codecept('codecept.phar'))->noRebuild()->getCommand() + ); + $failGroupName = 'failed2'; $this->assertRegExp( + // phpcs:ignore "|--override ['\"]extensions: config: Codeception\\\\Extension\\\\RunFailed: fail-group: {$failGroupName}['\"]|", - (new \Robo\Task\Testing\Codecept('codecept.phar'))->failGroup($failGroupName)->getCommand()); + (new \Robo\Task\Testing\Codecept('codecept.phar'))->failGroup($failGroupName)->getCommand() + ); } - } diff --git a/tests/unit/Task/ComposerTest.php b/tests/unit/Task/ComposerTest.php index 48f33764a..3b1cce744 100644 --- a/tests/unit/Task/ComposerTest.php +++ b/tests/unit/Task/ComposerTest.php @@ -24,7 +24,14 @@ protected function _before() // tests public function testComposerInstall() { - $composer = test::double('Robo\Task\Composer\Install', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $composer = test::double( + 'Robo\Task\Composer\Install', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger() + ] + ); (new \Robo\Task\Composer\Install('composer'))->run(); $composer->verifyInvoked('executeCommand', ['composer install --no-interaction']); @@ -45,7 +52,14 @@ public function testComposerInstallAnsi() $config = new \Robo\Config(); $config->setDecorated(true); $config->setInteractive(true); - $composer = test::double('Robo\Task\Composer\Install', ['executeCommand' => null, 'getConfig' => $config, 'logger' => new \Psr\Log\NullLogger()]); + $composer = test::double( + 'Robo\Task\Composer\Install', + [ + 'executeCommand' => null, + 'getConfig' => $config, + 'logger' => new \Psr\Log\NullLogger() + ] + ); (new \Robo\Task\Composer\Install('composer'))->run(); $composer->verifyInvoked('executeCommand', ['composer install --ansi']); @@ -63,7 +77,14 @@ public function testComposerInstallAnsi() public function testComposerUpdate() { - $composer = test::double('Robo\Task\Composer\Update', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $composer = test::double( + 'Robo\Task\Composer\Update', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger() + ] + ); (new \Robo\Task\Composer\Update('composer'))->run(); $composer->verifyInvoked('executeCommand', ['composer update --no-interaction']); @@ -76,7 +97,14 @@ public function testComposerUpdate() public function testComposerDumpAutoload() { - $composer = test::double('Robo\Task\Composer\DumpAutoload', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $composer = test::double( + 'Robo\Task\Composer\DumpAutoload', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger() + ] + ); (new \Robo\Task\Composer\DumpAutoload('composer'))->run(); $composer->verifyInvoked('executeCommand', ['composer dump-autoload --no-interaction']); @@ -100,7 +128,14 @@ public function testComposerDumpAutoload() public function testComposerValidate() { - $composer = test::double('Robo\Task\Composer\Validate', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $composer = test::double( + 'Robo\Task\Composer\Validate', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger() + ] + ); (new \Robo\Task\Composer\Validate('composer'))->run(); $composer->verifyInvoked('executeCommand', ['composer validate --no-interaction']); @@ -273,8 +308,18 @@ public function testComposerValidateCommand() ->getCommand() ); + $expected = implode(' ', [ + 'composer', + 'validate', + '--no-check-all', + '--no-check-lock', + '--no-check-publish', + '--with-dependencies', + '--strict', + '--no-interaction', + ]); $this->assertEquals( - 'composer validate --no-check-all --no-check-lock --no-check-publish --with-dependencies --strict --no-interaction', + $expected, (new \Robo\Task\Composer\Validate('composer')) ->setConfig(new \Robo\Config()) ->noCheckAll() @@ -293,8 +338,21 @@ public function testComposerInitCommand() (new \Robo\Task\Composer\Init('composer'))->setConfig(new \Robo\Config())->getCommand() ); + $expected = $this->adjustQuotes(implode(' ', [ + 'composer', + 'init', + '--name foo/bar', + "--description 'A test project'", + "--require 'baz/boz:^2.4.8'", + '--type project', + "--homepage 'https://foo.bar.com'", + '--stability beta', + '--license MIT', + "--repository 'https://packages.drupal.org/8'", + '--no-interaction', + ])); $this->assertEquals( - $this->adjustQuotes("composer init --name foo/bar --description 'A test project' --require 'baz/boz:^2.4.8' --type project --homepage 'https://foo.bar.com' --stability beta --license MIT --repository 'https://packages.drupal.org/8' --no-interaction"), + $expected, (new \Robo\Task\Composer\Init('composer')) ->setConfig(new \Robo\Config()) ->projectName('foo/bar') @@ -307,7 +365,6 @@ public function testComposerInitCommand() ->repository('https://packages.drupal.org/8') ->getCommand() ); - } public function testComposerConfigCommand() @@ -329,8 +386,16 @@ public function testComposerConfigCommand() ->getCommand() ); + $expected = $this->adjustQuotes(implode(' ', [ + 'composer', + 'config', + 'repositories.drupalorg', + 'composer', + "'https://packages.drupal.org/8'", + '--no-interaction', + ])); $this->assertEquals( - $this->adjustQuotes("composer config repositories.drupalorg composer 'https://packages.drupal.org/8' --no-interaction"), + $expected, (new \Robo\Task\Composer\Config('composer')) ->setConfig(new \Robo\Config()) ->repository('drupalorg', 'https://packages.drupal.org/8', 'composer') @@ -359,8 +424,20 @@ public function testComposerRequireCommand() public function testComposerCreateProjectCommand() { + $expected = $this->adjustQuotes(implode(' ', [ + 'composer', + 'create-project', + '--repository', + "'https://packages.drupal.org/8'", + '--keep-vcs', + '--no-install', + 'foo/bar', + 'mybar', + "'^2.4.8'", + '--no-interaction', + ])); $this->assertEquals( - $this->adjustQuotes("composer create-project --repository 'https://packages.drupal.org/8' --keep-vcs --no-install foo/bar mybar '^2.4.8' --no-interaction"), + $expected, (new \Robo\Task\Composer\CreateProject('composer')) ->setConfig(new \Robo\Config()) ->source('foo/bar') diff --git a/tests/unit/Task/DockerTest.php b/tests/unit/Task/DockerTest.php index 57d349068..578ef4963 100644 --- a/tests/unit/Task/DockerTest.php +++ b/tests/unit/Task/DockerTest.php @@ -20,7 +20,14 @@ protected function _before() // tests public function testDockerBuild() { - $docker = test::double('Robo\Task\Docker\Build', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $docker = test::double( + 'Robo\Task\Docker\Build', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger() + ] + ); (new \Robo\Task\Docker\Build())->run(); $docker->verifyInvoked('executeCommand', ['docker build .']); @@ -34,7 +41,14 @@ public function testDockerBuild() public function testDockerCommit() { - $docker = test::double('Robo\Task\Docker\Commit', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $docker = test::double( + 'Robo\Task\Docker\Commit', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger() + ] + ); (new \Robo\Task\Docker\Commit('cid'))->run(); $docker->verifyInvoked('executeCommand', ['docker commit cid ']); @@ -45,7 +59,14 @@ public function testDockerCommit() public function testDockerExec() { - $docker = test::double('Robo\Task\Docker\Exec', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $docker = test::double( + 'Robo\Task\Docker\Exec', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger() + ] + ); (new \Robo\Task\Docker\Exec('cid'))->run(); $docker->verifyInvoked('executeCommand', ['docker exec cid ']); @@ -56,7 +77,14 @@ public function testDockerExec() public function testDockerPull() { - $docker = test::double('Robo\Task\Docker\Pull', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $docker = test::double( + 'Robo\Task\Docker\Pull', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger() + ] + ); (new \Robo\Task\Docker\Pull('image'))->run(); $docker->verifyInvoked('executeCommand', ['docker pull image ']); @@ -64,7 +92,14 @@ public function testDockerPull() public function testDockerRemove() { - $docker = test::double('Robo\Task\Docker\Remove', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $docker = test::double( + 'Robo\Task\Docker\Remove', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger() + ] + ); (new \Robo\Task\Docker\Remove('container'))->run(); $docker->verifyInvoked('executeCommand', ['docker rm container ']); @@ -72,7 +107,15 @@ public function testDockerRemove() public function testDockerRun() { - $docker = test::double('Robo\Task\Docker\Run', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger(), 'getUniqId' => '12345']); + $docker = test::double( + 'Robo\Task\Docker\Run', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger(), + 'getUniqId' => '12345' + ] + ); (new \Robo\Task\Docker\Run('cid'))->tmpDir('/tmp')->run(); $docker->verifyInvoked('executeCommand', ['docker run -i --cidfile /tmp/docker_12345.cid cid']); @@ -83,7 +126,14 @@ public function testDockerRun() public function testDockerStart() { - $docker = test::double('Robo\Task\Docker\Start', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $docker = test::double( + 'Robo\Task\Docker\Start', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger() + ] + ); (new \Robo\Task\Docker\Start('cid'))->run(); $docker->verifyInvoked('executeCommand', ['docker start cid']); @@ -91,7 +141,14 @@ public function testDockerStart() public function testDockerStop() { - $docker = test::double('Robo\Task\Docker\Stop', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $docker = test::double( + 'Robo\Task\Docker\Stop', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger() + ] + ); (new \Robo\Task\Docker\Stop('cid'))->run(); $docker->verifyInvoked('executeCommand', ['docker stop cid']); diff --git a/tests/unit/Task/ExecTaskTest.php b/tests/unit/Task/ExecTaskTest.php index 36d36c0b7..003010828 100644 --- a/tests/unit/Task/ExecTaskTest.php +++ b/tests/unit/Task/ExecTaskTest.php @@ -29,7 +29,8 @@ public function testExec() $this->process->verifyInvoked('run'); $this->assertEquals( 'Hello world', - $result->getMessage()); + $result->getMessage() + ); $this->assertEquals(0, $result->getExitCode()); } @@ -48,7 +49,8 @@ public function testGetCommand() { $this->assertEquals( 'ls', - (new \Robo\Task\Base\Exec('ls'))->getCommand()); + (new \Robo\Task\Base\Exec('ls'))->getCommand() + ); } public function testExecStack() @@ -86,4 +88,4 @@ public function testExecStackCommandInterface() ->getCommand() ); } -}; +} diff --git a/tests/unit/Task/GitTest.php b/tests/unit/Task/GitTest.php index 5038cb6eb..78867d851 100644 --- a/tests/unit/Task/GitTest.php +++ b/tests/unit/Task/GitTest.php @@ -31,9 +31,37 @@ public function testGitStackRun() public function testGitStackCommands() { - $linuxCmd = "git clone https://github.com/consolidation-org/Robo && git pull && git add -A && git commit -m 'changed' && git push && git tag 0.6.0 && git push origin 0.6.0"; + $linuxCmd = implode(' ', [ + 'git clone https://github.com/consolidation-org/Robo', + '&&', + 'git pull', + '&&', + 'git add -A', + '&&', + "git commit -m 'changed'", + '&&', + 'git push', + '&&', + 'git tag 0.6.0', + '&&', + 'git push origin 0.6.0', + ]); - $winCmd = 'git clone https://github.com/consolidation-org/Robo && git pull && git add -A && git commit -m "changed" && git push && git tag 0.6.0 && git push origin 0.6.0'; + $winCmd = implode(' ', [ + 'git clone https://github.com/consolidation-org/Robo', + '&&', + 'git pull', + '&&', + 'git add -A', + '&&', + 'git commit -m "changed"', + '&&', + 'git push', + '&&', + 'git tag 0.6.0', + '&&', + 'git push origin 0.6.0', + ]); $cmd = stripos(PHP_OS, 'WIN') === 0 ? $winCmd : $linuxCmd; @@ -53,9 +81,37 @@ public function testGitStackCommands() public function testGitStackCommandsWithTagMessage() { - $linuxCmd = "git clone https://github.com/consolidation-org/Robo && git pull && git add -A && git commit -m 'changed' && git push && git tag -m 'message' 0.6.0 && git push origin 0.6.0"; + $linuxCmd = implode(' ', [ + 'git clone https://github.com/consolidation-org/Robo', + '&&', + 'git pull', + '&&', + 'git add -A', + '&&', + "git commit -m 'changed'", + '&&', + 'git push', + '&&', + "git tag -m 'message' 0.6.0", + '&&', + "git push origin 0.6.0", + ]); - $winCmd = 'git clone https://github.com/consolidation-org/Robo && git pull && git add -A && git commit -m "changed" && git push && git tag -m \'message\' 0.6.0 && git push origin 0.6.0'; + $winCmd = implode(' ', [ + 'git clone https://github.com/consolidation-org/Robo', + '&&', + 'git pull', + '&&', + 'git add -A', + '&&', + 'git commit -m "changed"', + '&&', + 'git push', + '&&', + "git tag -m 'message' 0.6.0", + '&&', + 'git push origin 0.6.0', + ]); $cmd = stripos(PHP_OS, 'WIN') === 0 ? $winCmd : $linuxCmd; diff --git a/tests/unit/Task/GulpTest.php b/tests/unit/Task/GulpTest.php index 567f768c7..b84f33deb 100644 --- a/tests/unit/Task/GulpTest.php +++ b/tests/unit/Task/GulpTest.php @@ -24,43 +24,51 @@ public function testGulpGetCommand() { $this->assertEquals( $this->adjustQuotes("gulp 'default'"), - (new \Robo\Task\Gulp\Run('default','gulp'))->getCommand() + (new \Robo\Task\Gulp\Run('default', 'gulp'))->getCommand() ); $this->assertEquals( $this->adjustQuotes("gulp 'another'"), - (new \Robo\Task\Gulp\Run('another','gulp'))->getCommand() + (new \Robo\Task\Gulp\Run('another', 'gulp'))->getCommand() ); $this->assertEquals( $this->adjustQuotes("gulp 'default' --silent"), - (new \Robo\Task\Gulp\Run('default','gulp'))->silent()->getCommand() + (new \Robo\Task\Gulp\Run('default', 'gulp'))->silent()->getCommand() ); $this->assertEquals( $this->adjustQuotes("gulp 'default' --no-color"), - (new \Robo\Task\Gulp\Run('default','gulp'))->noColor()->getCommand() + (new \Robo\Task\Gulp\Run('default', 'gulp'))->noColor()->getCommand() ); $this->assertEquals( $this->adjustQuotes("gulp 'default' --color"), - (new \Robo\Task\Gulp\Run('default','gulp'))->color()->getCommand() + (new \Robo\Task\Gulp\Run('default', 'gulp'))->color()->getCommand() ); $this->assertEquals( $this->adjustQuotes("gulp 'default' --tasks-simple"), - (new \Robo\Task\Gulp\Run('default','gulp'))->simple()->getCommand() + (new \Robo\Task\Gulp\Run('default', 'gulp'))->simple()->getCommand() ); } public function testGulpRun() { - $gulp = test::double('Robo\Task\Gulp\Run', ['executeCommand' => null, 'getConfig' => new \Robo\Config(), 'logger' => new \Psr\Log\NullLogger()]); + $gulp = test::double( + 'Robo\Task\Gulp\Run', + [ + 'executeCommand' => null, + 'getConfig' => new \Robo\Config(), + 'logger' => new \Psr\Log\NullLogger(), + ] + ); - $task = (new \Robo\Task\Gulp\Run('default','gulp'))->simple(); + $task = (new \Robo\Task\Gulp\Run('default', 'gulp'))->simple(); $this->assertEquals( $this->adjustQuotes("gulp 'default' --tasks-simple"), - $task->getCommand()); + $task->getCommand() + ); $task->run(); $gulp->verifyInvoked('executeCommand', [$this->adjustQuotes("gulp 'default' --tasks-simple")]); } @@ -74,7 +82,7 @@ public function testGulpUnusualChars() $this->assertEquals( $expected, - (new \Robo\Task\Gulp\Run('anotherWith weired!("\') Chars','gulp'))->getCommand() + (new \Robo\Task\Gulp\Run('anotherWith weired!("\') Chars', 'gulp'))->getCommand() ); } } diff --git a/tests/unit/Task/HgTest.php b/tests/unit/Task/HgTest.php index 10ac38441..7c2ee1b45 100644 --- a/tests/unit/Task/HgTest.php +++ b/tests/unit/Task/HgTest.php @@ -57,8 +57,23 @@ public function testHgStackAddFiles() public function testHgStackCommands() { + $expected = implode(' ', [ + 'hg clone https://bitbucket.org/durin42/hgsubversion', + '&&', + 'hg pull', + '&&', + 'hg add', + '&&', + "hg commit -m 'changed'", + '&&', + 'hg push', + '&&', + 'hg tag 0.6.0', + '&&', + "hg push -b '0.6.0'", + ]); $this->assertEquals( - "hg clone https://bitbucket.org/durin42/hgsubversion && hg pull && hg add && hg commit -m 'changed' && hg push && hg tag 0.6.0 && hg push -b '0.6.0'", + $expected, $this->hgStack ->cloneRepo('https://bitbucket.org/durin42/hgsubversion') ->pull() @@ -73,8 +88,23 @@ public function testHgStackCommands() public function testHgStackCommandsWithTagMessage() { + $expected = implode(' ', [ + 'hg clone https://bitbucket.org/durin42/hgsubversion', + '&&', + 'hg pull', + '&&', + 'hg add', + '&&', + "hg commit -m 'changed'", + '&&', + 'hg push', + '&&', + "hg tag -m 'message' 0.6.0". + '&&', + "hg push -b '0.6.0'", + ]); $this->assertEquals( - "hg clone https://bitbucket.org/durin42/hgsubversion && hg pull && hg add && hg commit -m 'changed' && hg push && hg tag -m 'message' 0.6.0 && hg push -b '0.6.0'", + $expected, $this->hgStack ->cloneRepo('https://bitbucket.org/durin42/hgsubversion') ->pull() diff --git a/tests/unit/Task/NpmTest.php b/tests/unit/Task/NpmTest.php index 051fc1a85..2c81cb2e6 100644 --- a/tests/unit/Task/NpmTest.php +++ b/tests/unit/Task/NpmTest.php @@ -45,5 +45,4 @@ public function testNpmInstallCommand() ->getCommand() ); } - } diff --git a/tests/unit/Task/PHPServerTest.php b/tests/unit/Task/PHPServerTest.php index df0f24df6..1421e2c12 100644 --- a/tests/unit/Task/PHPServerTest.php +++ b/tests/unit/Task/PHPServerTest.php @@ -18,7 +18,12 @@ protected function _before() 'getExitCode' => 0, 'logger' => new \Psr\Log\NullLogger(), ]); - test::double('Robo\Task\Development\PhpServer', ['output' => new \Symfony\Component\Console\Output\NullOutput()]); + test::double( + 'Robo\Task\Development\PhpServer', + [ + 'output' => new \Symfony\Component\Console\Output\NullOutput(), + ] + ); } public function testServerBackgroundRun() diff --git a/tests/unit/Task/PHPUnitTest.php b/tests/unit/Task/PHPUnitTest.php index c7ca81363..61a4e0d91 100644 --- a/tests/unit/Task/PHPUnitTest.php +++ b/tests/unit/Task/PHPUnitTest.php @@ -34,9 +34,21 @@ public function testPHPUnitCommand() ->debug(); $this->assertEquals( 'phpunit --bootstrap bootstrap.php --filter Model --group important --log-junit result.xml --debug', - $task->getCommand()); + $task->getCommand() + ); $task->run(); - $this->phpunit->verifyInvoked('executeCommand', ['phpunit --bootstrap bootstrap.php --filter Model --group important --log-junit result.xml --debug']); + $this->phpunit->verifyInvoked( + 'executeCommand', + [ + implode(' ', [ + 'phpunit', + '--bootstrap bootstrap.php', + '--filter Model', + '--group important', + '--log-junit result.xml', + '--debug', + ]), + ] + ); } - } diff --git a/tests/unit/Task/PhpspecTest.php b/tests/unit/Task/PhpspecTest.php index 653cae21c..eeb6bb686 100644 --- a/tests/unit/Task/PhpspecTest.php +++ b/tests/unit/Task/PhpspecTest.php @@ -36,8 +36,24 @@ public function testPHPSpecCommand() ->format('pretty'); $this->assertEquals( 'phpspec run --stop-on-failure --no-code-generation --quiet -vv --no-ansi --no-interaction --format pretty', - $task->getCommand()); + $task->getCommand() + ); $task->run(); - $this->phpspec->verifyInvoked('executeCommand', ['phpspec run --stop-on-failure --no-code-generation --quiet -vv --no-ansi --no-interaction --format pretty']); + $this->phpspec->verifyInvoked( + 'executeCommand', + [ + implode(' ', [ + 'phpspec', + 'run', + '--stop-on-failure', + '--no-code-generation', + '--quiet', + '-vv', + '--no-ansi', + '--no-interaction', + '--format pretty', + ]), + ] + ); } } diff --git a/tests/unit/Task/SemVerTest.php b/tests/unit/Task/SemVerTest.php index 26d55c382..b55ac93fb 100644 --- a/tests/unit/Task/SemVerTest.php +++ b/tests/unit/Task/SemVerTest.php @@ -14,7 +14,8 @@ public function testSemver() ->run(); $this->assertEquals( 'v1.0.1-RC.1', - $res->getMessage()); + $res->getMessage() + ); $semver->verifyInvoked('dump'); } @@ -26,13 +27,15 @@ public function testSemverIncrementMinorAfterIncrementedPatch() ->run(); $this->assertEquals( 'v0.0.1', - $res->getMessage()); + $res->getMessage() + ); $res = (new \Robo\Task\Development\SemVer()) ->increment('minor') ->run(); $this->assertEquals( 'v0.1.0', - $res->getMessage()); + $res->getMessage() + ); $semver->verifyInvoked('dump'); } @@ -44,19 +47,22 @@ public function testSemverIncrementMajorAfterIncrementedMinorAndPatch() ->run(); $this->assertEquals( 'v0.0.1', - $res->getMessage()); + $res->getMessage() + ); $res = (new \Robo\Task\Development\SemVer()) ->increment('minor') ->run(); $this->assertEquals( 'v0.1.0', - $res->getMessage()); + $res->getMessage() + ); $res = (new \Robo\Task\Development\SemVer()) ->increment('major') ->run(); $this->assertEquals( 'v1.0.0', - $res->getMessage()); + $res->getMessage() + ); $semver->verifyInvoked('dump'); } @@ -70,7 +76,8 @@ public function testSemverParseFileWithWindowsLineEndings() ->run(); $this->assertEquals( 'v1.0.1-RC.1', - $res->getMessage()); + $res->getMessage() + ); @unlink($fixturePath); } diff --git a/tests/unit/Task/SvnTest.php b/tests/unit/Task/SvnTest.php index fc0ef4386..106c787fc 100644 --- a/tests/unit/Task/SvnTest.php +++ b/tests/unit/Task/SvnTest.php @@ -36,8 +36,31 @@ public function testSvnStackRun() public function testSvnStackCommands() { + $expected = implode(' ', [ + 'svn', + '--username guest', + '--password foo', + 'checkout svn://server/trunk', + '&&', + 'svn', + '--username guest', + '--password foo', + 'update', + '&&', + 'svn', + '--username guest', + '--password foo', + 'add', + '&&', + 'svn', + '--username guest', + '--password foo', + 'commit', + "-m 'changed'", + ]); + $this->assertEquals( - "svn --username guest --password foo checkout svn://server/trunk && svn --username guest --password foo update && svn --username guest --password foo add && svn --username guest --password foo commit -m 'changed'", + $expected, (new \Robo\Task\Vcs\SvnStack('guest', 'foo')) ->checkout('svn://server/trunk') ->update() @@ -46,5 +69,4 @@ public function testSvnStackCommands() ->getCommand() ); } - }