FEATURE: Allow to overwrite cli arguments for test
* Enable overwriting using Arguments.php. * Add multiple sub tests for AjaxRegistrationSniff. Relates: #46
This commit is contained in:
parent
63d48e01fa
commit
0703167315
6 changed files with 237 additions and 29 deletions
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
return [
|
||||||
|
'ext_tables' => [
|
||||||
|
'inputFileName' => 'ext_tables.php',
|
||||||
|
],
|
||||||
|
'ext_localconf' => [
|
||||||
|
'inputFileName' => 'ext_localconf.php',
|
||||||
|
],
|
||||||
|
];
|
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"files": {
|
||||||
|
"ext_localconf.php": {
|
||||||
|
"errors": 0,
|
||||||
|
"messages": [
|
||||||
|
{
|
||||||
|
"column": 54,
|
||||||
|
"fixable": false,
|
||||||
|
"line": 22,
|
||||||
|
"message": "Defining AJAX using $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'][$ajaxID] is no longer supported with a single String like 'something'. Since TYPO3 7.6, use PSR-7-based Routing for Backend AJAX Requests. See: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.6/Feature-69916-PSR-7-basedRoutingForBackendAJAXRequests.html",
|
||||||
|
"severity": 5,
|
||||||
|
"source": "Typo3Update.Deprecated.AjaxRegistration",
|
||||||
|
"type": "WARNING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"column": 54,
|
||||||
|
"fixable": false,
|
||||||
|
"line": 23,
|
||||||
|
"message": "Defining AJAX using $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'][$ajaxID] is no longer supported with a single String like \"something\". Since TYPO3 7.6, use PSR-7-based Routing for Backend AJAX Requests. See: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.6/Feature-69916-PSR-7-basedRoutingForBackendAJAXRequests.html",
|
||||||
|
"severity": 5,
|
||||||
|
"source": "Typo3Update.Deprecated.AjaxRegistration",
|
||||||
|
"type": "WARNING"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"warnings": 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"totals": {
|
||||||
|
"errors": 0,
|
||||||
|
"fixable": 0,
|
||||||
|
"warnings": 2
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
$GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'][$ajaxID] = 'something';
|
||||||
|
$GLOBALS["TYPO3_CONF_VARS"]["BE"]["AJAX"][$ajaxID] = "something";
|
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"files": {
|
||||||
|
"ext_tables.php": {
|
||||||
|
"errors": 0,
|
||||||
|
"messages": [
|
||||||
|
{
|
||||||
|
"column": 54,
|
||||||
|
"fixable": false,
|
||||||
|
"line": 22,
|
||||||
|
"message": "Defining AJAX using $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'][$ajaxID] is no longer supported with a single String like 'something'. Since TYPO3 7.6, use PSR-7-based Routing for Backend AJAX Requests. See: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.6/Feature-69916-PSR-7-basedRoutingForBackendAJAXRequests.html",
|
||||||
|
"severity": 5,
|
||||||
|
"source": "Typo3Update.Deprecated.AjaxRegistration",
|
||||||
|
"type": "WARNING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"column": 54,
|
||||||
|
"fixable": false,
|
||||||
|
"line": 23,
|
||||||
|
"message": "Defining AJAX using $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'][$ajaxID] is no longer supported with a single String like \"something\". Since TYPO3 7.6, use PSR-7-based Routing for Backend AJAX Requests. See: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.6/Feature-69916-PSR-7-basedRoutingForBackendAJAXRequests.html",
|
||||||
|
"severity": 5,
|
||||||
|
"source": "Typo3Update.Deprecated.AjaxRegistration",
|
||||||
|
"type": "WARNING"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"warnings": 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"totals": {
|
||||||
|
"errors": 0,
|
||||||
|
"fixable": 0,
|
||||||
|
"warnings": 2
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
$GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'][$ajaxID] = 'something';
|
||||||
|
$GLOBALS["TYPO3_CONF_VARS"]["BE"]["AJAX"][$ajaxID] = "something";
|
|
@ -51,35 +51,76 @@ class SniffsTest extends TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($finder->directories()->name('*Sniff') as $folder) {
|
foreach ($finder->directories()->name('*Sniff') as $folder) {
|
||||||
|
if (is_file($this->getArgumentsFile($folder))) {
|
||||||
|
$arguments = require $this->getArgumentsFile($folder);
|
||||||
|
$this->executeSniffSubfolders($folder, $arguments);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$this->executeSniff($folder);
|
$this->executeSniff($folder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute sniff using subfolders.
|
||||||
|
*
|
||||||
|
* @param SplFileInfo $folder
|
||||||
|
* @param array $arguments
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function executeSniffSubfolders(SplFileInfo $folder, array $arguments = [])
|
||||||
|
{
|
||||||
|
$finder = new Finder();
|
||||||
|
$finder->in($folder->getRealPath());
|
||||||
|
|
||||||
|
foreach ($arguments as $subFolder => $values) {
|
||||||
|
$folderName = $folder->getRealPath() . DIRECTORY_SEPARATOR . $subFolder;
|
||||||
|
$this->executeSniff(new SplFileInfo($folderName, $folderName, $folderName), $values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute phpunit assertion for sniff based on $folder.
|
* Execute phpunit assertion for sniff based on $folder.
|
||||||
*
|
*
|
||||||
* @param SplFileInfo $folder
|
* @param SplFileInfo $folder
|
||||||
|
* @param array $arguments
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function executeSniff(SplFileInfo $folder)
|
protected function executeSniff(SplFileInfo $folder, array $arguments = [])
|
||||||
{
|
{
|
||||||
|
$internalArguments = array_merge([
|
||||||
|
'runtime-set' => 'mappingFile '
|
||||||
|
. __DIR__ . DIRECTORY_SEPARATOR
|
||||||
|
. 'Fixtures' . DIRECTORY_SEPARATOR
|
||||||
|
. 'LegacyClassnames.php',
|
||||||
|
'report' => 'json',
|
||||||
|
'sniffs' => $this->getSniffByFolder($folder),
|
||||||
|
'inputFile' => $folder->getRealPath() . DIRECTORY_SEPARATOR . 'InputFileForIssues.php',
|
||||||
|
], $arguments);
|
||||||
|
|
||||||
|
if (isset($internalArguments['inputFileName'])) {
|
||||||
|
$internalArguments['inputFile'] = $folder->getRealPath() . DIRECTORY_SEPARATOR . $internalArguments['inputFileName'];
|
||||||
|
unset($internalArguments['inputFileName']);
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$this->getExpectedJsonOutput($folder),
|
$this->getExpectedJsonOutput($folder),
|
||||||
$this->getOutput($folder, 'json')['output'],
|
$this->getOutput($folder, $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 '
|
||||||
. $this->getInputFile($folder)
|
. $internalArguments['inputFile']
|
||||||
. ' called: ' . $this->getPhpcsCall($folder, 'json')
|
. ' called: ' . $this->getPhpcsCall($folder, $internalArguments)
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$internalArguments['report'] = 'diff';
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$this->getExpectedDiffOutput($folder),
|
$this->getExpectedDiffOutput($folder),
|
||||||
$this->getOutput($folder, 'diff')['output'],
|
$this->getOutput($folder, $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 '
|
||||||
. $this->getInputFile($folder)
|
. $internalArguments['inputFile']
|
||||||
. ' called: ' . $this->getPhpcsCall($folder, 'diff')
|
. ' called: ' . $this->getPhpcsCall($folder, $internalArguments)
|
||||||
);
|
);
|
||||||
} catch (FileNotFoundException $e) {
|
} catch (FileNotFoundException $e) {
|
||||||
// Ok, ignore, we don't have an diff.
|
// Ok, ignore, we don't have an diff.
|
||||||
|
@ -126,61 +167,83 @@ class SniffsTest extends TestCase
|
||||||
*/
|
*/
|
||||||
protected function getSniffByFolder(SplFileInfo $folder)
|
protected function getSniffByFolder(SplFileInfo $folder)
|
||||||
{
|
{
|
||||||
$folderParts = explode(DIRECTORY_SEPARATOR, $folder->getPath());
|
$folderParts = array_filter(explode(DIRECTORY_SEPARATOR, $folder->getPathName()));
|
||||||
|
$sniffNamePosition;
|
||||||
|
|
||||||
return array_slice($folderParts, -3)[0]
|
foreach ($folderParts as $index => $folderPart) {
|
||||||
. '.' . array_slice($folderParts, -1)[0]
|
if (strpos($folderPart, 'Sniff', 1) !== false) {
|
||||||
. '.' . substr($folder->getFilename(), 0, -5);
|
$sniffNamePosition = $index;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($sniffNamePosition === null) {
|
||||||
|
throw new \Exception('Could not detect sniff name by folder: ' . var_export($folder, true), 1491485369);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $folderParts[$sniffNamePosition - 3]
|
||||||
|
. '.' . $folderParts[$sniffNamePosition - 1]
|
||||||
|
. '.' . substr($folderParts[$sniffNamePosition], 0, -5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns file to use as input for phpcs.
|
* Get absolute file path to file containing further arguments.
|
||||||
*
|
*
|
||||||
* @param SplFileInfo $folder
|
* @param SplFileInfo $folder
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getInputFile(SplFileInfo $folder)
|
protected function getArgumentsFile(SplFileInfo $folder)
|
||||||
{
|
{
|
||||||
return $folder->getRealPath() . DIRECTORY_SEPARATOR . 'InputFileForIssues.php';
|
return $folder->getRealPath() . DIRECTORY_SEPARATOR . 'Arguments.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build cli call for phpcs.
|
* Build cli call for phpcs.
|
||||||
*
|
*
|
||||||
* @param SplFileInfo $folder
|
* @param SplFileInfo $folder
|
||||||
* @param string $report Defined the report format to use for output.
|
* @param array $arguments
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getPhpcsCall(SplFileInfo $folder, $report)
|
protected function getPhpcsCall(SplFileInfo $folder, array $arguments)
|
||||||
{
|
{
|
||||||
$bin = './vendor/bin/phpcs';
|
$bin = './vendor/bin/phpcs';
|
||||||
$arguments = '--sniffs=' . $this->getSniffByFolder($folder)
|
$preparedArguments = [];
|
||||||
. ' --report=' . $report
|
|
||||||
. ' --runtime-set mappingFile '
|
|
||||||
. __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'LegacyClassnames.php'
|
|
||||||
. ' '
|
|
||||||
. $this->getInputFile($folder)
|
|
||||||
;
|
|
||||||
|
|
||||||
return $bin . ' ' . $arguments;
|
foreach ($arguments as $argumentName => $argumentValue) {
|
||||||
|
if ($argumentName === 'inputFile') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prefix = "--$argumentName=";
|
||||||
|
if (in_array($argumentName, ['runtime-set'])) {
|
||||||
|
$prefix = "--$argumentName ";
|
||||||
|
}
|
||||||
|
|
||||||
|
$preparedArguments[] = "$prefix$argumentValue";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bin
|
||||||
|
. ' ' . implode(' ', $preparedArguments)
|
||||||
|
. ' ' . $arguments['inputFile']
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 SplFileInfo $folder
|
||||||
* @param string $report Defined the report format to use for output.
|
* @param array $arguments
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getOutput(SplFileInfo $folder, $report)
|
protected function getOutput(SplFileInfo $folder, array $arguments)
|
||||||
{
|
{
|
||||||
$output = '';
|
$output = '';
|
||||||
$returnValue;
|
$returnValue;
|
||||||
exec($this->getPhpcsCall($folder, $report), $output, $returnValue);
|
exec($this->getPhpcsCall($folder, $arguments), $output, $returnValue);
|
||||||
|
|
||||||
if ($report === 'json') {
|
if ($arguments['report'] === 'json') {
|
||||||
$output = $this->prepareJsonOutput($output);
|
$output = $this->prepareJsonOutput($output);
|
||||||
} if ($report === 'diff') {
|
} if ($arguments['report'] === 'diff') {
|
||||||
$output = $this->prepareDiffOutput($output);
|
$output = $this->prepareDiffOutput($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,6 +263,10 @@ class SniffsTest extends TestCase
|
||||||
{
|
{
|
||||||
$preparedOutput = json_decode($output[0], true);
|
$preparedOutput = json_decode($output[0], true);
|
||||||
|
|
||||||
|
if ($preparedOutput === null) {
|
||||||
|
throw new \Exception('Output for phpcs was not valid json: ' . var_export($output, true), 1491485173);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (array_keys($preparedOutput['files']) as $fileName) {
|
foreach (array_keys($preparedOutput['files']) as $fileName) {
|
||||||
$newKey = basename($fileName);
|
$newKey = basename($fileName);
|
||||||
$preparedOutput['files'][$newKey] = $preparedOutput['files'][$fileName];
|
$preparedOutput['files'][$newKey] = $preparedOutput['files'][$fileName];
|
||||||
|
|
Loading…
Reference in a new issue