diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php index bdf9c64c3..ba4f1f8c3 100644 --- a/src/CodeCoverage.php +++ b/src/CodeCoverage.php @@ -150,6 +150,14 @@ public function clear(): void $this->cachedReport = null; } + /** + * @internal + */ + public function clearCache(): void + { + $this->cachedReport = null; + } + /** * Returns the filter object used. */ diff --git a/src/Report/PHP.php b/src/Report/PHP.php index 2058fb39a..1f8186d04 100644 --- a/src/Report/PHP.php +++ b/src/Report/PHP.php @@ -21,6 +21,8 @@ final class PHP { public function process(CodeCoverage $coverage, ?string $target = null): string { + $coverage->clearCache(); + $buffer = "assertEquals($coverage, $unserialized); } + + public function testCacheDataNeverGetSaved(): void + { + $coverage = $this->getLineCoverageForBankAccount(); + + // Warm up cache + $coverage->getReport(); + + $refProperty = new ReflectionProperty($coverage, 'cachedReport'); + $refProperty->setAccessible(true); + + $this->assertNotNull($refProperty->getValue($coverage)); + + /* @noinspection UnusedFunctionResultInspection */ + (new PHP)->process($coverage, self::$TEST_TMP_PATH . '/serialized.php'); + + $this->assertNull($refProperty->getValue($coverage)); + } }