Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Robo v1.X #61

Merged
merged 10 commits into from
May 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
class RoboFile extends \Robo\Tasks
{
use CodeAnalysisTasks;
use Task\RoboAdapter;
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions phpqa
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -51,4 +51,5 @@ if ($isNotToolsCommand) {

// run robo
$robo = new QARunner('Edge\QA\RoboFile');
$robo->execute($argv);
$result = $robo->execute($argv);
exit($result);
6 changes: 3 additions & 3 deletions src/CodeAnalysisTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private function ciClean()

private function runTools()
{
$group = $this->options->isParallel ? new Task\ParallelExec() : new Task\NonParallelExec();
$group = $this->taskPhpqaRunner($this->options->isParallel);
foreach ($this->usedTools as $tool) {
$exec = $this->toolToExec($tool);
$tool->process = $group->process($exec);
Expand All @@ -187,9 +187,9 @@ private function toolToExec(RunningTool $tool)
$method = str_replace('-', '', $tool);
foreach ($this->{$method}($tool) as $arg => $value) {
if (is_int($arg)) {
$process->arg($value);
$this->addArgToExec($process, $value);
} else {
$process->arg($tool->buildOption($arg, $value));
$this->addArgToExec($process, $tool->buildOption($arg, $value));
}
}
return $process;
Expand Down
41 changes: 41 additions & 0 deletions src/Task/NonParallelExecV0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Edge\QA\Task;

use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;

// Adapter for Robo v0.X
class NonParallelExecV0 extends NonParallelExecV1
{
private $progress;

protected function startProgressIndicator()
{
$this->progress = new ProgressBar($this->getOutput());
$this->progress->start(count($this->processes));
}

protected function advanceProgressIndicator($steps = 1)
{
$this->progress->advance($steps);
}

protected function stopProgressIndicator()
{
$this->getOutput()->writeln("");
}

protected function printProcessResult(Process $process)
{
$this->getOutput()->writeln("");
$this->printTaskInfo(
"Output for <fg=white;bg=magenta> " . $process->getCommandLine()." </fg=white;bg=magenta>"
);
$this->getOutput()->writeln($process->getOutput(), OutputInterface::OUTPUT_RAW);
if ($process->getErrorOutput()) {
$this->getOutput()->writeln("<error>" . $process->getErrorOutput() . "</error>");
}
}
}
33 changes: 18 additions & 15 deletions src/Task/NonParallelExec.php → src/Task/NonParallelExecV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -16,34 +16,26 @@
* - 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()
{
foreach ($this->processes as $process) {
$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 <fg=white;bg=magenta> " . $process->getCommandLine()." </fg=white;bg=magenta>"
);
$this->getOutput()->writeln($process->getOutput(), OutputInterface::OUTPUT_RAW);
if ($process->getErrorOutput()) {
$this->getOutput()->writeln("<error>" . $process->getErrorOutput() . "</error>");
}
$this->printProcessResult($process);
}
}

$this->getOutput()->writeln("");
$this->stopProgressIndicator();
$this->stopTimer();

$errorMessage = '';
Expand All @@ -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 <fg=white;bg=magenta> " . $process->getCommandLine()." </fg=white;bg=magenta>"
);
$this->printTaskOutput(ConsoleLogLevel::SUCCESS, $process->getOutput(), $this->getTaskContext());
if ($process->getErrorOutput()) {
$this->printTaskOutput(ConsoleLogLevel::ERROR, $process->getErrorOutput(), $this->getTaskContext());
}
}
}
39 changes: 39 additions & 0 deletions src/Task/RoboAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Edge\QA\Task;

trait RoboAdapter
{
protected function taskPhpqaRunner($isParallel)
{
$getClass = function ($class) {
return "Edge\QA\Task\\{$class}";
};
$class = $isParallel
? $getClass('ParallelExec')
: ($this->isRoboVersionOne() ? $getClass('NonParallelExecV1') : $getClass('NonParallelExecV0'));
if ($this->isRoboVersionOne()) {
return $this->task($class);
} else {
return new $class();
}
}

protected function addArgToExec($exec, $arg)
{
if ($this->isRoboVersionOne()) {
return $exec->rawArg($arg);
} else {
return $exec->arg($arg);
}
}

private function isRoboVersionOne()
{
static $isVersionOne = null;
if ($isVersionOne === null) {
$isVersionOne = method_exists('Robo\Common\CommandArguments', 'rawArg');
}
return $isVersionOne;
}
}
6 changes: 5 additions & 1 deletion tests/.travis/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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_]+\(\)#'