From 92c973c7f4dd14dc58de7c826738082fc9e18548 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 8 Apr 2017 22:49:00 +0200 Subject: [PATCH 01/11] WIP|FEATURE: Integrate gitlab ci * Provide a way to run php unit functional tests --- .gitlab-ci.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..3ff7b80 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,18 @@ +image: 'composer:latest' + +before_script: + - > + composer install + --optimize-autoloader + --no-interaction + --no-ansi + +stages: + - test + +test:functional: + stage: test + script: + - ./vendor/bin/phpunit + +# Further stages, and jobs e.g. linting, cgl, etc. From 3e33096a4762e6d40f6dd72d55ef5a36ebfeb00c Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 8 Apr 2017 23:04:16 +0200 Subject: [PATCH 02/11] BUGFIX: Make tests work in gitlab ci env --- tests/SniffsTest.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/SniffsTest.php b/tests/SniffsTest.php index ad2dd10..86f4fce 100644 --- a/tests/SniffsTest.php +++ b/tests/SniffsTest.php @@ -23,7 +23,6 @@ namespace Typo3Update\Tests; use PHPUnit\Framework\TestCase; use Symfony\Component\Finder\Finder; -use Symfony\Component\Finder\SplFileInfo; /** * Will test all sniffs where fixtures are available. @@ -64,29 +63,29 @@ class SniffsTest extends TestCase /** * Execute sniff using subfolders. * - * @param SplFileInfo $folder + * @param \SplFileInfo $folder * @param array $arguments * @return void */ - protected function executeSniffSubfolders(SplFileInfo $folder, array $arguments = []) + 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); + $this->executeSniff(new \SplFileInfo($folderName), $values); } } /** * Execute phpunit assertion for sniff based on $folder. * - * @param SplFileInfo $folder + * @param \SplFileInfo $folder * @param array $arguments * @return void */ - protected function executeSniff(SplFileInfo $folder, array $arguments = []) + protected function executeSniff(\SplFileInfo $folder, array $arguments = []) { $internalArguments = array_merge_recursive([ 'runtime-set' => [ @@ -133,10 +132,10 @@ class SniffsTest extends TestCase /** * Get expected json output for comparison. * - * @param SplFileInfo $folder + * @param \SplFileInfo $folder * @return array */ - protected function getExpectedJsonOutput(SplFileInfo $folder) + protected function getExpectedJsonOutput(\SplFileInfo $folder) { $file = $folder->getPathname() . DIRECTORY_SEPARATOR . 'Expected.json'; if (!is_file($file)) { @@ -149,12 +148,12 @@ class SniffsTest extends TestCase /** * Returns absolute file path to diff file containing expected output. * - * @param SplFileInfo $folder + * @param \SplFileInfo $folder * @return string * * @throws FileNotFoundException */ - protected function getExpectedDiffOutput(SplFileInfo $folder) + protected function getExpectedDiffOutput(\SplFileInfo $folder) { $file = $folder->getRealPath() . DIRECTORY_SEPARATOR . 'Expected.diff'; if (!is_file($file)) { @@ -167,10 +166,10 @@ class SniffsTest extends TestCase /** * Returns PHPCS Sniff name for given folder. * - * @param SplFileInfo $folder + * @param \SplFileInfo $folder * @return string */ - protected function getSniffByFolder(SplFileInfo $folder) + protected function getSniffByFolder(\SplFileInfo $folder) { $folderParts = array_filter(explode(DIRECTORY_SEPARATOR, $folder->getPathName())); $sniffNamePosition; @@ -194,10 +193,10 @@ class SniffsTest extends TestCase /** * Get absolute file path to file containing further arguments. * - * @param SplFileInfo $folder + * @param \SplFileInfo $folder * @return string */ - protected function getArgumentsFile(SplFileInfo $folder) + protected function getArgumentsFile(\SplFileInfo $folder) { return $folder->getRealPath() . DIRECTORY_SEPARATOR . 'Arguments.php'; } From bd3e6b080d45e7e85f2d32f4c8c8881b74293c28 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 8 Apr 2017 23:07:26 +0200 Subject: [PATCH 03/11] BUGFIX: Finish installation / setup on gitlab ci * Install PHPCS Standard to execute with tests --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3ff7b80..85d8106 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,6 +6,7 @@ before_script: --optimize-autoloader --no-interaction --no-ansi + - make install stages: - test From a2eb6d799db034ac4e52a4460f77d63c54e6c6d8 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 8 Apr 2017 23:10:59 +0200 Subject: [PATCH 04/11] TASK: Install make to run install routine --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 85d8106..54161e5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ image: 'composer:latest' before_script: + - apk add --no-cache make - > composer install --optimize-autoloader From c511f1a70b14f62663d4fec48b7d7207f9b3de68 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 8 Apr 2017 23:23:09 +0200 Subject: [PATCH 05/11] WIP|FEATURE: Test on multiple php versions * Use different jobs to run in parallel. * Use different docker image for each php version. * Provide common way to install composer on each image. --- .gitlab-ci.yml | 23 +++++++++++++++-------- Makefile | 11 ++++++++++- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 54161e5..38fb4e2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,18 +1,25 @@ -image: 'composer:latest' - before_script: - - apk add --no-cache make - > - composer install - --optimize-autoloader - --no-interaction - --no-ansi + apt-get update + && apt-get install -y + make + wget + --no-install-recommends + && rm -r /var/lib/apt/lists/* + - make install-composer - make install stages: - test -test:functional: +test:5.6: + image: php:5.6 + stage: test + script: + - ./vendor/bin/phpunit + +test:7.0: + image: php:7.0 stage: test script: - ./vendor/bin/phpunit diff --git a/Makefile b/Makefile index 432e039..13e7363 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ DEFAULT_STANDARD = Typo3Update CUSTOM_STANDARDS = $(abspath ./src/Standards/) install: - composer install + composer install --optimize-autoloader --no-interaction --no-ansi $(BIN_PHPCS) --config-set installed_paths $(CUSTOM_STANDARDS) $(BIN_PHPCS) -i | grep Typo3Update $(BIN_PHPCS) --config-set default_standard $(DEFAULT_STANDARD) @@ -14,3 +14,12 @@ test-search: $(BIN_PHPCS) -p --colors -s PROJECT_PATH test-fix: $(BIN_PHPCBF) -p --colors -s PROJECT_PATH + +# For CI: +install-composer: + wget https://composer.github.io/installer.sig -O - -q | tr -d '\n' > installer.sig + php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" + php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" + php composer-setup.php + php -r "unlink('composer-setup.php'); unlink('installer.sig');" + php composer.phar install From ba20024783039d9e594a9529f1798911b738cf09 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 8 Apr 2017 23:32:11 +0200 Subject: [PATCH 06/11] TASK: Migrate to smaller alpine images * To have faster downloads, smaller images, simpler installs --- .gitlab-ci.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 38fb4e2..183cfe4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,11 +1,5 @@ before_script: - - > - apt-get update - && apt-get install -y - make - wget - --no-install-recommends - && rm -r /var/lib/apt/lists/* + - apk add --no-cache make wget git - make install-composer - make install @@ -13,13 +7,13 @@ stages: - test test:5.6: - image: php:5.6 + image: php:5.6-alpine stage: test script: - ./vendor/bin/phpunit test:7.0: - image: php:7.0 + image: php:7.0-alpine stage: test script: - ./vendor/bin/phpunit From 3e8931643088208e314a414dc3b355c8537e1d3f Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 8 Apr 2017 23:34:56 +0200 Subject: [PATCH 07/11] TASK: Make composer available as bin --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 13e7363..feeeb7e 100644 --- a/Makefile +++ b/Makefile @@ -22,4 +22,5 @@ install-composer: php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php'); unlink('installer.sig');" - php composer.phar install + chmod ugo+x composer.phar + mv composer.phar /usr/local/bin/composer From b8d84c5bdcdb9d3a2ef123603c52fb2a015295f7 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sun, 9 Apr 2017 00:10:22 +0200 Subject: [PATCH 08/11] TASK: Add further linting --- .gitlab-ci.yml | 29 +++++++++++++++++++++++++++++ composer.json | 20 +++++++++++--------- phpcs.xml.dist | 22 ++++++++++++++++++++++ phpmd.xml | 19 +++++++++++++++++++ 4 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 phpcs.xml.dist create mode 100644 phpmd.xml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 183cfe4..0afc2bf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,10 +2,33 @@ before_script: - apk add --no-cache make wget git - make install-composer - make install + - mkdir -p result stages: - test +lint:coding-guideline: + image: php:7.0-alpine + stage: test + script: + - ./vendor/bin/phpcs -s + - ./vendor/bin/phpcs -s > result/phpcs-summary.txt + artifacts: + when: on_failure + paths: + - result + +lint:php-mass-detection: + image: php:7.0-alpine + stage: test + script: + - ./vendor/bin/phpmd src text phpmd.xml > result/phpmd.txt + - ./vendor/bin/phpmd src html phpmd.xml > result/phpmd.html + artifacts: + when: on_failure + paths: + - result + test:5.6: image: php:5.6-alpine stage: test @@ -18,4 +41,10 @@ test:7.0: script: - ./vendor/bin/phpunit +test:latest: + image: php:7-alpine + stage: test + script: + - ./vendor/bin/phpunit + # Further stages, and jobs e.g. linting, cgl, etc. diff --git a/composer.json b/composer.json index 0db31eb..ec779e3 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,13 @@ "name": "siepmann/typo3_update", "description": "Auto migrate PHP Source of extensions to be compatible.", "type": "project", + "license": "GPL-2.0+", + "authors": [ + { + "name": "Daniel Siepmann", + "email": "coding@daniel-siepmann.de" + } + ], "autoload": { "psr-4": { "Typo3Update\\Tests\\": "tests/", @@ -22,15 +29,10 @@ "squizlabs/php_codesniffer": "2.8.*", "symfony/yaml": "3.2.*" }, - "license": "GPL-2.0+", - "authors": [ - { - "name": "Daniel Siepmann", - "email": "coding@daniel-siepmann.de" - } - ], "require-dev": { - "phpunit/phpunit": "^5.7", - "symfony/finder": "^3.2" + "phpunit/phpunit": "5.7.*", + "symfony/finder": "3.2.*", + "phpmd/phpmd": "2.6.*", + "pdepend/pdepend": "2.5.*" } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..c742021 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,22 @@ + + + The coding standard for this Project + + ./src + ./tests + */Fixtures/* + + + + *Sniff.php$ + */Tokenizers/* + + + *Sniff.php$ + */Tokenizers/* + + + *Sniff.php$ + */Tokenizers/* + + diff --git a/phpmd.xml b/phpmd.xml new file mode 100644 index 0000000..829b5eb --- /dev/null +++ b/phpmd.xml @@ -0,0 +1,19 @@ + + + + My custom rule set that checks my code... + + + + + + + + + From b20bf043f0bf93f27896ff3bb9af6e9881ca4bf4 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 10 Apr 2017 09:32:22 +0200 Subject: [PATCH 09/11] TASK: Don't show warnings * On CI we just want to make sure we don't have any errors. --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0afc2bf..70c0f43 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,8 +11,8 @@ lint:coding-guideline: image: php:7.0-alpine stage: test script: - - ./vendor/bin/phpcs -s - - ./vendor/bin/phpcs -s > result/phpcs-summary.txt + - ./vendor/bin/phpcs -s -n + - ./vendor/bin/phpcs -s -n > result/phpcs-summary.txt artifacts: when: on_failure paths: From e48cbe712ecfbdb4b9a5af9aaf5bc20b6a2144f6 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 10 Apr 2017 13:32:44 +0200 Subject: [PATCH 10/11] BUGFIX: Allow phpunit tests to run even if phpcs.xml.dist is provided * By adding Coding Standard to calls, phpcs will not lookup the standard to use in our phpcs.xml.dist, which is used to check the project itself. * Instead it will use the provided standard. --- tests/SniffsTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/SniffsTest.php b/tests/SniffsTest.php index 16d58b0..2560f1a 100644 --- a/tests/SniffsTest.php +++ b/tests/SniffsTest.php @@ -115,6 +115,7 @@ class SniffsTest extends TestCase protected function executeSniff(\SplFileInfo $folder, array $arguments = []) { $internalArguments = array_merge_recursive([ + 'standard' => 'Typo3Update', 'runtime-set' => [ 'mappingFile' => __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR From 89af4a2e371d5e907458ca28d00c9b56e9e27c0e Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 11 Apr 2017 08:39:32 +0200 Subject: [PATCH 11/11] TASK: Configure phpmd * Make phpmd pass. * Comment supressions with a reason. --- phpmd.xml | 20 +++++++++++++------ src/CodeSniffer/Tokenizers/TypoScript.php | 2 ++ .../AbstractClassnameChecker.php | 6 ++++++ .../Sniffs/LegacyClassnames/Mapping.php | 3 +++ .../MissingNamespaceSniff.php | 2 ++ .../Sniffs/LegacyClassnames/UseSniff.php | 2 ++ .../Sniffs/Removed/AbstractGenericUsage.php | 5 +++-- 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/phpmd.xml b/phpmd.xml index 829b5eb..67d345c 100644 --- a/phpmd.xml +++ b/phpmd.xml @@ -10,10 +10,18 @@ My custom rule set that checks my code... - - - - - - + + + + + + + + + + + + + + diff --git a/src/CodeSniffer/Tokenizers/TypoScript.php b/src/CodeSniffer/Tokenizers/TypoScript.php index 8130faf..26136f6 100644 --- a/src/CodeSniffer/Tokenizers/TypoScript.php +++ b/src/CodeSniffer/Tokenizers/TypoScript.php @@ -65,6 +65,8 @@ class PHP_CodeSniffer_Tokenizers_TYPOSCRIPT * @param string $eolChar The EOL character to use for splitting strings. * * @return void + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) We need to match the signature. */ public function processAdditional(&$tokens, $eolChar) { diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php index 19719e9..76c3cfe 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php @@ -82,6 +82,8 @@ abstract class AbstractClassnameChecker implements PhpCsSniff * the token was found. * * @return void + * + * @SuppressWarnings(PHPMD.ElseExpression) This is for performance reason. */ public function process(PhpCsFile $phpcsFile, $stackPtr) { @@ -217,6 +219,8 @@ abstract class AbstractClassnameChecker implements PhpCsSniff * @param int $classnamePosition * @param string $classname * @param bool $forceEmptyPrefix Defines whether '\\' prefix should be checked or always be left out. + * + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ protected function replaceLegacyClassname( PhpCsFile $phpcsFile, @@ -243,6 +247,8 @@ abstract class AbstractClassnameChecker implements PhpCsSniff * @param string $originalClassname * @param PhpCsFile $phpcsFile * @return string + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) We need to match the signature. */ protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile) { diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php index 201263a..685dec6 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php @@ -48,6 +48,9 @@ final class Mapping private function __clone() { } + /** + * @SuppressWarnings(PHPMD.UnusedPrivateMethod) We just want to implement singleton pattern. + */ private function __wakeup() { } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php index e8d0feb..8e97c45 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php @@ -95,6 +95,8 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends Abstract * @param int $classnamePosition * @param string $classname * @param bool $forceEmptyPrefix Defines whether '\\' prefix should be checked or always be left out. + * + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ protected function replaceLegacyClassname( PhpCsFile $phpcsFile, diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php index f1129ba..bed18bc 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php @@ -46,6 +46,8 @@ class Typo3Update_Sniffs_LegacyClassnames_UseSniff extends AbstractClassnameChec * @param int $classnamePosition * @param string $classname * @param bool $forceEmptyPrefix Defines whether '\\' prefix should be checked or always be left out. + * + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ protected function replaceLegacyClassname( PhpCsFile $phpcsFile, diff --git a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php index 766db34..13697f0 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php @@ -29,8 +29,9 @@ use Typo3Update\Sniffs\Options; /** * Contains common functionality for removed code like constants or functions. * - * Removed parts are configured using YAML-Files, for examples see src/Standards/Typo3Update/Configuration/Removed/Constants/7.0.yaml - * Also check out the configuration options in Readme.rst. + * Removed parts are configured using YAML-Files, for examples see + * src/Standards/Typo3Update/Configuration/Removed/Constants/7.0.yaml Also + * check out the configuration options in Readme.rst. */ abstract class AbstractGenericUsage implements PhpCsSniff {