Skip to content

Commit

Permalink
Merge branch '9.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 12, 2023
2 parents 61a9ced + 8e87fb9 commit 57851ca
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-10.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ public function clear(): void
$this->cachedReport = null;
}

/**
* @internal
*/
public function clearCache(): void
{
$this->cachedReport = null;
}

/**
* Returns the filter object used.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Report/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ final class PHP
{
public function process(CodeCoverage $coverage, ?string $target = null): string
{
$coverage->clearCache();

$buffer = "<?php
return \unserialize(<<<'END_OF_COVERAGE_SERIALIZATION'" . PHP_EOL . serialize($coverage) . PHP_EOL . 'END_OF_COVERAGE_SERIALIZATION' . PHP_EOL . ');';

Expand Down
19 changes: 19 additions & 0 deletions tests/tests/Report/PhpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace SebastianBergmann\CodeCoverage\Report;

use ReflectionProperty;
use SebastianBergmann\CodeCoverage\TestCase;

final class PhpTest extends TestCase
Expand Down Expand Up @@ -43,4 +44,22 @@ public function testPHPSerialisationProducesValidCodeWhenOutputIncludesSingleQuo

$this->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));
}
}

0 comments on commit 57851ca

Please sign in to comment.