diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..c20385f --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,23 @@ + + + + + + ./tests/ + + + + + + ./src/ + + + diff --git a/tests/FileNotFoundException.php b/tests/FileNotFoundException.php new file mode 100644 index 0000000..3aba4a6 --- /dev/null +++ b/tests/FileNotFoundException.php @@ -0,0 +1,26 @@ + + * + * 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. + */ + +class FileNotFoundException extends \Exception +{ +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff/Expected.json new file mode 100644 index 0000000..9b17ce4 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff/Expected.json @@ -0,0 +1,69 @@ +{ + "files": { + "InputFileForIssues.php": { + "errors": 6, + "messages": [ + { + "column": 34, + "fixable": true, + "line": 22, + "message": "Legacy classes are not allowed; found \"Tx_Extbase_Configuration_Configurationmanager\", use \"TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager\" instead", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.Inheritance.legacyClassname", + "type": "ERROR" + }, + { + "column": 91, + "fixable": true, + "line": 22, + "message": "Legacy classes are not allowed; found \"t3lib_Singleton\", use \"TYPO3\\CMS\\Core\\SingletonInterface\" instead", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.Inheritance.legacyClassname", + "type": "ERROR" + }, + { + "column": 108, + "fixable": true, + "line": 22, + "message": "Legacy classes are not allowed; found \"Tx_Extbase_Core_BootstrapInterface\", use \"TYPO3\\CMS\\Extbase\\Core\\BootstrapInterface\" instead", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.Inheritance.legacyClassname", + "type": "ERROR" + }, + { + "column": 34, + "fixable": true, + "line": 27, + "message": "Legacy classes are not allowed; found \"Tx_Extbase_Configuration_Configurationmanager\", use \"TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager\" instead", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.Inheritance.legacyClassname", + "type": "ERROR" + }, + { + "column": 5, + "fixable": true, + "line": 28, + "message": "Legacy classes are not allowed; found \"t3lib_Singleton\", use \"TYPO3\\CMS\\Core\\SingletonInterface\" instead", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.Inheritance.legacyClassname", + "type": "ERROR" + }, + { + "column": 5, + "fixable": true, + "line": 29, + "message": "Legacy classes are not allowed; found \"Tx_Extbase_Core_BootstrapInterface\", use \"TYPO3\\CMS\\Extbase\\Core\\BootstrapInterface\" instead", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.Inheritance.legacyClassname", + "type": "ERROR" + } + ], + "warnings": 0 + } + }, + "totals": { + "errors": 6, + "fixable": 6, + "warnings": 0 + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff/InputFileForIssues.php new file mode 100644 index 0000000..ee8fd0f --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff/InputFileForIssues.php @@ -0,0 +1,32 @@ + + * + * 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. + */ + +class InputFileForIssues extends Tx_Extbase_Configuration_Configurationmanager implements t3lib_Singleton, Tx_Extbase_Core_BootstrapInterface +{ + +} + +class InputFileForIssues extends Tx_Extbase_Configuration_Configurationmanager implements + t3lib_Singleton, + Tx_Extbase_Core_BootstrapInterface +{ + +} diff --git a/tests/SniffsTest.php b/tests/SniffsTest.php index 7995d35..6223650 100644 --- a/tests/SniffsTest.php +++ b/tests/SniffsTest.php @@ -66,18 +66,24 @@ class SniffsTest extends TestCase $this->assertEquals( $this->getExpectedJsonOutput($folder), $this->getOutput($folder, 'json')['output'], - 'Sniff ' . $this->getSniffByFolder($folder) + 'Checking Sniff "' . $this->getSniffByFolder($folder) . '"' . ' did not produce expected output for input file ' . $this->getInputFile($folder) + . ' called: ' . $this->getPhpcsCall($folder, 'json') ); - $this->assertEquals( - $this->getExpectedDiffOutput($folder), - $this->getOutput($folder, 'diff')['output'], - 'Sniff ' . $this->getSniffByFolder($folder) - . ' did not produce expected diff for input file ' - . $this->getInputFile($folder) - ); + try { + $this->assertEquals( + $this->getExpectedDiffOutput($folder), + $this->getOutput($folder, 'diff')['output'], + 'Fixing Sniff "' . $this->getSniffByFolder($folder) . '"' + . ' did not produce expected diff for input file ' + . $this->getInputFile($folder) + . ' called: ' . $this->getPhpcsCall($folder, 'diff') + ); + } catch (FileNotFoundException $e) { + // Ok, ignore, we don't have an diff. + } } /** @@ -99,10 +105,17 @@ class SniffsTest extends TestCase * * @param SplFileInfo $folder * @return string + * + * @throws FileNotFoundException */ protected function getExpectedDiffOutput(SplFileInfo $folder) { - return file_get_contents($folder->getRealPath() . DIRECTORY_SEPARATOR . 'Expected.diff'); + $file = $folder->getRealPath() . DIRECTORY_SEPARATOR . 'Expected.diff'; + if (!is_file($file)) { + throw new FileNotFoundException('File does not exist.', 1491469621); + } + + return file_get_contents($file); } /** @@ -131,6 +144,25 @@ class SniffsTest extends TestCase return $folder->getRealPath() . DIRECTORY_SEPARATOR . 'InputFileForIssues.php'; } + /** + * Build cli call for phpcs. + * + * @param SplFileInfo $folder + * @param string $report Defined the report format to use for output. + * @return string + */ + protected function getPhpcsCall(SplFileInfo $folder, $report) + { + $bin = './vendor/bin/phpcs'; + $arguments = '--sniffs=' . $this->getSniffByFolder($folder) + . ' --report=' . $report + . ' ' + . $this->getInputFile($folder) + ; + + return $bin . ' ' . $arguments; + } + /** * Executes phpcs for sniff based on $folder and returns the generated output. * @@ -140,16 +172,9 @@ class SniffsTest extends TestCase */ protected function getOutput(SplFileInfo $folder, $report) { - $bin = './vendor/bin/phpcs'; - $arguments = '--sniffs=' . $this->getSniffByFolder($folder) - . ' --report=' . $report - . ' ' - . $this->getInputFile($folder) - ; $output = ''; $returnValue; - - exec($bin . ' ' . $arguments, $output, $returnValue); + exec($this->getPhpcsCall($folder, $report), $output, $returnValue); if ($report === 'json') { $output = $this->prepareJsonOutput($output);