From 55a44533eb433a46dd4004dcf0c8a9e8b98479e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 8 Dec 2019 13:47:09 +0100 Subject: [PATCH 1/6] CI - test and build docker image in php 7.2 Docker image has php 7.2 https://github.com/EdgedesignCZ/phpqa/commit/6ef3519 $ docker run --rm -it zdenekdrahos/phpqa:v1.23.3 php -v PHP 7.2.12 (cli) --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5902aa6b..2339dab4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ install: composer require sensiolabs/security-checker:~5; fi # test installing suggested tools like docker image - if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]]; then + if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]; then bin/suggested-tools.sh install --prefer-dist; fi script: @@ -43,7 +43,7 @@ deploy: skip_cleanup: false on: all_branches: true - php: 7.0 + php: 7.2 # http://blog.wyrihaximus.net/2015/07/composer-cache-on-travis/ cache: directories: From 73f69764ceb96b9d7eb4b2b61f56c24329fff7b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 8 Dec 2019 14:07:21 +0100 Subject: [PATCH 2/6] CI - disable failing suggested tools (php-cs-fixer, phpstan) on travis php 7.2 https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622261274#L1823 https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.2.20/php-cs-fixer#L28 It's not caused by php 7.2.22, something else is wrong... https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622265515 https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622267530#L721 https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622270345 https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622271457 https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622272539 https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622274667#L1082 --- tests/.travis/.phpqa.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/.travis/.phpqa.yml b/tests/.travis/.phpqa.yml index c3be8c27..bcde076f 100644 --- a/tests/.travis/.phpqa.yml +++ b/tests/.travis/.phpqa.yml @@ -14,11 +14,12 @@ phpqa: - phpmetrics:0 - phploc - phpcs:0 - - php-cs-fixer:0 + # fails on travis 7.2 without an error, works in docker image, no idea why, check the commit + # - php-cs-fixer:0 - phpmd:0 - pdepend - phpcpd:0 - - phpstan + #- phpstan - phpunit:0 - psalm - security-checker:0 From 26dc2682f7371f55089be8b3b17f083a9369252e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 8 Dec 2019 15:07:08 +0100 Subject: [PATCH 3/6] CI - try phpstan 0.12 on php 7.2 https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622274667#L1833 simplexml_load_file(): build//phpstan.xml:1: parser error : Start tag expec --- bin/suggested-tools.sh | 2 +- tests/.travis/.phpqa.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/suggested-tools.sh b/bin/suggested-tools.sh index 6c5fc28f..ac9487dd 100755 --- a/bin/suggested-tools.sh +++ b/bin/suggested-tools.sh @@ -13,7 +13,7 @@ then echo "Installing suggested tools" if [ ! -z "$requireMode" ]; then # docker build OR travis + php 7.0 OR symfony2 (default composer.lock) - composer require symfony/filesystem:~2 symfony/process:~2 symfony/finder:~2 jakub-onderka/php-parallel-lint jakub-onderka/php-console-highlighter phpstan/phpstan:~0.8.0 friendsofphp/php-cs-fixer:~2.2 vimeo/psalm:~1 sensiolabs/security-checker:~5 $requireMode + composer require symfony/filesystem:~2 symfony/process:~2 symfony/finder:~2 jakub-onderka/php-parallel-lint jakub-onderka/php-console-highlighter phpstan/phpstan:~0.12.0 nette/neon friendsofphp/php-cs-fixer:~2.2 vimeo/psalm:~1 sensiolabs/security-checker:~5 $requireMode else # symfony 3 composer require jakub-onderka/php-parallel-lint jakub-onderka/php-console-highlighter phpstan/phpstan nette/neon friendsofphp/php-cs-fixer:~2.2 vimeo/psalm sensiolabs/security-checker diff --git a/tests/.travis/.phpqa.yml b/tests/.travis/.phpqa.yml index bcde076f..0aad708b 100644 --- a/tests/.travis/.phpqa.yml +++ b/tests/.travis/.phpqa.yml @@ -14,12 +14,12 @@ phpqa: - phpmetrics:0 - phploc - phpcs:0 - # fails on travis 7.2 without an error, works in docker image, no idea why, check the commit + # fails on travis 7.2 without an error, works in docker image, no idea why, check the commit 73f6976 # - php-cs-fixer:0 - phpmd:0 - pdepend - phpcpd:0 - #- phpstan + - phpstan - phpunit:0 - psalm - security-checker:0 From 595ba71bfa99960c282a53997e175b975230ef30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 8 Dec 2019 15:57:07 +0100 Subject: [PATCH 4/6] Tools - fix handling errors when xml is invalid Summary should be shown, no fatal error. It should suppress php-cs-fixer errors on php 7.2. https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622282695#L2241 https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622261274#L1823 https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622274667#L1833 --- src/RunningTool.php | 9 ++++++--- src/report.php | 11 +++++++++++ tests/.travis/.phpqa.yml | 3 +-- tests/RunningToolTest.php | 16 ++++++++++++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/RunningTool.php b/src/RunningTool.php index f59b0513..17c5282a 100644 --- a/src/RunningTool.php +++ b/src/RunningTool.php @@ -84,11 +84,14 @@ public function analyzeResult($hasNoOutput = false) } elseif (!$xpath) { return [true, '']; } elseif (!file_exists($this->getMainXml())) { - return [false, 0]; + return [$this->areErrorsIgnored(), "XML [{$this->getMainXml()}] not found"]; } - $xml = simplexml_load_file($this->getMainXml()); - $errorsCount = count($xml->xpath($xpath)); + list($isInvalidXml, $xpathOrError) = xmlXpath($this->getMainXml(), $xpath); + if ($isInvalidXml) { + return [$this->areErrorsIgnored(), $xpathOrError]; + } + $errorsCount = count($xpathOrError); return $this->evaluteErrorsCount($errorsCount); } diff --git a/src/report.php b/src/report.php index c390b2e9..b7712db7 100644 --- a/src/report.php +++ b/src/report.php @@ -48,6 +48,17 @@ function xmlToHtml(array $xmlDocuments, $style, $outputFile, array $params = []) } } +function xmlXpath($xmlFile, $xpathQuery) +{ + convertPhpErrorsToExceptions(); + try { + $xml = simplexml_load_file($xmlFile); + return [false, $xml->xpath($xpathQuery)]; + } catch (Exception $e) { + return [true, $e->getMessage()]; + } +} + function convertPhpErrorsToExceptions() { static $isNotLoaded = true; diff --git a/tests/.travis/.phpqa.yml b/tests/.travis/.phpqa.yml index 0aad708b..3fd9edd3 100644 --- a/tests/.travis/.phpqa.yml +++ b/tests/.travis/.phpqa.yml @@ -14,8 +14,7 @@ phpqa: - phpmetrics:0 - phploc - phpcs:0 - # fails on travis 7.2 without an error, works in docker image, no idea why, check the commit 73f6976 - # - php-cs-fixer:0 + - php-cs-fixer - phpmd:0 - pdepend - phpcpd:0 diff --git a/tests/RunningToolTest.php b/tests/RunningToolTest.php index cb84c556..584bb264 100644 --- a/tests/RunningToolTest.php +++ b/tests/RunningToolTest.php @@ -20,13 +20,25 @@ public function testMarkSuccessWhenXPathIsNotDefined() assertThat($tool->analyzeResult(), is([true, ''])); } - public function testMarkFailureWhenXmlFileDoesNotExist() + /** @dataProvider provideAllowedErrorsForNonexistentFile */ + public function testMarkFailureWhenXmlFileDoesNotExist($allowedErrors, $expectedIsOk) { $tool = new RunningTool('tool', [ 'xml' => ['non-existent.xml'], 'errorsXPath' => '//errors/error', + 'allowedErrorsCount' => $allowedErrors, ]); - assertThat($tool->analyzeResult(), is([false, 0])); + list($isOk, $error) = $tool->analyzeResult(); + assertThat($isOk, is($expectedIsOk)); + assertThat($error, containsString('not found')); + } + + public function provideAllowedErrorsForNonexistentFile() + { + return [ + 'success when allowed errors are not defined' => [null, true], + 'success when errors count are defined' => [$this->errorsCountInXmlFile, false], + ]; } /** @dataProvider provideAllowedErrors */ From acaa481f5d6cfccef0522c5e66dbfede1a26d7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sun, 8 Dec 2019 16:05:30 +0100 Subject: [PATCH 5/6] CI - show artifacts and tools in docker image Still don't know why php-cs-fixer xml causes errors. https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622290077#L2265 It's caused by (unset) cast https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622293431#L2325 --- .docker/build-image | 1 + .travis.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.docker/build-image b/.docker/build-image index f2b67a62..49fd9d07 100755 --- a/.docker/build-image +++ b/.docker/build-image @@ -22,6 +22,7 @@ load_docker_variables () { build_docker_image () { set -e time docker build --file $DOCKER_FILE --tag $DOCKER_TAG $APP_DIR + docker run --rm -it $DOCKER_TAG phpqa tools if [ -z "$TRAVIS_TAG" ]; then echo "Docker image is published only if the current build is for a git tag" diff --git a/.travis.yml b/.travis.yml index 2339dab4..cabd6795 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,6 +37,7 @@ script: - vendor/phpunit/phpunit/phpunit - ./phpqa tools - bin/ci.sh + - ls -lAh build deploy: - provider: script script: .docker/build-image From e6be79963e71bb5db44864a512d746794c4f8d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Draho=C5=A1?= Date: Sat, 14 Dec 2019 09:21:08 +0100 Subject: [PATCH 6/6] CI - add php 7.4 https://travis-ci.org/EdgedesignCZ/phpqa/jobs/622280212 [Twig\Error\SyntaxError] An exception has been thrown during the compilation of a template ("Unparen thesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e ` or `a ? b : (c ? d : e)`") in "cli.html.twig". It might need twig v1.42.3 that dropped php 5.4 support https://github.com/twigphp/Twig/blob/v1.42.4/CHANGELOG#L6 --- .travis.yml | 1 + composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index cabd6795..06494427 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ matrix: - php: 7.1 - php: 7.2 - php: 7.3 + - php: 7.4 install: - if [ -n "$GITHUB_OAUTH_TOKEN" ]; then composer config -g github-oauth.github.com ${GITHUB_OAUTH_TOKEN}; fi; - composer install --no-interaction diff --git a/composer.lock b/composer.lock index 8e6a646e..9dc49fbf 100644 --- a/composer.lock +++ b/composer.lock @@ -1839,16 +1839,16 @@ }, { "name": "twig/twig", - "version": "v1.38.4", + "version": "v1.42.2", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "7732e9e7017d751313811bd118de61302e9c8b35" + "reference": "21707d6ebd05476854805e4f91b836531941bcd4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/7732e9e7017d751313811bd118de61302e9c8b35", - "reference": "7732e9e7017d751313811bd118de61302e9c8b35", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/21707d6ebd05476854805e4f91b836531941bcd4", + "reference": "21707d6ebd05476854805e4f91b836531941bcd4", "shasum": "" }, "require": { @@ -1858,12 +1858,12 @@ "require-dev": { "psr/container": "^1.0", "symfony/debug": "^2.7", - "symfony/phpunit-bridge": "^3.4.19|^4.1.8" + "symfony/phpunit-bridge": "^3.4.19|^4.1.8|^5.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.38-dev" + "dev-master": "1.42-dev" } }, "autoload": { @@ -1901,7 +1901,7 @@ "keywords": [ "templating" ], - "time": "2019-03-23T14:27:19+00:00" + "time": "2019-06-18T15:35:16+00:00" } ], "packages-dev": [