Change unit testing to match phpDocumentor itself

This commit is contained in:
Mike van Riel
2020-02-12 08:18:08 +01:00
parent 1070e666aa
commit 50e77ace68
7 changed files with 82 additions and 41 deletions
+6 -10
View File
@@ -64,16 +64,12 @@ jobs:
restore-keys: |
all-tools-${{ github.sha }}-
all-tools-
- name: Setup PHP
uses: shivammathur/setup-php@master
with:
php-version: 7.2
extension-csv: mbstring, intl, iconv, libxml, dom, json, simplexml, zlib
ini-values-csv: memory_limit=2G, display_errors=On, error_reporting=-1
coverage: xdebug
pecl: false
- name: Run PHPUnit
run: php tools/phpunit
- name: PHPUnit
uses: docker://phpdoc/phpunit-ga:latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Quick check code coverage level
run: php tests/coverage-checker.php 89
phpunit:
runs-on: ${{ matrix.operating-system }}
+1
View File
@@ -15,3 +15,4 @@ vendor/
# By default the phpunit.xml.dist is provided; you can override this using a local config file
phpunit.xml
.phpunit.result.cache
+2 -1
View File
@@ -29,7 +29,8 @@ psalm:
.PHONY: test
test:
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.4-pcov tools/phpunit
docker run -it --rm -v${CURDIR}:/github/workspace phpdoc/phpunit-ga
docker run -it --rm -v${CURDIR}:/data -w /data php:7.2 -f ./tests/coverage-checker.php 89
.PHONY: pre-commit-test
pre-commit-test: test phpcs phpstan psalm
+27 -26
View File
@@ -8,30 +8,31 @@
forceCoversAnnotation="true"
verbose="true"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="unit">
<directory>./tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory>./tests/integration</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html"
target="build/coverage"
lowUpperBound="35"
highLowerBound="70"/>
</logging>
<listeners>
<listener
class="Mockery\Adapter\Phpunit\TestListener"
file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"
/>
</listeners>
>
<testsuites>
<testsuite name="unit">
<directory>./tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory>./tests/integration</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html"
target="build/coverage"
lowUpperBound="35"
highLowerBound="70"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<listeners>
<listener
class="Mockery\Adapter\Phpunit\TestListener"
file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"
/>
</listeners>
</phpunit>
+2 -3
View File
@@ -69,10 +69,9 @@ class Description
}
/**
* Returns the body template
* @return string
* Returns the body template.
*/
public function getBodyTemplate(): string
public function getBodyTemplate() : string
{
return $this->bodyTemplate;
}
+31
View File
@@ -0,0 +1,31 @@
<?php
// based on https://ocramius.github.io/blog/automated-code-coverage-check-for-github-pull-requests-with-travis/
$inputFile = __DIR__ . '/../build/logs/clover.xml';
$percentage = min(100, max(0, (int) $argv[1]));
if (!file_exists($inputFile)) {
throw new InvalidArgumentException('Invalid input file provided');
}
if (!$percentage) {
throw new InvalidArgumentException('An integer checked percentage must be given as parameter');
}
$xml = new SimpleXMLElement(file_get_contents($inputFile));
$metrics = $xml->xpath('//metrics');
$totalElements = 0;
$checkedElements = 0;
foreach ($metrics as $metric) {
$totalElements += (int) $metric['elements'];
$checkedElements += (int) $metric['coveredelements'];
}
$coverage = ($checkedElements / $totalElements) * 100;
if ($coverage < $percentage) {
echo 'Code coverage is ' . $coverage . '%, which is below the accepted ' . $percentage . '%' . PHP_EOL;
exit(1);
}
echo 'Code coverage is ' . $coverage . '% - OK!' . PHP_EOL;
+12
View File
@@ -104,6 +104,18 @@ class DescriptionTest extends TestCase
$this->assertSame($tag2, $actualTags[1]);
}
/**
* @covers ::getBodyTemplate
*/
public function testDescriptionBodyTemplateGetter() : void
{
$body = 'See https://github.com/phpDocumentor/ReflectionDocBlock/pull/171 for more information';
$fixture = new Description($body, []);
$this->assertSame($body, $fixture->getBodyTemplate());
}
/**
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag