FEATURE: Allow multiple files to be used as insert for tests

* Detect file for php and TS out of the box.
* Keep old handling to configure file name.
* Also detect file format, e.g. TypoScript, and configure phpcs
  tokenizer accordingly.

Relates: #54
This commit is contained in:
Daniel Siepmann 2017-04-13 13:39:08 +02:00
parent 7a999212e2
commit 154fe43582
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4

View file

@ -114,6 +114,12 @@ class SniffsTest extends TestCase
*/ */
protected function executeSniff(\SplFileInfo $folder, array $arguments = []) protected function executeSniff(\SplFileInfo $folder, array $arguments = [])
{ {
$fileName = '';
if (isset($arguments['inputFileName'])) {
$fileName = $arguments['inputFileName'];
unset($arguments['inputFileName']);
}
$internalArguments = array_merge_recursive([ $internalArguments = array_merge_recursive([
'standard' => 'Typo3Update', 'standard' => 'Typo3Update',
'runtime-set' => [ 'runtime-set' => [
@ -123,14 +129,11 @@ class SniffsTest extends TestCase
], ],
'report' => 'json', 'report' => 'json',
'sniffs' => $this->getSniffByFolder($folder), 'sniffs' => $this->getSniffByFolder($folder),
'inputFile' => $folder->getRealPath() . DIRECTORY_SEPARATOR . 'InputFileForIssues.php', 'inputFile' => $this->getInputFile($folder, $fileName),
], $arguments); ], $arguments);
if (isset($internalArguments['inputFileName'])) { if (strpos($internalArguments['inputFile'], '.ts') !== false) {
$internalArguments['inputFile'] = $folder->getRealPath() $internalArguments['extensions'] = 'ts/TypoScript';
. DIRECTORY_SEPARATOR
. $internalArguments['inputFileName'];
unset($internalArguments['inputFileName']);
} }
$this->assertEquals( $this->assertEquals(
@ -229,6 +232,35 @@ class SniffsTest extends TestCase
return $folder->getRealPath() . DIRECTORY_SEPARATOR . 'Arguments.php'; return $folder->getRealPath() . DIRECTORY_SEPARATOR . 'Arguments.php';
} }
/**
* Get absolute file path to file to use for testing.
*
* @param \SplFileInfo $folder
* @param string $fileName
* @return string
*/
protected function getInputFile(\SplFileInfo $folder, $fileName = '')
{
$folderPath = $folder->getRealPath() . DIRECTORY_SEPARATOR;
$file = $folderPath . $fileName;
if (!is_file($file)) {
$file = $folderPath . $fileName;
}
if (!is_file($file)) {
$file = $folderPath . 'InputFileForIssues.php';
}
if (!is_file($file)) {
$file = $folderPath . 'InputFileForIssues.ts';
}
if (!is_file($file)) {
throw new \Exception('message', 1492083289);
}
return $file;
}
/** /**
* Build cli call for phpcs. * Build cli call for phpcs.
* *