Skip to content

Commit

Permalink
Allow PHPUnit 9.3 (#504)
Browse files Browse the repository at this point in the history
* Allow PHPUnit 9.3

* Suggest warming coverage cache
  • Loading branch information
Slamdunk authored Aug 10, 2020
1 parent d51a2ad commit 88e4d87
Show file tree
Hide file tree
Showing 15 changed files with 289 additions and 232 deletions.
6 changes: 4 additions & 2 deletions .github/lint-xml-configuration/lint-xml-configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

set -ex

xmllint --noout --schema vendor/phpunit/phpunit/phpunit.xsd phpunit.xml.dist
phpunitXsd="vendor/phpunit/phpunit/phpunit.xsd"

xmllint --noout --schema "$phpunitXsd" phpunit.xml.dist
xmllint --noout --schema vendor/squizlabs/php_codesniffer/phpcs.xsd phpcs.xml.dist
xmllint --noout --schema vendor/vimeo/psalm/config.xsd psalm.xml.dist
find test/ -name "phpunit*.xml*" -not -name "phpunit-files-dirs-mix-nested.xml" -print0 | xargs -0 xmllint --noout --schema vendor/phpunit/phpunit/phpunit.xsd
find test/ -name "phpunit*.xml*" -not -name "phpunit-files-dirs-mix-nested.xml" -print0 | xargs -0 xmllint --noout --schema "$phpunitXsd"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ The corresponding logfiles are placed in your `sys_get_temp_dir()`.
See [Logging docs](docs/logging.md) for further information.

### Generating code coverage

Beginning from PHPUnit 9.3.4, it is strongly advised to warm the coverage cache before running any code-coverage
analysis, see [PHPUnit Changlog @ 9.3.4](https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-9.3.md#934---2020-08-10):

```
vendor/bin/phpunit --warm-coverage-cache
```

Examples assume your tests are located under `./test/unit`.
````
vendor/bin/paratest -p 1 --coverage-text test/unit
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
"ext-reflection": "*",
"ext-simplexml": "*",
"brianium/habitat": "^1.0",
"phpunit/php-code-coverage": "^8.0",
"phpunit/php-code-coverage": "^9.1.2",
"phpunit/php-timer": "^5.0",
"phpunit/phpunit": "^9.2",
"symfony/console": "^4.4 || ^5.0",
"symfony/process": "^4.4 || ^5.0"
"phpunit/phpunit": "^9.3.5",
"symfony/console": "^4.4 || ^5.1",
"symfony/process": "^4.4 || ^5.1"
},
"require-dev": {
"doctrine/coding-standard": "^8.1",
"phpstan/phpstan": "^0.12.33",
"phpstan/phpstan-phpunit": "^0.12.12",
"squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "^3.12"
"doctrine/coding-standard": "^8.1.0",
"phpstan/phpstan": "^0.12.37",
"phpstan/phpstan-phpunit": "^0.12.16",
"squizlabs/php_codesniffer": "^3.5.6",
"vimeo/psalm": "^3.12.2"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 0 additions & 6 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ parameters:
excludes_analyse:
- test/fixtures/*
ignoreErrors:
# @see https://github.com/phpstan/phpstan-src/pull/281
-
message: "#^Strict comparison using \\=\\=\\= between int and false will always evaluate to false\\.$#"
count: 1
path: src/Runners/PHPUnit/SqliteRunner.php

# Known fixtures
-
message: "#^Property ParaTest\\\\Runners\\\\PHPUnit\\\\ExecutableTest\\:\\:\\$process type has no value type specified in iterable type Symfony\\\\Component\\\\Process\\\\Process\\.$#"
Expand Down
61 changes: 31 additions & 30 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./test/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./test/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="ParaTest Unit Tests">
<directory>./test/Unit/</directory>
</testsuite>
<testsuite name="ParaTest Functional Tests">
<directory>./test/Functional/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
<testsuites>
<testsuite name="ParaTest Unit Tests">
<directory>./test/Unit/</directory>
</testsuite>
<testsuite name="ParaTest Functional Tests">
<directory>./test/Functional/</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
5 changes: 5 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<InternalClass errorLevel="suppress" />
<InternalMethod errorLevel="suppress" />
</issueHandlers>
</psalm>
12 changes: 9 additions & 3 deletions src/Coverage/CoverageMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use RuntimeException;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\ProcessedCodeCoverageData;
use SplFileObject;

use function array_map;
Expand Down Expand Up @@ -118,7 +119,8 @@ private function limitCoverageTests(CodeCoverage $coverage): void
return;
}

$coverage->setData(array_map(
$data = $coverage->getData(true);
$newData = array_map(
function (array $lines) {
return array_map(function ($value) {
if (! is_array($value)) {
Expand All @@ -128,7 +130,11 @@ function (array $lines) {
return array_slice($value, 0, $this->test_limit);
}, $lines);
},
$coverage->getData($raw = true)
));
$data->lineCoverage(),
);
$processedData = new ProcessedCodeCoverageData();
$processedData->setLineCoverage($newData);

$coverage->setData($processedData);
}
}
2 changes: 1 addition & 1 deletion src/Runners/PHPUnit/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function __construct(array $opts = [])
$this->maxBatchSize = (int) $opts['max-batch-size'];
$this->filter = $opts['filter'];
$this->parallelSuite = $opts['parallel-suite'];
$this->passthru = $this->parsePassthru($opts['passthru-php'] ?? null);
$this->passthru = $this->parsePassthru($opts['passthru'] ?? null);
$this->passthruPhp = $this->parsePassthru($opts['passthru-php'] ?? null);
$this->verbose = $opts['verbose'] ?? 0;
$this->coverageTestLimit = $opts['coverage-test-limit'] ?? 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Runners/PHPUnit/Worker/BaseWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function stop(): void
}

/**
* @param array<string, bool|int> $status
* @param array<string, bool|int|string> $status
*/
protected function setExitCode(array $status): void
{
Expand Down
4 changes: 2 additions & 2 deletions test/Functional/Coverage/CoverageReporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testGenerateClover(array $coverageFiles): void

static::assertFileExists($target);

$reportXml = Xml::loadFile($target);
$reportXml = (new Xml\Loader())->loadFile($target);
static::assertInstanceOf('DomDocument', $reportXml, 'Incorrect clover report xml was generated');
}

Expand All @@ -133,7 +133,7 @@ public function testGenerateCrap4J(array $coverageFiles): void

static::assertFileExists($target);

$reportXml = Xml::loadFile($target);
$reportXml = (new Xml\Loader())->loadFile($target);
static::assertInstanceOf('DomDocument', $reportXml, 'Incorrect crap4j report xml was generated');
static::assertEquals('crap_result', $reportXml->documentElement->tagName);
}
Expand Down
54 changes: 32 additions & 22 deletions test/Unit/Coverage/CoverageMergerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use ParaTest\Coverage\CoverageMerger;
use ParaTest\Tests\TestBase;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Driver\Driver;
use SebastianBergmann\CodeCoverage\Filter;
use SebastianBergmann\CodeCoverage\RawCodeCoverageData;

use function assert;

Expand All @@ -34,20 +36,24 @@ public function testSimpleMerge(): void
$secondFileFirstLine = 53;

$filter = new Filter();
$filter->addFilesToWhitelist([$firstFile, $secondFile]);
$coverage1 = new CodeCoverage(null, $filter);
$filter->includeFiles([$firstFile, $secondFile]);

$data = RawCodeCoverageData::fromXdebugWithoutPathCoverage([
$firstFile => [$firstFileFirstLine => 1],
$secondFile => [$secondFileFirstLine => 1],
]);
$coverage1 = new CodeCoverage(Driver::forLineCoverage($filter), $filter);
$coverage1->append(
[
$firstFile => [$firstFileFirstLine => 1],
$secondFile => [$secondFileFirstLine => 1],
],
$data,
'Test1'
);
$coverage2 = new CodeCoverage(null, $filter);

$data = RawCodeCoverageData::fromXdebugWithoutPathCoverage([
$firstFile => [$firstFileFirstLine => 1, 1 + $firstFileFirstLine => 1],
]);
$coverage2 = new CodeCoverage(Driver::forLineCoverage($filter), $filter);
$coverage2->append(
[
$firstFile => [$firstFileFirstLine => 1, 1 + $firstFileFirstLine => 1],
],
$data,
'Test2'
);

Expand All @@ -60,7 +66,7 @@ public function testSimpleMerge(): void

$this->assertInstanceOf(CodeCoverage::class, $coverage);

$data = $coverage->getData();
$data = $coverage->getData()->lineCoverage();

$this->assertCount(2, $data[$firstFile][$firstFileFirstLine]);
$this->assertEquals('Test1', $data[$firstFile][$firstFileFirstLine][0]);
Expand All @@ -86,20 +92,24 @@ public function testSimpleMergeLimited(): void
$secondFileFirstLine = 53;

$filter = new Filter();
$filter->addFilesToWhitelist([$firstFile, $secondFile]);
$coverage1 = new CodeCoverage(null, $filter);
$filter->includeFiles([$firstFile, $secondFile]);

$data = RawCodeCoverageData::fromXdebugWithoutPathCoverage([
$firstFile => [$firstFileFirstLine => 1],
$secondFile => [$secondFileFirstLine => 1],
]);
$coverage1 = new CodeCoverage(Driver::forLineCoverage($filter), $filter);
$coverage1->append(
[
$firstFile => [$firstFileFirstLine => 1],
$secondFile => [$secondFileFirstLine => 1],
],
$data,
'Test1'
);
$coverage2 = new CodeCoverage(null, $filter);

$data = RawCodeCoverageData::fromXdebugWithoutPathCoverage([
$firstFile => [$firstFileFirstLine => 1, 1 + $firstFileFirstLine => 1],
]);
$coverage2 = new CodeCoverage(Driver::forLineCoverage($filter), $filter);
$coverage2->append(
[
$firstFile => [$firstFileFirstLine => 1, 1 + $firstFileFirstLine => 1],
],
$data,
'Test2'
);

Expand All @@ -111,7 +121,7 @@ public function testSimpleMergeLimited(): void
assert($coverage instanceof CodeCoverage);

$this->assertInstanceOf(CodeCoverage::class, $coverage);
$data = $coverage->getData();
$data = $coverage->getData()->lineCoverage();

$this->assertCount(1, $data[$firstFile][$firstFileFirstLine]);
$this->assertCount(1, $data[$secondFile][$secondFileFirstLine]);
Expand Down
Loading

0 comments on commit 88e4d87

Please sign in to comment.