Skip to content

Commit 305ebf5

Browse files
Only export properties for configuration, code coverage data, and test results when serializing CodeCoverage for #1090
1 parent ff7895b commit 305ebf5

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

ChangeLog-12.3.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+
## [12.3.5] - 2025-MM-DD
6+
7+
### Changed
8+
9+
* [#1090](https://github.com/sebastianbergmann/php-code-coverage/issues/1090): Only export properties for configuration, code coverage data, and test results when serializing `CodeCoverage`
10+
511
## [12.3.4] - 2025-08-29
612

713
### Changed
@@ -38,6 +44,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
3844

3945
* [#1080](https://github.com/sebastianbergmann/php-code-coverage/pull/1080): Support for reporting code coverage information in OpenClover XML format; unlike the existing Clover XML reporter, which remains unchanged, the XML documents generated by this new reporter validate against the OpenClover project's XML schema definition, with one exception: we do not generate the `<testproject>` element. This feature is experimental and the generated XML might change in order to improve compliance with the OpenClover project's XML schema definition further. Such changes will be made in bugfix and/or minor releases even if they break backward compatibility.
4046

47+
[12.3.5]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.3.4...main
4148
[12.3.4]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.3.3...12.3.4
4249
[12.3.3]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.3.2...12.3.3
4350
[12.3.2]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.3.1...12.3.2

src/CodeCoverage.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,27 @@ public function __construct(Driver $driver, Filter $filter)
7676
$this->data = new ProcessedCodeCoverageData;
7777
}
7878

79+
/**
80+
* @return non-empty-list<non-empty-string>
81+
*/
82+
public function __sleep(): array
83+
{
84+
return [
85+
// Configuration
86+
'cacheDirectory',
87+
'checkForUnintentionallyCoveredCode',
88+
'includeUncoveredFiles',
89+
'ignoreDeprecatedCode',
90+
'parentClassesExcludedFromUnintentionallyCoveredCodeCheck',
91+
'useAnnotationsForIgnoringCode',
92+
'filter',
93+
94+
// Data
95+
'data',
96+
'tests',
97+
];
98+
}
99+
79100
/**
80101
* Returns the code coverage information as a graph of node objects.
81102
*/

tests/tests/Report/PhpTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace SebastianBergmann\CodeCoverage\Report;
1111

1212
use ReflectionProperty;
13+
use SebastianBergmann\CodeCoverage\CodeCoverage;
1314
use SebastianBergmann\CodeCoverage\TestCase;
1415

1516
final class PhpTest extends TestCase
@@ -28,7 +29,9 @@ public function testPHPSerialisationProducesValidCode(): void
2829

2930
$unserialized = require TEST_FILES_PATH . 'tmp/serialized.php';
3031

31-
$this->assertEquals($coverage, $unserialized);
32+
$this->assertInstanceOf(CodeCoverage::class, $unserialized);
33+
$this->assertEquals($coverage->getData(), $unserialized->getData());
34+
$this->assertEquals($coverage->getTests(), $unserialized->getTests());
3235
}
3336

3437
public function testPHPSerialisationProducesValidCodeWhenOutputIncludesSingleQuote(): void
@@ -40,7 +43,9 @@ public function testPHPSerialisationProducesValidCodeWhenOutputIncludesSingleQuo
4043

4144
$unserialized = require TEST_FILES_PATH . 'tmp/serialized.php';
4245

43-
$this->assertEquals($coverage, $unserialized);
46+
$this->assertInstanceOf(CodeCoverage::class, $unserialized);
47+
$this->assertEquals($coverage->getData(), $unserialized->getData());
48+
$this->assertEquals($coverage->getTests(), $unserialized->getTests());
4449
}
4550

4651
public function testCacheDataNeverGetSaved(): void

0 commit comments

Comments
 (0)