diff --git a/ChangeLog-10.1.md b/ChangeLog-10.1.md index fdee9eb79..33b77792d 100644 --- a/ChangeLog-10.1.md +++ b/ChangeLog-10.1.md @@ -2,6 +2,12 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## [10.1.5] - 2023-MM-DD + +### Changed + +* [#1011](https://github.com/sebastianbergmann/php-code-coverage/pull/1011): Avoid serialization of cache data in PHP report + ## [10.1.4] - 2023-08-31 ### Fixed @@ -41,6 +47,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt * The `SebastianBergmann\CodeCoverage\Filter::includeDirectory()`, `SebastianBergmann\CodeCoverage\Filter::excludeDirectory()`, and `SebastianBergmann\CodeCoverage\Filter::excludeFile()` methods are now deprecated +[10.1.5]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.4...main [10.1.4]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.3...10.1.4 [10.1.3]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.2...10.1.3 [10.1.2]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.1...10.1.2 diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php index 43541bcea..f22b5f76c 100644 --- a/src/CodeCoverage.php +++ b/src/CodeCoverage.php @@ -106,6 +106,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)); + } }