Skip to content

Commit

Permalink
Merge pull request #2 from Sweetchuck/fix-ci
Browse files Browse the repository at this point in the history
Fix CI
  • Loading branch information
Sweetchuck committed Jul 1, 2018
2 parents 13ff23b + 3c3ec71 commit 191fe04
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 37 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"require": {
"php": ">=7.1",
"ext-pcre": "*",
"consolidation/robo": "^1.0",
"sweetchuck/cli-cmd-builder": "^0.0"
},
Expand Down
5 changes: 3 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/Task/LintInputTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ protected function processRunCallback(string $type, string $data): void
break;

case Process::ERR:
$data = preg_replace('/(?<= in )-(?= on line \d+)/', $this->currentFile['fileName'], $data);
$pattern = '/(?<= in )(-|Standard input code)(?= on line \d+)/';
$data = preg_replace($pattern, $this->currentFile['fileName'], $data);
$this->printTaskError($data);
break;
}
Expand Down
6 changes: 1 addition & 5 deletions tests/_support/Helper/RoboFiles/PhpLintRoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ class PhpLintRoboFile extends Tasks
*/
public function phpLintFilesDefault(
array $options = [
'workingDirectory' => '',
'parallelizer' => '',
'fileNamePatterns' => [],
]
): TaskInterface {
$lintOptions = array_filter(array_intersect_key(
$options,
array_flip([
'workingDirectory',
'parallelizer',
'fileNamePatterns',
])
Expand All @@ -44,20 +42,18 @@ public function phpLintFilesDefault(
*/
public function phpLintFilesCustom(
array $options = [
'workingDirectory' => '',
'parallelizer' => '',
'fileNamePattern' => '*.php',
]
): TaskInterface {
$fileListerCommand = sprintf(
'for fileName in %s; do echo -n $fileName"\\0"; done',
($options['workingDirectory'] ?: '.') . '/' . $options['fileNamePattern']
$options['fileNamePattern']
);

$lintOptions = array_intersect_key(
$options,
array_flip([
'workingDirectory',
'parallelizer',
'fileNamePatterns',
])
Expand Down
8 changes: 3 additions & 5 deletions tests/acceptance/Task/LintCestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Sweetchuck\Robo\PhpLint\Tests\Acceptance\Task;

use Webmozart\PathUtil\Path;

class LintCestBase
{
protected function getDefaultPhpDefinitions(): string
Expand All @@ -18,10 +20,6 @@ protected function getDefaultPhpDefinitions(): string

protected function getFixturesDir(): string
{
return preg_replace(
'/^' . preg_quote(getcwd() . '/', '/') . '/',
'',
codecept_data_dir('fixtures')
);
return Path::makeRelative(codecept_data_dir('fixtures'), getcwd());
}
}
225 changes: 215 additions & 10 deletions tests/acceptance/Task/LintFilesCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@

class LintFilesCest extends LintCestBase
{
public function phpLintFilesDefaultTrue(AcceptanceTester $I)
public function phpLintFilesDefaultTrueParallel(AcceptanceTester $I)
{
$fixturesDir = $this->getFixturesDir();
$id = 'php-lint:files:default:true';
$id = 'php-lint:files:default:true:parallel';
$I->runRoboTask(
$id,
PhpLintRoboFile::class,
'php-lint:files:default',
"--workingDirectory=$fixturesDir",
'--fileNamePatterns=./true.*.php'
"--fileNamePatterns=$fixturesDir/true.*.php"
);

$exitCode = $I->getRoboTaskExitCode($id);
Expand All @@ -28,7 +27,7 @@ public function phpLintFilesDefaultTrue(AcceptanceTester $I)
$expectedStdOutput = '';
$expectedStdError = implode(' ', [
' [PHP Lint files]',
"cd '$fixturesDir' && git ls-files -z -- './true.*.php'",
"git ls-files -z -- '$fixturesDir/true.*.php'",
'|',
'parallel --null',
"\"php -n $phpDefinitions -l {} 1>'/dev/null'",
Expand All @@ -39,16 +38,50 @@ public function phpLintFilesDefaultTrue(AcceptanceTester $I)
$I->assertContains($expectedStdError, $stdError);
}

public function phpLintFilesDefaultFalse(AcceptanceTester $I)
public function phpLintFilesDefaultTrueXargs(AcceptanceTester $I)
{
$fixturesDir = $this->getFixturesDir();
$id = 'php-lint:files:default:false';
$id = 'php-lint:files:default:true:xargs';
$I->runRoboTask(
$id,
PhpLintRoboFile::class,
'php-lint:files:default',
"--workingDirectory=$fixturesDir",
'--fileNamePatterns=./false.*.php'
"--fileNamePatterns=$fixturesDir/true.*.php",
'--parallelizer=xargs'
);

$exitCode = $I->getRoboTaskExitCode($id);
$stdOutput = $I->getRoboTaskStdOutput($id);
$stdError = $I->getRoboTaskStdError($id);

$phpDefinitions = $this->getDefaultPhpDefinitions();

$expectedStdOutput = implode(PHP_EOL, [
'No syntax errors detected in tests/_data/fixtures/true.01.php',
'No syntax errors detected in tests/_data/fixtures/true.02.php',
]);
$expectedStdError = implode(' ', [
' [PHP Lint files]',
"git ls-files -z -- '$fixturesDir/true.*.php'",
'|',
'xargs -0 --max-args=\'1\' --max-procs="$(nproc)"',
"php -n $phpDefinitions -l\n",
]);

$I->assertSame(0, $exitCode);
$I->assertSame($expectedStdOutput, $this->sortLines($stdOutput));
$I->assertStringStartsWith($expectedStdError, $stdError);
}

public function phpLintFilesDefaultFalseParallel(AcceptanceTester $I)
{
$fixturesDir = $this->getFixturesDir();
$id = 'php-lint:files:default:false:parallel';
$I->runRoboTask(
$id,
PhpLintRoboFile::class,
'php-lint:files:default',
"--fileNamePatterns=$fixturesDir/*.php"
);
$exitCode = $I->getRoboTaskExitCode($id);
$stdOutput = $I->getRoboTaskStdOutput($id);
Expand All @@ -60,7 +93,139 @@ public function phpLintFilesDefaultFalse(AcceptanceTester $I)
$expectedStdOutput = '';
$expectedStdError = implode(' ', [
' [PHP Lint files]',
"cd '$fixturesDir' && git ls-files -z -- './false.*.php'",
"git ls-files -z -- '$fixturesDir/*.php'",
'|',
'parallel --null',
"\"php -n $phpDefinitions -l {} 1>'/dev/null'",
]);

$I->assertSame($expectedExitCode, $exitCode);
$I->assertSame($expectedStdOutput, $stdOutput);
$I->assertContains($expectedStdError, $stdError);
}

public function phpLintFilesDefaultFalseXargs(AcceptanceTester $I)
{
$fixturesDir = $this->getFixturesDir();
$id = 'php-lint:files:default:false:xargs';
$I->runRoboTask(
$id,
PhpLintRoboFile::class,
'php-lint:files:default',
"--fileNamePatterns=$fixturesDir/*.php",
'--parallelizer=xargs'
);

$exitCode = $I->getRoboTaskExitCode($id);
$stdOutput = $I->getRoboTaskStdOutput($id);
$stdError = $I->getRoboTaskStdError($id);

$phpDefinitions = $this->getDefaultPhpDefinitions();

$expectedExitCode = 124;
$expectedStdOutput = implode(PHP_EOL, [
'Errors parsing tests/_data/fixtures/false.01.php',
'Errors parsing tests/_data/fixtures/false.02.php',
'No syntax errors detected in tests/_data/fixtures/true.01.php',
'No syntax errors detected in tests/_data/fixtures/true.02.php',
]);
$expectedStdError = implode(' ', [
' [PHP Lint files]',
"git ls-files -z -- '$fixturesDir/*.php'",
'|',
'xargs -0 --max-args=\'1\' --max-procs="$(nproc)"',
"php -n $phpDefinitions -l\n",
]);

$I->assertSame($expectedExitCode, $exitCode);
$I->assertSame($expectedStdOutput, $this->sortLines($stdOutput));
$I->assertStringStartsWith($expectedStdError, $stdError);
}

public function phpLintFilesCustomTrueParallel(AcceptanceTester $I)
{
$fixturesDir = $this->getFixturesDir();
$id = 'php-lint:files:custom:true:parallel';
$I->runRoboTask(
$id,
PhpLintRoboFile::class,
'php-lint:files:custom',
"--fileNamePattern=$fixturesDir/true.*.php"
);
$exitCode = $I->getRoboTaskExitCode($id);
$stdOutput = $I->getRoboTaskStdOutput($id);
$stdError = $I->getRoboTaskStdError($id);

$phpDefinitions = $this->getDefaultPhpDefinitions();

$expectedExitCode = 1;
$expectedStdOutput = '';
$expectedStdError = implode(' ', [
' [PHP Lint files]',
"for fileName in $fixturesDir/true.*.php; do echo -n \$fileName\"\\0\"; done",
'|',
'parallel --null',
"\"php -n $phpDefinitions -l {} 1>'/dev/null'",
]);

$I->assertSame($expectedExitCode, $exitCode);
$I->assertSame($expectedStdOutput, $stdOutput);
$I->assertContains($expectedStdError, $stdError);
}

public function phpLintFilesCustomTrueXargs(AcceptanceTester $I)
{
$fixturesDir = $this->getFixturesDir();
$id = 'php-lint:files:custom:true:xargs';
$I->runRoboTask(
$id,
PhpLintRoboFile::class,
'php-lint:files:custom',
"--fileNamePattern=$fixturesDir/true.*.php",
'--parallelizer=xargs'
);
$exitCode = $I->getRoboTaskExitCode($id);
$stdOutput = $I->getRoboTaskStdOutput($id);
$stdError = $I->getRoboTaskStdError($id);

$phpDefinitions = $this->getDefaultPhpDefinitions();

$expectedExitCode = 123;
$expectedStdOutput = '';
$expectedStdError = implode(' ', [
' [PHP Lint files]',
"for fileName in $fixturesDir/true.*.php; do echo -n \$fileName\"\\0\"; done",
'|',
'xargs -0 --max-args=\'1\' --max-procs="$(nproc)"',
"php -n $phpDefinitions -l" . PHP_EOL,
]);

$I->assertSame($expectedExitCode, $exitCode);
$I->assertSame($expectedStdOutput, $stdOutput);
$I->assertContains($expectedStdError, $stdError);
}

public function phpLintFilesCustomFalseParallel(AcceptanceTester $I)
{
$fixturesDir = $this->getFixturesDir();
$id = 'php-lint:files:custom:false:parallel';
$I->runRoboTask(
$id,
PhpLintRoboFile::class,
'php-lint:files:custom',
"--fileNamePattern=$fixturesDir/*.php"
);
$exitCode = $I->getRoboTaskExitCode($id);
$stdOutput = $I->getRoboTaskStdOutput($id);
$stdError = $I->getRoboTaskStdError($id);

$phpDefinitions = $this->getDefaultPhpDefinitions();

$expectedExitCode = 1;
$expectedStdOutput = '';
$expectedStdError = implode(' ', [
' [PHP Lint files]',
"for fileName in $fixturesDir/*.php; do echo -n \$fileName\"\\0\"; done",
'|',
'parallel --null',
"\"php -n $phpDefinitions -l {} 1>'/dev/null'",
Expand All @@ -70,4 +235,44 @@ public function phpLintFilesDefaultFalse(AcceptanceTester $I)
$I->assertSame($expectedStdOutput, $stdOutput);
$I->assertContains($expectedStdError, $stdError);
}

public function phpLintFilesCustomFalseXargs(AcceptanceTester $I)
{
$fixturesDir = $this->getFixturesDir();
$id = 'php-lint:files:custom:false:xargs';
$I->runRoboTask(
$id,
PhpLintRoboFile::class,
'php-lint:files:custom',
"--fileNamePattern=$fixturesDir/*.php",
'--parallelizer=xargs'
);
$exitCode = $I->getRoboTaskExitCode($id);
$stdOutput = $I->getRoboTaskStdOutput($id);
$stdError = $I->getRoboTaskStdError($id);

$phpDefinitions = $this->getDefaultPhpDefinitions();

$expectedExitCode = 123;
$expectedStdOutput = '';
$expectedStdError = implode(' ', [
' [PHP Lint files]',
"for fileName in $fixturesDir/*.php; do echo -n \$fileName\"\\0\"; done",
'|',
'xargs -0 --max-args=\'1\' --max-procs="$(nproc)"',
"php -n $phpDefinitions -l" . PHP_EOL,
]);

$I->assertSame($expectedExitCode, $exitCode);
$I->assertSame($expectedStdOutput, $stdOutput);
$I->assertContains($expectedStdError, $stdError);
}

protected function sortLines(string $text): string
{
$lines = explode(PHP_EOL, trim($text));
sort($lines);

return implode(PHP_EOL, $lines);
}
}
Loading

0 comments on commit 191fe04

Please sign in to comment.