Skip to content

Commit 372ae5c

Browse files
authored
Merge pull request #9 from vemaeg/feature/phpunit-10-support
Feature/phpunit 10 support
2 parents c5c746a + 1920a38 commit 372ae5c

File tree

8 files changed

+51
-50
lines changed

8 files changed

+51
-50
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/.Build
22
/.idea
3+
/.Log
4+
/.phpunit.cache
5+
/.phpunit.result.cache
36
composer.lock

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@
2626
}
2727
],
2828
"require": {
29-
"php": "^7.0.8 || ^8.0",
29+
"php": "^8.1",
3030
"ext-dom": "*",
3131
"ext-json": "*",
3232
"ext-simplexml": "*",
33-
"phpunit/php-code-coverage": ">=5.0 <10.0",
33+
"phpunit/php-code-coverage": "^10",
3434
"symfony/console": ">=2.7 <6.0",
3535
"symfony/finder": ">=2.7 <6.0"
3636
},
3737
"require-dev": {
38-
"phpunit/phpunit": ">=6.0 <10.0",
38+
"phpunit/phpunit": "^10",
3939
"symfony/filesystem": ">=2.7 <6.0"
4040
},
4141
"suggest": {

phpunit.xml.dist

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.4/phpunit.xsd"
4-
bootstrap=".Build/vendor/autoload.php"
5-
executionOrder="depends,defects"
6-
forceCoversAnnotation="false"
7-
beStrictAboutCoversAnnotation="true"
8-
beStrictAboutOutputDuringTests="true"
9-
beStrictAboutTodoAnnotatedTests="true"
10-
verbose="true">
11-
<testsuites>
12-
<testsuite name="coverage">
13-
<directory suffix="Test.php">tests/PhpunitMerger/Command/Coverage</directory>
14-
</testsuite>
15-
<testsuite name="log">
16-
<directory suffix="Test.php">tests/PhpunitMerger/Command/Log</directory>
17-
</testsuite>
18-
</testsuites>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" bootstrap=".Build/vendor/autoload.php" executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache"
3+
beStrictAboutCoverageMetadata="true">
4+
<testsuites>
5+
<testsuite name="coverage">
6+
<directory>tests/PhpunitMerger/Command/Coverage</directory>
7+
</testsuite>
8+
<testsuite name="log">
9+
<directory>tests/PhpunitMerger/Command/Log</directory>
10+
</testsuite>
11+
</testsuites>
12+
<source>
13+
<include>
14+
<directory>src</directory>
15+
</include>
16+
</source>
1917
</phpunit>

src/PhpunitMerger/Command/CoverageCommand.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
namespace Nimut\PhpunitMerger\Command;
66

77
use SebastianBergmann\CodeCoverage\CodeCoverage;
8-
use SebastianBergmann\CodeCoverage\Driver\Driver;
8+
use SebastianBergmann\CodeCoverage\Driver\Selector;
99
use SebastianBergmann\CodeCoverage\Filter as CodeCoverageFilter;
1010
use SebastianBergmann\CodeCoverage\Report\Clover;
1111
use SebastianBergmann\CodeCoverage\Report\Cobertura;
1212
use SebastianBergmann\CodeCoverage\Report\Html\Facade;
13+
use SebastianBergmann\CodeCoverage\Report\Thresholds;
1314
use Symfony\Component\Console\Command\Command;
1415
use Symfony\Component\Console\Input\InputArgument;
1516
use Symfony\Component\Console\Input\InputInterface;
@@ -95,12 +96,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
9596

9697
private function getCodeCoverage(OutputInterface $output, $coverageCache = null)
9798
{
98-
$driver = null;
99-
$filter = null;
100-
if (method_exists(Driver::class, 'forLineCoverage')) {
101-
$filter = new CodeCoverageFilter();
102-
$driver = Driver::forLineCoverage($filter);
103-
}
99+
$filter = new CodeCoverageFilter();
100+
$driver = (new Selector())->forLineCoverage($filter);
104101

105102
$codeCoverage = new CodeCoverage($driver, $filter);
106103

@@ -141,7 +138,7 @@ private function writeCodeCoverage(CodeCoverage $codeCoverage, OutputInterface $
141138

142139
private function writeHtmlReport(CodeCoverage $codeCoverage, string $destination, int $lowUpperBound, int $highLowerBound)
143140
{
144-
$writer = new Facade($lowUpperBound, $highLowerBound);
141+
$writer = new Facade(thresholds: Thresholds::from($lowUpperBound, $highLowerBound));
145142
$writer->process($codeCoverage, $destination);
146143
}
147144
}

src/PhpunitMerger/Command/LogCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
6060
}
6161
} catch (\Exception $exception) {
6262
// Initial fallthrough
63+
// At the time of the initial test execution, the log file of the test is empty
64+
// and therefore file_get_contents returns "" which leads to the ignored error.
65+
// .travis.yml uses the app itself later to merge the junit-logs again and
66+
// creates a new log.xml
6367
}
6468
}
6569

tests/PhpunitMerger/Command/AbstractCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public function assertOutputFileNotExists()
2424
$filesystem = new Filesystem();
2525
$filesystem->remove($this->logDirectory . $this->outputFile);
2626

27-
$this->assertFileNotExists($this->logDirectory . $this->outputFile);
27+
$this->assertFileDoesNotExist($this->logDirectory . $this->outputFile);
2828
}
2929

