Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .docker/build-image
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion bin/suggested-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/RunningTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 11 additions & 0 deletions src/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/.travis/.phpqa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ phpqa:
- phpmetrics:0
- phploc
- phpcs:0
- php-cs-fixer:0
- php-cs-fixer
- phpmd:0
- pdepend
- phpcpd:0
Expand Down
16 changes: 14 additions & 2 deletions tests/RunningToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down