From 958086da244e6168edaa48ffd74d167d82c32342 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 6 Apr 2017 15:48:37 +0200 Subject: [PATCH] FEATURE: Add tests for MissingVendorForPluginsAndModulesSniff * With custom vendor and default vendor. Relates: #46 --- .../Arguments.php | 27 ++++ .../customVendor/Expected.diff | 52 ++++++++ .../customVendor/Expected.json | 69 ++++++++++ .../{ => customVendor}/InputFileForIssues.php | 0 .../{ => defaultVendor}/Expected.diff | 2 +- .../{ => defaultVendor}/Expected.json | 0 .../defaultVendor/InputFileForIssues.php | 118 ++++++++++++++++++ tests/SniffsTest.php | 10 +- 8 files changed, 273 insertions(+), 5 deletions(-) create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/Arguments.php create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/customVendor/Expected.diff create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/customVendor/Expected.json rename tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/{ => customVendor}/InputFileForIssues.php (100%) rename tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/{ => defaultVendor}/Expected.diff (93%) rename tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/{ => defaultVendor}/Expected.json (100%) create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/defaultVendor/InputFileForIssues.php diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/Arguments.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/Arguments.php new file mode 100644 index 0000000..e4121c8 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/Arguments.php @@ -0,0 +1,27 @@ + + * + * 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 [ + 'defaultVendor' => [], + 'customVendor' => [ + 'runtime-set' => 'vendor MyCustomVendor', + ], +]; diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/customVendor/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/customVendor/Expected.diff new file mode 100644 index 0000000..22d4fa8 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/customVendor/Expected.diff @@ -0,0 +1,52 @@ +--- tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/customVendor/InputFileForIssues.php ++++ PHP_CodeSniffer +@@ -20,7 +20,7 @@ + */ + + TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin( +- $_EXTKEY, ++ 'MyCustomVendor.' . $_EXTKEY, + 'name', + [ + 'Controller' => 'action', +@@ -28,7 +28,7 @@ + ); + + Tx_Extbase_Utility_Extension::configurePlugin( +- $_EXTKEY, ++ 'MyCustomVendor.' . $_EXTKEY, + 'name', + [ + 'Controller' => 'action', +@@ -36,19 +36,19 @@ + ); + + Tx_Extbase_Utility_Extension::registerPlugin( +- $_EXTKEY, ++ 'MyCustomVendor.' . $_EXTKEY, + 'name', + 'title' + ); + + TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin( +- $_EXTKEY, ++ 'MyCustomVendor.' . $_EXTKEY, + 'name', + 'title' + ); + + Tx_Extbase_Utility_Extension::registerModule( +- $_EXTKEY, ++ 'MyCustomVendor.' . $_EXTKEY, + 'subpart', + 'key' + '', +@@ -58,7 +58,7 @@ + ); + + \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule( +- $_EXTKEY, ++ 'MyCustomVendor.' . $_EXTKEY, + 'subpart', + 'key' + '', diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/customVendor/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/customVendor/Expected.json new file mode 100644 index 0000000..c46162f --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/customVendor/Expected.json @@ -0,0 +1,69 @@ +{ + "files": { + "InputFileForIssues.php": { + "errors": 6, + "messages": [ + { + "column": 5, + "fixable": true, + "line": 23, + "message": "No vendor is given, that will break TYPO3 handling for namespaced classes. Add vendor before Extensionkey like: \"MyCustomVendor.\" . $_EXTKEY", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.MissingVendorForPluginsAndModules.missingVendor", + "type": "ERROR" + }, + { + "column": 5, + "fixable": true, + "line": 31, + "message": "No vendor is given, that will break TYPO3 handling for namespaced classes. Add vendor before Extensionkey like: \"MyCustomVendor.\" . $_EXTKEY", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.MissingVendorForPluginsAndModules.missingVendor", + "type": "ERROR" + }, + { + "column": 5, + "fixable": true, + "line": 39, + "message": "No vendor is given, that will break TYPO3 handling for namespaced classes. Add vendor before Extensionkey like: \"MyCustomVendor.\" . $_EXTKEY", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.MissingVendorForPluginsAndModules.missingVendor", + "type": "ERROR" + }, + { + "column": 5, + "fixable": true, + "line": 45, + "message": "No vendor is given, that will break TYPO3 handling for namespaced classes. Add vendor before Extensionkey like: \"MyCustomVendor.\" . $_EXTKEY", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.MissingVendorForPluginsAndModules.missingVendor", + "type": "ERROR" + }, + { + "column": 5, + "fixable": true, + "line": 51, + "message": "No vendor is given, that will break TYPO3 handling for namespaced classes. Add vendor before Extensionkey like: \"MyCustomVendor.\" . $_EXTKEY", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.MissingVendorForPluginsAndModules.missingVendor", + "type": "ERROR" + }, + { + "column": 5, + "fixable": true, + "line": 61, + "message": "No vendor is given, that will break TYPO3 handling for namespaced classes. Add vendor before Extensionkey like: \"MyCustomVendor.\" . $_EXTKEY", + "severity": 5, + "source": "Typo3Update.LegacyClassnames.MissingVendorForPluginsAndModules.missingVendor", + "type": "ERROR" + } + ], + "warnings": 0 + } + }, + "totals": { + "errors": 6, + "fixable": 6, + "warnings": 0 + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/customVendor/InputFileForIssues.php similarity index 100% rename from tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/InputFileForIssues.php rename to tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/customVendor/InputFileForIssues.php diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/defaultVendor/Expected.diff similarity index 93% rename from tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/Expected.diff rename to tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/defaultVendor/Expected.diff index 30eec72..2faa023 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/Expected.diff +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/defaultVendor/Expected.diff @@ -1,4 +1,4 @@ ---- tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/InputFileForIssues.php +--- tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/defaultVendor/InputFileForIssues.php +++ PHP_CodeSniffer @@ -20,7 +20,7 @@ */ diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/defaultVendor/Expected.json similarity index 100% rename from tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/Expected.json rename to tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/defaultVendor/Expected.json diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/defaultVendor/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/defaultVendor/InputFileForIssues.php new file mode 100644 index 0000000..65d0d16 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff/defaultVendor/InputFileForIssues.php @@ -0,0 +1,118 @@ + + * + * 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. + */ + +TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin( + $_EXTKEY, + 'name', + [ + 'Controller' => 'action', + ] +); + +Tx_Extbase_Utility_Extension::configurePlugin( + $_EXTKEY, + 'name', + [ + 'Controller' => 'action', + ] +); + +Tx_Extbase_Utility_Extension::registerPlugin( + $_EXTKEY, + 'name', + 'title' +); + +TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin( + $_EXTKEY, + 'name', + 'title' +); + +Tx_Extbase_Utility_Extension::registerModule( + $_EXTKEY, + 'subpart', + 'key' + '', + [ + 'Controller' => 'action', + ] +); + +\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule( + $_EXTKEY, + 'subpart', + 'key' + '', + [ + 'Controller' => 'action', + ] +); + +// Already vendor exists + +TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin( + 'Vendor.' . $_EXTKEY, + 'name', + [ + 'Controller' => 'action', + ] +); + +Tx_Extbase_Utility_Extension::configurePlugin( + 'Vendor.' . $_EXTKEY, + 'name', + [ + 'Controller' => 'action', + ] +); + +Tx_Extbase_Utility_Extension::registerPlugin( + 'Vendor.' . $_EXTKEY, + 'name', + 'title' +); + +TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin( + 'Vendor.' . $_EXTKEY, + 'name', + 'title' +); + +Tx_Extbase_Utility_Extension::registerModule( + 'Vendor.' . $_EXTKEY, + 'subpart', + 'key' + '', + [ + 'Controller' => 'action', + ] +); + +\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule( + 'Vendor.' . $_EXTKEY, + 'subpart', + 'key' + '', + [ + 'Controller' => 'action', + ] +); diff --git a/tests/SniffsTest.php b/tests/SniffsTest.php index 4a1e4f7..915ae86 100644 --- a/tests/SniffsTest.php +++ b/tests/SniffsTest.php @@ -135,10 +135,12 @@ class SniffsTest extends TestCase */ protected function getExpectedJsonOutput(SplFileInfo $folder) { - return json_decode( - file_get_contents($folder->getRealPath() . DIRECTORY_SEPARATOR . 'Expected.json'), - true - ); + $file = $folder->getPathname() . DIRECTORY_SEPARATOR . 'Expected.json'; + if (!is_file($file)) { + throw new \Exception('Could not load file: ' . $file, 1491486050); + } + + return json_decode(file_get_contents($file), true); } /**