3030
public function assertOutputDirectoryNotExists()
3131
{
3232
$filesystem = new Filesystem();
3333
$filesystem->remove($this->logDirectory . dirname($this->outputFile));
3434

35-
$this->assertDirectoryNotExists($this->logDirectory . dirname($this->outputFile));
35+
$this->assertDirectoryDoesNotExist($this->logDirectory . dirname($this->outputFile));
3636
}
3737
}

tests/PhpunitMerger/Command/Coverage/CoverageCommandTest.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Nimut\PhpunitMerger\Command\CoverageCommand;
88
use Nimut\PhpunitMerger\Tests\Command\AbstractCommandTest;
9-
use Prophecy\Argument;
109
use Symfony\Component\Console\Input\ArgvInput;
1110
use Symfony\Component\Console\Output\OutputInterface;
1211

@@ -28,11 +27,11 @@ public function testCoverageWritesOutputFile()
2827
$this->logDirectory . $this->outputFile,
2928
]
3029
);
31-
$output = $this->prophesize(OutputInterface::class);
32-
$output->write(Argument::any())->shouldNotBeCalled();
30+
$output = $this->createMock(OutputInterface::class);
31+
$output->expects(self::never())->method('write');
3332

3433
$command = new CoverageCommand();
35-
$command->run($input, $output->reveal());
34+
$command->run($input, $output);
3635

3736
$this->assertFileExists($this->logDirectory . $this->outputFile);
3837
}
@@ -47,11 +46,11 @@ public function testCoverageWritesStandardOutput()
4746
$this->logDirectory . 'coverage/',
4847
]
4948
);
50-
$output = $this->prophesize(OutputInterface::class);
51-
$output->write(Argument::type('string'))->shouldBeCalled();
49+
$output = $this->createMock(OutputInterface::class);
50+
$output->expects(self::once())->method('write')->with(self::anything());
5251

5352
$command = new CoverageCommand();
54-
$command->run($input, $output->reveal());
53+
$command->run($input, $output);
5554
}
5655

5756
public function testCoverageWritesHtmlReport()
@@ -66,11 +65,11 @@ public function testCoverageWritesHtmlReport()
6665
'--html=' . $this->logDirectory . dirname($this->outputFile),
6766
]
6867
);
69-
$output = $this->prophesize(OutputInterface::class);
70-
$output->write(Argument::type('string'))->shouldBeCalled();
68+
$output = $this->createMock(OutputInterface::class);
69+
$output->expects(self::once())->method('write')->with(self::anything());
7170

7271
$command = new CoverageCommand();
73-
$command->run($input, $output->reveal());
72+
$command->run($input, $output);
7473

7574
$this->assertFileExists($this->logDirectory . $this->outputFile);
7675
}
@@ -89,11 +88,11 @@ public function testCoverageWritesHtmlReportWithCustomBounds()
8988
'--highLowerBound=70',
9089
]
9190
);
92-
$output = $this->prophesize(OutputInterface::class);
93-
$output->write(Argument::type('string'))->shouldBeCalled();
91+
$output = $this->createMock(OutputInterface::class);
92+
$output->expects(self::once())->method('write')->with(self::anything());
9493

9594
$command = new CoverageCommand();
96-
$command->run($input, $output->reveal());
95+
$command->run($input, $output);
9796

9897
$this->assertFileExists($this->logDirectory . $this->outputFile);
9998

@@ -103,8 +102,8 @@ public function testCoverageWritesHtmlReportWithCustomBounds()
103102
$this->assertStringContainsString('<strong>High</strong>: 70% to 100%', $content);
104103
} else {
105104
// Fallback for phpunit < 7.0
106-
$this->assertContains('<strong>Low</strong>: 0% to 20%', $content);
107-
$this->assertContains('<strong>High</strong>: 70% to 100%', $content);
105+
$this->assertStringContainsString('<strong>Low</strong>: 0% to 20%', $content);
106+
$this->assertStringContainsString('<strong>High</strong>: 70% to 100%', $content);
108107
}
109108
}
110109

@@ -122,11 +121,11 @@ public function testCoverageWritesOutputFileAndHtmlReport()
122121
$this->logDirectory . $this->outputFile,
123122
]
124123
);
125-
$output = $this->prophesize(OutputInterface::class);
126-
$output->write(Argument::any())->shouldNotBeCalled();
124+
$output = $this->createMock(OutputInterface::class);
125+
$output->expects(self::never())->method('write');
127126

128127
$command = new CoverageCommand();
129-
$command->run($input, $output->reveal());
128+
$command->run($input, $output);
130129

131130
$this->assertFileExists($this->logDirectory . $this->outputFile);
132131
$this->assertFileExists($this->logDirectory . dirname($this->outputFile) . '/index.html');

tests/PhpunitMerger/Command/Log/LogCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public function testRunMergesCoverage()
2727
$this->logDirectory . $this->outputFile,
2828
]
2929
);
30-
$output = $this->prophesize(OutputInterface::class);
30+
$output = $this->createMock(OutputInterface::class);
3131

3232
$command = new LogCommand();
33-
$command->run($input, $output->reveal());
33+
$command->run($input, $output);
3434

3535
$this->assertFileExists($this->logDirectory . $this->outputFile);
3636
}

0 commit comments

Comments
 (0)