Skip to content

Commit

Permalink
Upgraded for PHPUnit 10.
Browse files Browse the repository at this point in the history
  • Loading branch information
thirsch committed Jul 18, 2023
1 parent fab082e commit abf6e55
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/.Build
/.idea
/.Log
/.phpunit.cache
/.phpunit.result.cache
composer.lock
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
}
],
"require": {
"php": "^7.0.8 || ^8.0",
"php": "^8.1",
"ext-dom": "*",
"ext-json": "*",
"ext-simplexml": "*",
"phpunit/php-code-coverage": ">=5.0 <10.0",
"phpunit/php-code-coverage": "^10",
"symfony/console": ">=2.7 <6.0",
"symfony/finder": ">=2.7 <6.0"
},
"require-dev": {
"phpunit/phpunit": ">=6.0 <10.0",
"phpunit/phpunit": "^10",
"symfony/filesystem": ">=2.7 <6.0"
},
"suggest": {
Expand Down
32 changes: 15 additions & 17 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.4/phpunit.xsd"
bootstrap=".Build/vendor/autoload.php"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuites>
<testsuite name="coverage">
<directory suffix="Test.php">tests/PhpunitMerger/Command/Coverage</directory>
</testsuite>
<testsuite name="log">
<directory suffix="Test.php">tests/PhpunitMerger/Command/Log</directory>
</testsuite>
</testsuites>
<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"
beStrictAboutCoverageMetadata="true">
<testsuites>
<testsuite name="coverage">
<directory>tests/PhpunitMerger/Command/Coverage</directory>
</testsuite>
<testsuite name="log">
<directory>tests/PhpunitMerger/Command/Log</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
13 changes: 5 additions & 8 deletions src/PhpunitMerger/Command/CoverageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
namespace Nimut\PhpunitMerger\Command;

use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Driver\Driver;
use SebastianBergmann\CodeCoverage\Driver\Selector;
use SebastianBergmann\CodeCoverage\Filter as CodeCoverageFilter;
use SebastianBergmann\CodeCoverage\Report\Clover;
use SebastianBergmann\CodeCoverage\Report\Cobertura;
use SebastianBergmann\CodeCoverage\Report\Html\Facade;
use SebastianBergmann\CodeCoverage\Report\Thresholds;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -94,12 +95,8 @@ protected function execute(InputInterface $input, OutputInterface $output)

private function getCodeCoverage(OutputInterface $output, $coverageCache = null)
{
$driver = null;
$filter = null;
if (method_exists(Driver::class, 'forLineCoverage')) {
$filter = new CodeCoverageFilter();
$driver = Driver::forLineCoverage($filter);
}
$filter = new CodeCoverageFilter();
$driver = (new Selector())->forLineCoverage($filter);

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

Expand Down Expand Up @@ -131,7 +128,7 @@ private function writeCodeCoverage(CodeCoverage $codeCoverage, OutputInterface $

private function writeHtmlReport(CodeCoverage $codeCoverage, string $destination, int $lowUpperBound, int $highLowerBound)
{
$writer = new Facade($lowUpperBound, $highLowerBound);
$writer = new Facade(thresholds: Thresholds::from($lowUpperBound, $highLowerBound));
$writer->process($codeCoverage, $destination);
}
}
4 changes: 4 additions & 0 deletions src/PhpunitMerger/Command/LogCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
} catch (\Exception $exception) {
// Initial fallthrough
// At the time of the initial test execution, the log file of the test is empty
// and therefore file_get_contents returns "" which leads to the ignored error.
// .travis.yml uses the app itself later to merge the junit-logs again and
// creates a new log.xml
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/PhpunitMerger/Command/AbstractCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public function assertOutputFileNotExists()
$filesystem = new Filesystem();
$filesystem->remove($this->logDirectory . $this->outputFile);

$this->assertFileNotExists($this->logDirectory . $this->outputFile);
$this->assertFileDoesNotExist($this->logDirectory . $this->outputFile);
}

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

$this->assertDirectoryNotExists($this->logDirectory . dirname($this->outputFile));
$this->assertDirectoryDoesNotExist($this->logDirectory . dirname($this->outputFile));
}
}
35 changes: 17 additions & 18 deletions tests/PhpunitMerger/Command/Coverage/CoverageCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Nimut\PhpunitMerger\Command\CoverageCommand;
use Nimut\PhpunitMerger\Tests\Command\AbstractCommandTest;
use Prophecy\Argument;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\OutputInterface;

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

$command = new CoverageCommand();
$command->run($input, $output->reveal());
$command->run($input, $output);

$this->assertFileExists($this->logDirectory . $this->outputFile);
}
Expand All @@ -47,11 +46,11 @@ public function testCoverageWritesStandardOutput()
$this->logDirectory . 'coverage/',
]
);
$output = $this->prophesize(OutputInterface::class);
$output->write(Argument::type('string'))->shouldBeCalled();
$output = $this->createMock(OutputInterface::class);
$output->expects(self::once())->method('write')->with(self::anything());

$command = new CoverageCommand();
$command->run($input, $output->reveal());
$command->run($input, $output);
}

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

$command = new CoverageCommand();
$command->run($input, $output->reveal());
$command->run($input, $output);

$this->assertFileExists($this->logDirectory . $this->outputFile);
}
Expand All @@ -89,11 +88,11 @@ public function testCoverageWritesHtmlReportWithCustomBounds()
'--highLowerBound=70',
]
);
$output = $this->prophesize(OutputInterface::class);
$output->write(Argument::type('string'))->shouldBeCalled();
$output = $this->createMock(OutputInterface::class);
$output->expects(self::once())->method('write')->with(self::anything());

$command = new CoverageCommand();
$command->run($input, $output->reveal());
$command->run($input, $output);

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

Expand All @@ -103,8 +102,8 @@ public function testCoverageWritesHtmlReportWithCustomBounds()
$this->assertStringContainsString('<strong>High</strong>: 70% to 100%', $content);
} else {
// Fallback for phpunit < 7.0
$this->assertContains('<strong>Low</strong>: 0% to 20%', $content);
$this->assertContains('<strong>High</strong>: 70% to 100%', $content);
$this->assertStringContainsString('<strong>Low</strong>: 0% to 20%', $content);
$this->assertStringContainsString('<strong>High</strong>: 70% to 100%', $content);
}
}

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

$command = new CoverageCommand();
$command->run($input, $output->reveal());
$command->run($input, $output);

$this->assertFileExists($this->logDirectory . $this->outputFile);
$this->assertFileExists($this->logDirectory . dirname($this->outputFile) . '/index.html');
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpunitMerger/Command/Log/LogCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public function testRunMergesCoverage()
$this->logDirectory . $this->outputFile,
]
);
$output = $this->prophesize(OutputInterface::class);
$output = $this->createMock(OutputInterface::class);

$command = new LogCommand();
$command->run($input, $output->reveal());
$command->run($input, $output);

$this->assertFileExists($this->logDirectory . $this->outputFile);
}
Expand Down

0 comments on commit abf6e55

Please sign in to comment.