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 5902aa6b..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 @@ -30,20 +31,21 @@ 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: - vendor/phpunit/phpunit/phpunit - ./phpqa tools - bin/ci.sh + - ls -lAh build deploy: - provider: script script: .docker/build-image 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: 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/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": [ 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 c3be8c27..3fd9edd3 100644 --- a/tests/.travis/.phpqa.yml +++ b/tests/.travis/.phpqa.yml @@ -14,7 +14,7 @@ phpqa: - phpmetrics:0 - phploc - phpcs:0 - - 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 */