Skip to content

Commit d1368b6

Browse files
bug #46527 [Serializer] Forget partially collected traces (mtarld)
This PR was merged into the 6.1 branch. Discussion ---------- [Serializer] Forget partially collected traces | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #46522 | License | MIT If serialization fails whereas a nested normalizer has already succeeded, a trace will be created but is still partially filled. But these traces aren't useful and might be omitted. Therefore, as discussed in #46522, this change will simply make the `SerializerDataColelctor::lateCollect` method ignore partial traces. Commits ------- a0d9fceae5 [Serializer] Forget partially collected traces
2 parents ea7fe34 + f44d623 commit d1368b6

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

DataCollector/SerializerDataCollector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ public function lateCollect(): void
179179
];
180180

181181
foreach ($this->collected as $collected) {
182+
if (!isset($collected['data'])) {
183+
continue;
184+
}
185+
182186
$data = [
183187
'data' => $this->cloneVar($collected['data']),
184188
'dataType' => get_debug_type($collected['data']),

Tests/DataCollector/SerializerDataCollectorTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,27 @@ public function testReset()
276276
$this->assertSame([], $dataCollector->getData());
277277
}
278278

279+
public function testDoNotCollectPartialTraces()
280+
{
281+
$dataCollector = new SerializerDataCollector();
282+
283+
$dataCollector->collectNormalization('traceIdOne', DateTimeNormalizer::class, 1.0);
284+
$dataCollector->collectDenormalization('traceIdTwo', DateTimeNormalizer::class, 1.0);
285+
$dataCollector->collectEncoding('traceIdThree', CsvEncoder::class, 10.0);
286+
$dataCollector->collectDecoding('traceIdFour', JsonEncoder::class, 1.0);
287+
288+
$dataCollector->lateCollect();
289+
290+
$data = $dataCollector->getData();
291+
292+
$this->assertSame([], $data['serialize']);
293+
$this->assertSame([], $data['deserialize']);
294+
$this->assertSame([], $data['normalize']);
295+
$this->assertSame([], $data['denormalize']);
296+
$this->assertSame([], $data['encode']);
297+
$this->assertSame([], $data['decode']);
298+
}
299+
279300
/**
280301
* Cast cloned vars to be able to test nested values.
281302
*/

0 commit comments

Comments
 (0)