mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Change unit testing to match phpDocumentor itself
This commit is contained in:
@@ -64,16 +64,12 @@ jobs:
|
|||||||
restore-keys: |
|
restore-keys: |
|
||||||
all-tools-${{ github.sha }}-
|
all-tools-${{ github.sha }}-
|
||||||
all-tools-
|
all-tools-
|
||||||
- name: Setup PHP
|
- name: PHPUnit
|
||||||
uses: shivammathur/setup-php@master
|
uses: docker://phpdoc/phpunit-ga:latest
|
||||||
with:
|
env:
|
||||||
php-version: 7.2
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
extension-csv: mbstring, intl, iconv, libxml, dom, json, simplexml, zlib
|
- name: Quick check code coverage level
|
||||||
ini-values-csv: memory_limit=2G, display_errors=On, error_reporting=-1
|
run: php tests/coverage-checker.php 89
|
||||||
coverage: xdebug
|
|
||||||
pecl: false
|
|
||||||
- name: Run PHPUnit
|
|
||||||
run: php tools/phpunit
|
|
||||||
|
|
||||||
phpunit:
|
phpunit:
|
||||||
runs-on: ${{ matrix.operating-system }}
|
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
|
# By default the phpunit.xml.dist is provided; you can override this using a local config file
|
||||||
phpunit.xml
|
phpunit.xml
|
||||||
|
.phpunit.result.cache
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ psalm:
|
|||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
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
|
.PHONY: pre-commit-test
|
||||||
pre-commit-test: test phpcs phpstan psalm
|
pre-commit-test: test phpcs phpstan psalm
|
||||||
|
|||||||
+27
-26
@@ -8,30 +8,31 @@
|
|||||||
forceCoversAnnotation="true"
|
forceCoversAnnotation="true"
|
||||||
verbose="true"
|
verbose="true"
|
||||||
bootstrap="vendor/autoload.php"
|
bootstrap="vendor/autoload.php"
|
||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="unit">
|
<testsuite name="unit">
|
||||||
<directory>./tests/unit</directory>
|
<directory>./tests/unit</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<testsuite name="integration">
|
<testsuite name="integration">
|
||||||
<directory>./tests/integration</directory>
|
<directory>./tests/integration</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<filter>
|
<filter>
|
||||||
<whitelist>
|
<whitelist>
|
||||||
<directory suffix=".php">./src/</directory>
|
<directory suffix=".php">./src/</directory>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
<logging>
|
<logging>
|
||||||
<log type="coverage-html"
|
<log type="coverage-html"
|
||||||
target="build/coverage"
|
target="build/coverage"
|
||||||
lowUpperBound="35"
|
lowUpperBound="35"
|
||||||
highLowerBound="70"/>
|
highLowerBound="70"/>
|
||||||
</logging>
|
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
||||||
<listeners>
|
</logging>
|
||||||
<listener
|
<listeners>
|
||||||
class="Mockery\Adapter\Phpunit\TestListener"
|
<listener
|
||||||
file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"
|
class="Mockery\Adapter\Phpunit\TestListener"
|
||||||
/>
|
file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"
|
||||||
</listeners>
|
/>
|
||||||
|
</listeners>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
@@ -67,12 +67,11 @@ class Description
|
|||||||
$this->bodyTemplate = $bodyTemplate;
|
$this->bodyTemplate = $bodyTemplate;
|
||||||
$this->tags = $tags;
|
$this->tags = $tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the body template
|
* Returns the body template.
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getBodyTemplate(): string
|
public function getBodyTemplate() : string
|
||||||
{
|
{
|
||||||
return $this->bodyTemplate;
|
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]);
|
$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\Generic
|
||||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
||||||
|
|||||||
Reference in New Issue
Block a user