Skip to content

Commit 57851ca

Browse files
Merge branch '9.2'
2 parents 61a9ced + 8e87fb9 commit 57851ca

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

ChangeLog-10.1.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
44

5+
## [10.1.5] - 2023-MM-DD
6+
7+
### Changed
8+
9+
* [#1011](https://github.com/sebastianbergmann/php-code-coverage/pull/1011): Avoid serialization of cache data in PHP report
10+
511
## [10.1.4] - 2023-08-31
612

713
### Fixed
@@ -41,6 +47,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
4147

4248
* The `SebastianBergmann\CodeCoverage\Filter::includeDirectory()`, `SebastianBergmann\CodeCoverage\Filter::excludeDirectory()`, and `SebastianBergmann\CodeCoverage\Filter::excludeFile()` methods are now deprecated
4349

50+
[10.1.5]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.4...main
4451
[10.1.4]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.3...10.1.4
4552
[10.1.3]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.2...10.1.3
4653
[10.1.2]: https://github.com/sebastianbergmann/php-code-coverage/compare/10.1.1...10.1.2

src/CodeCoverage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ public function clear(): void
106106
$this->cachedReport = null;
107107
}
108108

109+
/**
110+
* @internal
111+
*/
112+
public function clearCache(): void
113+
{
114+
$this->cachedReport = null;
115+
}
116+
109117
/**
110118
* Returns the filter object used.
111119
*/

src/Report/PHP.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ final class PHP
2121
{
2222
public function process(CodeCoverage $coverage, ?string $target = null): string
2323
{
24+
$coverage->clearCache();
25+
2426
$buffer = "<?php
2527
return \unserialize(<<<'END_OF_COVERAGE_SERIALIZATION'" . PHP_EOL . serialize($coverage) . PHP_EOL . 'END_OF_COVERAGE_SERIALIZATION' . PHP_EOL . ');';
2628

tests/tests/Report/PhpTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
namespace SebastianBergmann\CodeCoverage\Report;
1111

12+
use ReflectionProperty;
1213
use SebastianBergmann\CodeCoverage\TestCase;
1314

1415
final class PhpTest extends TestCase
@@ -43,4 +44,22 @@ public function testPHPSerialisationProducesValidCodeWhenOutputIncludesSingleQuo
4344

4445
$this->assertEquals($coverage, $unserialized);
4546
}
47+
48+
public function testCacheDataNeverGetSaved(): void
49+
{
50+
$coverage = $this->getLineCoverageForBankAccount();
51+
52+
// Warm up cache
53+
$coverage->getReport();
54+
55+
$refProperty = new ReflectionProperty($coverage, 'cachedReport');
56+
$refProperty->setAccessible(true);
57+
58+
$this->assertNotNull($refProperty->getValue($coverage));
59+
60+
/* @noinspection UnusedFunctionResultInspection */
61+
(new PHP)->process($coverage, self::$TEST_TMP_PATH . '/serialized.php');
62+
63+
$this->assertNull($refProperty->getValue($coverage));
64+
}
4665
}

0 commit comments

Comments
 (0)