Skip to content

Commit f591cff

Browse files
Fixed test coverage issues with ResultPrinter classes
1 parent f056b81 commit f591cff

File tree

5 files changed

+72
-49
lines changed

5 files changed

+72
-49
lines changed

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codedungeon/phpunit-result-printer",
3-
"version": "0.16.0",
3+
"version": "0.16.1",
44
"description": "PHPUnit Pretty Result Printer",
55
"keywords": [
66
"phpunit",
@@ -37,7 +37,10 @@
3737
"scripts": {
3838
"coverage-report": "open ./coverage/index.html",
3939
"test": "vendor/bin/phpunit --colors=always",
40-
"test-coverage": "./vendor/bin/phpunit --colors=always --testsuite Unit --coverage-html coverage",
40+
"test-coverage": [
41+
"./vendor/bin/phpunit --colors=always --testsuite Unit --coverage-html coverage",
42+
"open ./coverage/index.html"
43+
],
4144
"test-ci": "vendor/bin/phpunit -c phpunit.ci.xml",
4245
"test-watch": "vendor/bin/phpunit-watcher watch --testsuite Unit < /dev/tty",
4346
"watch-tickets": "vendor/bin/phpunit-watcher watch --testsuite Tickets < /dev/tty"

src/ResultPrinter5.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
use PHPUnit_Framework_Test;
66
use PHPUnit_TextUI_ResultPrinter;
77

8-
class ResultPrinter5 extends PHPUnit_TextUI_ResultPrinter
9-
{
10-
public function startTest(PHPUnit_Framework_Test $test)
8+
if (class_exists(PHPUnit_TextUI_ResultPrinter::class)) {
9+
class ResultPrinter5 extends PHPUnit_TextUI_ResultPrinter
1110
{
12-
$this->className = \get_class($test);
13-
parent::startTest($test);
11+
public function startTest(PHPUnit_Framework_Test $test)
12+
{
13+
$this->className = \get_class($test);
14+
parent::startTest($test);
15+
}
1416
}
15-
}
17+
}

src/ResultPrinter6.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33
namespace Codedungeon\PHPUnitPrettyResultPrinter;
44

55
use PHPUnit\Framework\Test;
6+
use PHPUnit\Runner\Version;
67
use PHPUnit\TextUI\ResultPrinter;
78

8-
class ResultPrinter6 extends ResultPrinter
9-
{
10-
public function startTest(Test $test)
9+
if (version_compare(Version::series(), '6.99.99', '<=')) {
10+
class ResultPrinter6 extends ResultPrinter
1111
{
12-
$this->className = \get_class($test);
13-
parent::startTest($test);
14-
}
12+
public function startTest(Test $test)
13+
{
14+
$this->className = \get_class($test);
15+
parent::startTest($test);
16+
}
1517

16-
protected function writeProgress($progress)
17-
{
18-
$this->writeProgressEx($progress);
19-
}
18+
protected function writeProgress($progress)
19+
{
20+
$this->writeProgressEx($progress);
21+
}
2022

21-
protected function writeProgressWithColor($progress, $buffer)
22-
{
23-
$this->writeProgressWithColorEx($progress, $buffer);
23+
protected function writeProgressWithColor($progress, $buffer)
24+
{
25+
$this->writeProgressWithColorEx($progress, $buffer);
26+
}
2427
}
25-
}
28+
}

src/ResultPrinter70.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@
33
namespace Codedungeon\PHPUnitPrettyResultPrinter;
44

55
use PHPUnit\Framework\Test;
6+
use PHPUnit\Runner\Version;
67
use PHPUnit\TextUI\ResultPrinter;
78

8-
class ResultPrinter70 extends ResultPrinter
9-
{
10-
public function startTest(Test $test): void
11-
{
12-
$this->className = \get_class($test);
13-
parent::startTest($test);
14-
}
9+
$low = version_compare(Version::series(), '7.0', '>=');
10+
$high = version_compare(Version::series(), '7.0.99', '<=');
1511

16-
protected function writeProgress($progress): void
12+
if ($low && $high) {
13+
class ResultPrinter70 extends ResultPrinter
1714
{
18-
$this->writeProgressEx($progress);
19-
}
15+
public function startTest(Test $test): void
16+
{
17+
$this->className = \get_class($test);
18+
parent::startTest($test);
19+
}
2020

21-
protected function writeProgressWithColor($progress, $buffer): void
22-
{
23-
$this->writeProgressWithColorEx($progress, $buffer);
21+
protected function writeProgress($progress): void
22+
{
23+
$this->writeProgressEx($progress);
24+
}
25+
26+
protected function writeProgressWithColor($progress, $buffer): void
27+
{
28+
$this->writeProgressWithColorEx($progress, $buffer);
29+
}
2430
}
2531
}

src/ResultPrinter71.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,32 @@
33
namespace Codedungeon\PHPUnitPrettyResultPrinter;
44

55
use PHPUnit\Framework\Test;
6+
use PHPUnit\Runner\Version;
67
use PHPUnit\TextUI\ResultPrinter;
78

8-
class ResultPrinter71 extends ResultPrinter
9-
{
10-
public function startTest(Test $test): void
11-
{
12-
$this->className = \get_class($test);
13-
parent::startTest($test);
14-
}
9+
$low = version_compare(Version::series(), '7.1', '>=');
10+
$high = true; // version_compare(Version::series(),'7.1.99','<=');
1511

16-
protected function writeProgress(string $progress): void
17-
{
18-
$this->writeProgressEx($progress);
19-
}
12+
if ($low && $high) {
2013

21-
protected function writeProgressWithColor(string $progress, string $buffer): void
14+
15+
class ResultPrinter71 extends ResultPrinter
2216
{
23-
$this->writeProgressWithColorEx($progress, $buffer);
17+
public function startTest(Test $test): void
18+
{
19+
$this->className = \get_class($test);
20+
parent::startTest($test);
21+
}
22+
23+
protected function writeProgress(string $progress): void
24+
{
25+
$this->writeProgressEx($progress);
26+
}
27+
28+
protected function writeProgressWithColor(string $progress, string $buffer): void
29+
{
30+
$this->writeProgressWithColorEx($progress, $buffer);
31+
}
2432
}
25-
}
33+
34+
}

0 commit comments

Comments
 (0)