Skip to content

Commit 50e77ac

Browse files
committed
Change unit testing to match phpDocumentor itself
1 parent 1070e66 commit 50e77ac

File tree

7 files changed

+82
-41
lines changed

7 files changed

+82
-41
lines changed

.github/workflows/push.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,12 @@ jobs:
6464
restore-keys: |
6565
all-tools-${{ github.sha }}-
6666
all-tools-
67-
- name: Setup PHP
68-
uses: shivammathur/setup-php@master
69-
with:
70-
php-version: 7.2
71-
extension-csv: mbstring, intl, iconv, libxml, dom, json, simplexml, zlib
72-
ini-values-csv: memory_limit=2G, display_errors=On, error_reporting=-1
73-
coverage: xdebug
74-
pecl: false
75-
- name: Run PHPUnit
76-
run: php tools/phpunit
67+
- name: PHPUnit
68+
uses: docker://phpdoc/phpunit-ga:latest
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
- name: Quick check code coverage level
72+
run: php tests/coverage-checker.php 89
7773

7874
phpunit:
7975
runs-on: ${{ matrix.operating-system }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ vendor/
1515

1616
# By default the phpunit.xml.dist is provided; you can override this using a local config file
1717
phpunit.xml
18+
.phpunit.result.cache

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ psalm:
2929

3030
.PHONY: test
3131
test:
32-
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.4-pcov tools/phpunit
32+
docker run -it --rm -v${CURDIR}:/github/workspace phpdoc/phpunit-ga
33+
docker run -it --rm -v${CURDIR}:/data -w /data php:7.2 -f ./tests/coverage-checker.php 89
3334

3435
.PHONY: pre-commit-test
3536
pre-commit-test: test phpcs phpstan psalm

phpunit.xml.dist

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,31 @@
88
forceCoversAnnotation="true"
99
verbose="true"
1010
bootstrap="vendor/autoload.php"
11-
>
12-
<testsuites>
13-
<testsuite name="unit">
14-
<directory>./tests/unit</directory>
15-
</testsuite>
16-
<testsuite name="integration">
17-
<directory>./tests/integration</directory>
18-
</testsuite>
19-
</testsuites>
20-
<filter>
21-
<whitelist>
22-
<directory suffix=".php">./src/</directory>
23-
</whitelist>
24-
</filter>
25-
<logging>
26-
<log type="coverage-html"
27-
target="build/coverage"
28-
lowUpperBound="35"
29-
highLowerBound="70"/>
30-
</logging>
31-
<listeners>
32-
<listener
33-
class="Mockery\Adapter\Phpunit\TestListener"
34-
file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"
35-
/>
36-
</listeners>
11+
>
12+
<testsuites>
13+
<testsuite name="unit">
14+
<directory>./tests/unit</directory>
15+
</testsuite>
16+
<testsuite name="integration">
17+
<directory>./tests/integration</directory>
18+
</testsuite>
19+
</testsuites>
20+
<filter>
21+
<whitelist>
22+
<directory suffix=".php">./src/</directory>
23+
</whitelist>
24+
</filter>
25+
<logging>
26+
<log type="coverage-html"
27+
target="build/coverage"
28+
lowUpperBound="35"
29+
highLowerBound="70"/>
30+
<log type="coverage-clover" target="build/logs/clover.xml"/>
31+
</logging>
32+
<listeners>
33+
<listener
34+
class="Mockery\Adapter\Phpunit\TestListener"
35+
file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"
36+
/>
37+
</listeners>
3738
</phpunit>

src/DocBlock/Description.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,11 @@ public function __construct(string $bodyTemplate, array $tags = [])
6767
$this->bodyTemplate = $bodyTemplate;
6868
$this->tags = $tags;
6969
}
70-
70+
7171
/**
72-
* Returns the body template
73-
* @return string
72+
* Returns the body template.
7473
*/
75-
public function getBodyTemplate(): string
74+
public function getBodyTemplate() : string
7675
{
7776
return $this->bodyTemplate;
7877
}

tests/coverage-checker.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
// based on https://ocramius.github.io/blog/automated-code-coverage-check-for-github-pull-requests-with-travis/
3+
$inputFile = __DIR__ . '/../build/logs/clover.xml';
4+
$percentage = min(100, max(0, (int) $argv[1]));
5+
6+
if (!file_exists($inputFile)) {
7+
throw new InvalidArgumentException('Invalid input file provided');
8+
}
9+
10+
if (!$percentage) {
11+
throw new InvalidArgumentException('An integer checked percentage must be given as parameter');
12+
}
13+
14+
$xml = new SimpleXMLElement(file_get_contents($inputFile));
15+
$metrics = $xml->xpath('//metrics');
16+
$totalElements = 0;
17+
$checkedElements = 0;
18+
19+
foreach ($metrics as $metric) {
20+
$totalElements += (int) $metric['elements'];
21+
$checkedElements += (int) $metric['coveredelements'];
22+
}
23+
24+
$coverage = ($checkedElements / $totalElements) * 100;
25+
26+
if ($coverage < $percentage) {
27+
echo 'Code coverage is ' . $coverage . '%, which is below the accepted ' . $percentage . '%' . PHP_EOL;
28+
exit(1);
29+
}
30+
31+
echo 'Code coverage is ' . $coverage . '% - OK!' . PHP_EOL;

tests/unit/DocBlock/DescriptionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ public function testDescriptionTagsGetter() : void
104104
$this->assertSame($tag2, $actualTags[1]);
105105
}
106106

107+
/**
108+
* @covers ::getBodyTemplate
109+
*/
110+
public function testDescriptionBodyTemplateGetter() : void
111+
{
112+
$body = 'See https://github.com/phpDocumentor/ReflectionDocBlock/pull/171 for more information';
113+
114+
$fixture = new Description($body, []);
115+
116+
$this->assertSame($body, $fixture->getBodyTemplate());
117+
}
118+
107119
/**
108120
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic
109121
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag

0 commit comments

Comments
 (0)