mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-17 17:47:13 +00:00
Change unit testing to match phpDocumentor itself
This commit is contained in:
@@ -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 }}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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>
|
||||
|
||||
@@ -67,12 +67,11 @@ class Description
|
||||
$this->bodyTemplate = $bodyTemplate;
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the body template
|
||||
* @return string
|
||||
* Returns the body template.
|
||||
*/
|
||||
public function getBodyTemplate(): string
|
||||
public function getBodyTemplate() : string
|
||||
{
|
||||
return $this->bodyTemplate;
|
||||
}
|
||||
|
||||
Executable
+31
@@ -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;
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user