TASK: Refactor, follow CS and add more info on error

Relates: #46
This commit is contained in:
Daniel Siepmann 2017-04-06 16:00:44 +02:00
parent 65512dcd1d
commit e957e5fe18
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4

View file

@ -99,28 +99,30 @@ class SniffsTest extends TestCase
], $arguments); ], $arguments);
if (isset($internalArguments['inputFileName'])) { if (isset($internalArguments['inputFileName'])) {
$internalArguments['inputFile'] = $folder->getRealPath() . DIRECTORY_SEPARATOR . $internalArguments['inputFileName']; $internalArguments['inputFile'] = $folder->getRealPath()
. DIRECTORY_SEPARATOR
. $internalArguments['inputFileName'];
unset($internalArguments['inputFileName']); unset($internalArguments['inputFileName']);
} }
$this->assertEquals( $this->assertEquals(
$this->getExpectedJsonOutput($folder), $this->getExpectedJsonOutput($folder),
$this->getOutput($folder, $internalArguments)['output'], $this->getOutput($internalArguments)['output'],
'Checking Sniff "' . $this->getSniffByFolder($folder) . '"' 'Checking Sniff "' . $this->getSniffByFolder($folder) . '"'
. ' did not produce expected output for input file ' . ' did not produce expected output for input file '
. $internalArguments['inputFile'] . $internalArguments['inputFile']
. ' called: ' . $this->getPhpcsCall($folder, $internalArguments) . ' called: ' . $this->getPhpcsCall($internalArguments)
); );
try { try {
$internalArguments['report'] = 'diff'; $internalArguments['report'] = 'diff';
$this->assertEquals( $this->assertEquals(
$this->getExpectedDiffOutput($folder), $this->getExpectedDiffOutput($folder),
$this->getOutput($folder, $internalArguments)['output'], $this->getOutput($internalArguments)['output'],
'Fixing Sniff "' . $this->getSniffByFolder($folder) . '"' 'Fixing Sniff "' . $this->getSniffByFolder($folder) . '"'
. ' did not produce expected diff for input file ' . ' did not produce expected diff for input file '
. $internalArguments['inputFile'] . $internalArguments['inputFile']
. ' called: ' . $this->getPhpcsCall($folder, $internalArguments) . ' called: ' . $this->getPhpcsCall($internalArguments)
); );
} catch (FileNotFoundException $e) { } catch (FileNotFoundException $e) {
// Ok, ignore, we don't have an diff. // Ok, ignore, we don't have an diff.
@ -202,11 +204,10 @@ class SniffsTest extends TestCase
/** /**
* Build cli call for phpcs. * Build cli call for phpcs.
* *
* @param SplFileInfo $folder
* @param array $arguments * @param array $arguments
* @return string * @return string
*/ */
protected function getPhpcsCall(SplFileInfo $folder, array $arguments) protected function getPhpcsCall(array $arguments)
{ {
$bin = './vendor/bin/phpcs'; $bin = './vendor/bin/phpcs';
$preparedArguments = []; $preparedArguments = [];
@ -233,18 +234,25 @@ class SniffsTest extends TestCase
/** /**
* Executes phpcs for sniff based on $folder and returns the generated output. * Executes phpcs for sniff based on $folder and returns the generated output.
* *
* @param SplFileInfo $folder
* @param array $arguments * @param array $arguments
* @return array * @return array
*/ */
protected function getOutput(SplFileInfo $folder, array $arguments) protected function getOutput(array $arguments)
{ {
$output = ''; $output = '';
$returnValue; $returnValue;
exec($this->getPhpcsCall($folder, $arguments), $output, $returnValue); exec($this->getPhpcsCall($arguments), $output, $returnValue);
if ($arguments['report'] === 'json') { if ($arguments['report'] === 'json') {
try {
$output = $this->prepareJsonOutput($output); $output = $this->prepareJsonOutput($output);
} catch (\Exception $e) {
throw new \Exception(
'Error during preparing json output by invoking '
. $this->getPhpcsCall($arguments) . ' ' . $output,
1491487079
);
}
} if ($arguments['report'] === 'diff') { } if ($arguments['report'] === 'diff') {
$output = $this->prepareDiffOutput($output); $output = $this->prepareDiffOutput($output);
} }