From 8e99c6d6f84b2cdfb280e79963cebc901da435e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 23 Apr 2017 14:57:03 +0200 Subject: [PATCH 01/10] Robo - allow v1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8ad2ef0c..acc6fe4f 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require": { "php": ">=5.4", "ext-xsl": "*", - "consolidation/robo": "<1", + "consolidation/robo": "<=1", "phpmd/phpmd" : "*", "phploc/phploc": "*", "symfony/dependency-injection": ">=2.8", From 889e3228f1e840ac8f357e3ba958b1f81bc6c0d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 23 Apr 2017 13:31:41 +0200 Subject: [PATCH 02/10] Robo - fix loadRoboFile declaration ERROR: Declaration of QARunner::loadRoboFile() should be compatible with Robo\Runner::loadRoboFile($output) --- phpqa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpqa b/phpqa index c5da434c..52056078 100755 --- a/phpqa +++ b/phpqa @@ -35,7 +35,7 @@ require_once COMPOSER_VENDOR_DIR . '/autoload.php'; */ class QARunner extends \Robo\Runner { - protected function loadRoboFile() + protected function loadRoboFile($output = null) { require_once __DIR__ . "/RoboFile.php"; return true; From afa243c82659c4c77b26955b6233252228e1a384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 23 Apr 2017 13:47:00 +0200 Subject: [PATCH 03/10] Robo - dont use autoescaping in robo v1 Breaking The arg(), args() and option() methods in CommandArguments now escape the values passed in to them. There is now a rawArg() method if you need to add just one argument that has already been escaped. --- src/CodeAnalysisTasks.php | 9 +++++---- src/Task/RoboAdapter.php | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/Task/RoboAdapter.php diff --git a/src/CodeAnalysisTasks.php b/src/CodeAnalysisTasks.php index f87b2445..f6ec7276 100644 --- a/src/CodeAnalysisTasks.php +++ b/src/CodeAnalysisTasks.php @@ -172,24 +172,25 @@ private function ciClean() private function runTools() { $group = $this->options->isParallel ? new Task\ParallelExec() : new Task\NonParallelExec(); + $roboAdapter= new Task\RoboAdapter(); foreach ($this->usedTools as $tool) { - $exec = $this->toolToExec($tool); + $exec = $this->toolToExec($tool, $roboAdapter); $tool->process = $group->process($exec); } $group->printed($this->options->isOutputPrinted)->run(); } /** @return \Robo\Task\Base\Exec */ - private function toolToExec(RunningTool $tool) + private function toolToExec(RunningTool $tool, Task\RoboAdapter $robo) { $binary = pathToBinary($tool->binary); $process = $this->taskExec($binary); $method = str_replace('-', '', $tool); foreach ($this->{$method}($tool) as $arg => $value) { if (is_int($arg)) { - $process->arg($value); + $robo->arg($process, $value); } else { - $process->arg($tool->buildOption($arg, $value)); + $robo->arg($process, $tool->buildOption($arg, $value)); } } return $process; diff --git a/src/Task/RoboAdapter.php b/src/Task/RoboAdapter.php new file mode 100644 index 00000000..5f9857c2 --- /dev/null +++ b/src/Task/RoboAdapter.php @@ -0,0 +1,23 @@ +isVersionOne = method_exists('Robo\Common\CommandArguments', 'rawArg'); + } + + // Robo v1 escapes the values + public function arg($exec, $arg) + { + if ($this->isVersionOne) { + return $exec->rawArg($arg); + } else { + return $exec->arg($arg); + } + } +} From f703f2eac5c780ce0ea245f018c6735d696cfc18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 23 Apr 2017 14:00:08 +0200 Subject: [PATCH 04/10] Robo - extract initializating tasks ERROR: No logger set for Edge\QA\Task\ParallelExec. Use $this->task(Foo::class) rather than new Foo() in loadTasks to ensure the builder can initialize task the task, or use $this->collectionBuilder()->taskFoo() if creating one task from within another. --- RoboFile.php | 1 + src/CodeAnalysisTasks.php | 2 +- src/Task/RoboAdapter.php | 5 +++++ src/Task/loadTasks.php | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/Task/loadTasks.php diff --git a/RoboFile.php b/RoboFile.php index 105dd090..860d4419 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -5,4 +5,5 @@ class RoboFile extends \Robo\Tasks { use CodeAnalysisTasks; + use Task\loadTasks; } diff --git a/src/CodeAnalysisTasks.php b/src/CodeAnalysisTasks.php index f6ec7276..46fb3619 100644 --- a/src/CodeAnalysisTasks.php +++ b/src/CodeAnalysisTasks.php @@ -171,8 +171,8 @@ private function ciClean() private function runTools() { - $group = $this->options->isParallel ? new Task\ParallelExec() : new Task\NonParallelExec(); $roboAdapter= new Task\RoboAdapter(); + $group = $this->taskPhpqaRunner($this->options->isParallel, $roboAdapter); foreach ($this->usedTools as $tool) { $exec = $this->toolToExec($tool, $roboAdapter); $tool->process = $group->process($exec); diff --git a/src/Task/RoboAdapter.php b/src/Task/RoboAdapter.php index 5f9857c2..b09bc89f 100644 --- a/src/Task/RoboAdapter.php +++ b/src/Task/RoboAdapter.php @@ -20,4 +20,9 @@ public function arg($exec, $arg) return $exec->arg($arg); } } + + public function isVersionOne() + { + return $this->isVersionOne; + } } diff --git a/src/Task/loadTasks.php b/src/Task/loadTasks.php new file mode 100644 index 00000000..719f673a --- /dev/null +++ b/src/Task/loadTasks.php @@ -0,0 +1,16 @@ +isVersionOne()) { + return $this->task($class); + } else { + return new $class(); + } + } +} From cd53f0dde2e5ee0a50b37d79e54bd79adb5068c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 23 Apr 2017 14:12:11 +0200 Subject: [PATCH 05/10] Robo - fix outputting text in nonParallelExec PHP Fatal error: Uncaught Error: Call to undefined method Edge\QA\Task\NonParallelExec::getOutput() Tasks must use TaskIO for output methods. It is no longer possible to use IO from a task. For direct access use Robo::output() (not recommended). https://github.com/EdgedesignCZ/phpqa/pull/57/files#diff-f9bcd99426b2eb566eabc2e8a09b18c2 --- src/Task/NonParallelExecV0.php | 41 +++++++++++++++++++ ...ParallelExec.php => NonParallelExecV1.php} | 35 ++++++++-------- src/Task/loadTasks.php | 2 +- 3 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 src/Task/NonParallelExecV0.php rename src/Task/{NonParallelExec.php => NonParallelExecV1.php} (64%) diff --git a/src/Task/NonParallelExecV0.php b/src/Task/NonParallelExecV0.php new file mode 100644 index 00000000..741b98b7 --- /dev/null +++ b/src/Task/NonParallelExecV0.php @@ -0,0 +1,41 @@ +progress = new ProgressBar($this->getOutput()); + $this->progress->start(count($this->processes)); + } + + protected function advanceProgressIndicator() + { + $this->progress->advance(); + } + + protected function stopProgressIndicator() + { + $this->getOutput()->writeln(""); + } + + protected function printProcessResult(Process $process) + { + $this->getOutput()->writeln(""); + $this->printTaskInfo( + "Output for " . $process->getCommandLine()." " + ); + $this->getOutput()->writeln($process->getOutput(), OutputInterface::OUTPUT_RAW); + if ($process->getErrorOutput()) { + $this->getOutput()->writeln("" . $process->getErrorOutput() . ""); + } + } +} diff --git a/src/Task/NonParallelExec.php b/src/Task/NonParallelExecV1.php similarity index 64% rename from src/Task/NonParallelExec.php rename to src/Task/NonParallelExecV1.php index 2f1d482c..6bb895c3 100644 --- a/src/Task/NonParallelExec.php +++ b/src/Task/NonParallelExecV1.php @@ -2,9 +2,9 @@ namespace Edge\QA\Task; -use Symfony\Component\Console\Helper\ProgressBar; -use Symfony\Component\Console\Output\OutputInterface; +use Consolidation\Log\ConsoleLogLevel; use Robo\Result; +use Symfony\Component\Process\Process; /** * The task has similar output, same signatures as ParallelExec, @@ -16,7 +16,7 @@ * - prints phploc's output when one command failed * phpqa --tools phpcs,phploc,phpmd --output file --execution s --quiet */ -class NonParallelExec extends ParallelExec +class NonParallelExecV1 extends ParallelExec { public function run() { @@ -24,26 +24,18 @@ public function run() $this->printTaskInfo($process->getCommandLine()); } - $progress = new ProgressBar($this->getOutput()); - $progress->start(count($this->processes)); + $this->startProgressIndicator(); $this->startTimer(); foreach ($this->processes as $process) { $process->run(); - $progress->advance(); + $this->advanceProgressIndicator(); if ($this->isPrinted) { - $this->getOutput()->writeln(""); - $this->printTaskInfo( - "Output for " . $process->getCommandLine()." " - ); - $this->getOutput()->writeln($process->getOutput(), OutputInterface::OUTPUT_RAW); - if ($process->getErrorOutput()) { - $this->getOutput()->writeln("" . $process->getErrorOutput() . ""); - } + $this->printProcessResult($process); } } - $this->getOutput()->writeln(""); + $this->stopProgressIndicator(); $this->stopTimer(); $errorMessage = ''; @@ -61,4 +53,15 @@ public function run() return new Result($this, $exitCode, $errorMessage, ['time' => $this->getExecutionTime()]); } -} + + protected function printProcessResult(Process $process) + { + $this->printTaskInfo( + "Output for " . $process->getCommandLine()." " + ); + $this->printTaskOutput(ConsoleLogLevel::SUCCESS, $process->getOutput(), $this->getTaskContext()); + if ($process->getErrorOutput()) { + $this->printTaskOutput(ConsoleLogLevel::ERROR, $process->getErrorOutput(), $this->getTaskContext()); + } + } +} \ No newline at end of file diff --git a/src/Task/loadTasks.php b/src/Task/loadTasks.php index 719f673a..cd9a4df7 100644 --- a/src/Task/loadTasks.php +++ b/src/Task/loadTasks.php @@ -6,7 +6,7 @@ trait loadTasks { function taskPhpqaRunner($isParallel, RoboAdapter $robo) { - $class = $isParallel ? ParallelExec::class : NonParallelExec::class; + $class = $isParallel ? ParallelExec::class : ($robo->isVersionOne() ? NonParallelExecV1::class : NonParallelExecV0::class); if ($robo->isVersionOne()) { return $this->task($class); } else { From 16c0497b22d8bf9446b870113a93e163b681d149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 23 Apr 2017 14:51:12 +0200 Subject: [PATCH 06/10] Robo - keep adapter in one place --- RoboFile.php | 2 +- src/CodeAnalysisTasks.php | 11 +++++------ src/Task/RoboAdapter.php | 28 ++++++++++++++++++---------- src/Task/loadTasks.php | 16 ---------------- 4 files changed, 24 insertions(+), 33 deletions(-) delete mode 100644 src/Task/loadTasks.php diff --git a/RoboFile.php b/RoboFile.php index 860d4419..47ba0643 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -5,5 +5,5 @@ class RoboFile extends \Robo\Tasks { use CodeAnalysisTasks; - use Task\loadTasks; + use Task\RoboAdapter; } diff --git a/src/CodeAnalysisTasks.php b/src/CodeAnalysisTasks.php index 46fb3619..13fe5d46 100644 --- a/src/CodeAnalysisTasks.php +++ b/src/CodeAnalysisTasks.php @@ -171,26 +171,25 @@ private function ciClean() private function runTools() { - $roboAdapter= new Task\RoboAdapter(); - $group = $this->taskPhpqaRunner($this->options->isParallel, $roboAdapter); + $group = $this->taskPhpqaRunner($this->options->isParallel); foreach ($this->usedTools as $tool) { - $exec = $this->toolToExec($tool, $roboAdapter); + $exec = $this->toolToExec($tool); $tool->process = $group->process($exec); } $group->printed($this->options->isOutputPrinted)->run(); } /** @return \Robo\Task\Base\Exec */ - private function toolToExec(RunningTool $tool, Task\RoboAdapter $robo) + private function toolToExec(RunningTool $tool) { $binary = pathToBinary($tool->binary); $process = $this->taskExec($binary); $method = str_replace('-', '', $tool); foreach ($this->{$method}($tool) as $arg => $value) { if (is_int($arg)) { - $robo->arg($process, $value); + $this->addArgToExec($process, $value); } else { - $robo->arg($process, $tool->buildOption($arg, $value)); + $this->addArgToExec($process, $tool->buildOption($arg, $value)); } } return $process; diff --git a/src/Task/RoboAdapter.php b/src/Task/RoboAdapter.php index b09bc89f..b6a6d938 100644 --- a/src/Task/RoboAdapter.php +++ b/src/Task/RoboAdapter.php @@ -2,27 +2,35 @@ namespace Edge\QA\Task; -class RoboAdapter +trait RoboAdapter { - private $isVersionOne; - - public function __construct() + protected function taskPhpqaRunner($isParallel) { - $this->isVersionOne = method_exists('Robo\Common\CommandArguments', 'rawArg'); + $class = $isParallel + ? ParallelExec::class + : ($this->isRoboVersionOne() ? NonParallelExecV1::class : NonParallelExecV0::class); + if ($this->isRoboVersionOne()) { + return $this->task($class); + } else { + return new $class(); + } } - // Robo v1 escapes the values - public function arg($exec, $arg) + protected function addArgToExec($exec, $arg) { - if ($this->isVersionOne) { + if ($this->isRoboVersionOne()) { return $exec->rawArg($arg); } else { return $exec->arg($arg); } } - public function isVersionOne() + private function isRoboVersionOne() { - return $this->isVersionOne; + static $isVersionOne = null; + if ($isVersionOne === null) { + $isVersionOne = method_exists('Robo\Common\CommandArguments', 'rawArg'); + } + return $isVersionOne; } } diff --git a/src/Task/loadTasks.php b/src/Task/loadTasks.php deleted file mode 100644 index cd9a4df7..00000000 --- a/src/Task/loadTasks.php +++ /dev/null @@ -1,16 +0,0 @@ -isVersionOne() ? NonParallelExecV1::class : NonParallelExecV0::class); - if ($robo->isVersionOne()) { - return $this->task($class); - } else { - return new $class(); - } - } -} From 65701cfab4b35b71ab311311f4d124e88ccd845d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 23 Apr 2017 14:55:05 +0200 Subject: [PATCH 07/10] Robo - fix coding standard --- src/Task/NonParallelExecV0.php | 2 +- src/Task/NonParallelExecV1.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Task/NonParallelExecV0.php b/src/Task/NonParallelExecV0.php index 741b98b7..f6208283 100644 --- a/src/Task/NonParallelExecV0.php +++ b/src/Task/NonParallelExecV0.php @@ -14,7 +14,7 @@ class NonParallelExecV0 extends NonParallelExecV1 protected function startProgressIndicator() { $this->progress = new ProgressBar($this->getOutput()); - $this->progress->start(count($this->processes)); + $this->progress->start(count($this->processes)); } protected function advanceProgressIndicator() diff --git a/src/Task/NonParallelExecV1.php b/src/Task/NonParallelExecV1.php index 6bb895c3..2cfee50f 100644 --- a/src/Task/NonParallelExecV1.php +++ b/src/Task/NonParallelExecV1.php @@ -64,4 +64,4 @@ protected function printProcessResult(Process $process) $this->printTaskOutput(ConsoleLogLevel::ERROR, $process->getErrorOutput(), $this->getTaskContext()); } } -} \ No newline at end of file +} From 32a25cb20765c855a2512a96fd71a15e72066b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Tue, 25 Apr 2017 18:24:02 +0200 Subject: [PATCH 08/10] Robo - fix php compatibility --- src/Task/NonParallelExecV0.php | 4 ++-- src/Task/RoboAdapter.php | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Task/NonParallelExecV0.php b/src/Task/NonParallelExecV0.php index f6208283..b82b1acc 100644 --- a/src/Task/NonParallelExecV0.php +++ b/src/Task/NonParallelExecV0.php @@ -17,9 +17,9 @@ protected function startProgressIndicator() $this->progress->start(count($this->processes)); } - protected function advanceProgressIndicator() + protected function advanceProgressIndicator($steps = 1) { - $this->progress->advance(); + $this->progress->advance($steps); } protected function stopProgressIndicator() diff --git a/src/Task/RoboAdapter.php b/src/Task/RoboAdapter.php index b6a6d938..4fe79ff7 100644 --- a/src/Task/RoboAdapter.php +++ b/src/Task/RoboAdapter.php @@ -6,9 +6,12 @@ trait RoboAdapter { protected function taskPhpqaRunner($isParallel) { + $getClass = function ($class) { + return "Edge\QA\Task\\{$class}"; + }; $class = $isParallel - ? ParallelExec::class - : ($this->isRoboVersionOne() ? NonParallelExecV1::class : NonParallelExecV0::class); + ? $getClass('ParallelExec') + : ($this->isRoboVersionOne() ? $getClass('NonParallelExecV1') : $getClass('NonParallelExecV0')); if ($this->isRoboVersionOne()) { return $this->task($class); } else { From c056b4df96fdab196c1dcb7a871b4567edd3689e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Tue, 25 Apr 2017 18:39:41 +0200 Subject: [PATCH 09/10] Robo - fix returning exit code Exit code is 0 when robo->execute isn't auto-exited https://github.com/consolidation/Robo/blob/0.7.2/src/Runner.php#L91 https://github.com/consolidation/Robo/blob/1.0.6/src/Runner.php#L159 --- phpqa | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpqa b/phpqa index 52056078..28c2cd34 100755 --- a/phpqa +++ b/phpqa @@ -51,4 +51,5 @@ if ($isNotToolsCommand) { // run robo $robo = new QARunner('Edge\QA\RoboFile'); -$robo->execute($argv); +$result = $robo->execute($argv); +exit($result); From 752e6fc06223986365a85ba6c60d06e26638ec31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 7 May 2017 09:03:27 +0200 Subject: [PATCH 10/10] Robo - don't analyze compatibility classes with phpstan --- tests/.travis/phpstan.neon | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/.travis/phpstan.neon b/tests/.travis/phpstan.neon index 8d373274..e31f1f50 100644 --- a/tests/.travis/phpstan.neon +++ b/tests/.travis/phpstan.neon @@ -6,6 +6,10 @@ parameters: autoload_directories: - %currentWorkingDirectory%/tests autoload_files: - - %currentWorkingDirectory%/RoboFile.php + - %currentWorkingDirectory%/RoboFile.php + # exclude robo v0/v1 compatibility classes - it's not possible to analyze them with phsptan (only one robo version is installed) + excludes_analyse: + - %currentWorkingDirectory%/src/Task/NonParallelExecV0.php + - %currentWorkingDirectory%/src/Task/NonParallelExecV1.php ignoreErrors: - '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::[a-zA-Z0-9_]+\(\)#'