Repository navigation
Expand file tree
/
Copy pathDebugSnapshotTest.php
More file actions
106 lines (90 loc) · 3.08 KB
/
Copy pathDebugSnapshotTest.php
File metadata and controls
106 lines (90 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
declare(strict_types=1);
namespace PHPForge\Debug\Tests\Storage;
use PHPForge\Debug\Storage\{DebugSnapshot, HydrationException, PanelFailure, RequestSummary};
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use RuntimeException;
/**
* Unit tests for {@see DebugSnapshot} covering its version guard and serialized panel failures.
*/
#[Group('storage')]
final class DebugSnapshotTest extends TestCase
{
public function testJsonSerializeProjectsPanelFailuresToArrays(): void
{
$snapshot = new DebugSnapshot(
$this->summary(),
[],
[
'log' => PanelFailure::fromThrowable(PanelFailure::CAPTURE, new RuntimeException('boom')),
],
);
$failures = $snapshot->jsonSerialize()['failures'] ?? null;
self::assertIsArray(
$failures,
'The failure collection must serialize as an array.',
);
$failure = $failures['log'] ?? null;
self::assertIsArray(
$failure,
'Serialized failures must not expose storage objects.',
);
self::assertSame(
PanelFailure::CAPTURE,
$failure['stage'] ?? null,
'The failure stage must be retained.',
);
$exception = $failure['exception'] ?? null;
self::assertIsArray(
$exception,
'The exception must serialize as an array.',
);
self::assertSame(
'boom',
$exception['message'] ?? null,
'The serialized exception payload must be retained.',
);
}
public function testSnapshotHydratesPanelsAndFailures(): void
{
$captured = new DebugSnapshot(
$this->summary(),
['request' => ['statusCode' => 200]],
['log' => PanelFailure::fromThrowable(PanelFailure::CAPTURE, new RuntimeException('boom'))],
);
$payload = $captured->jsonSerialize();
$snapshot = DebugSnapshot::fromArray($payload);
self::assertSame(
$payload,
$snapshot->jsonSerialize(),
'Snapshot envelope must round-trip exactly.',
);
}
public function testThrowHydrationExceptionWhenTheStorageVersionDoesNotMatch(): void
{
$this->expectException(HydrationException::class);
$this->expectExceptionMessage(
"Invalid debug snapshot value at '\$.version': expected storage version " . DebugSnapshot::VERSION . '.',
);
DebugSnapshot::fromArray(
[
'version' => DebugSnapshot::VERSION - 1,
'summary' => [],
'panels' => [],
'failures' => [],
],
);
}
/**
* Creates representative request metadata for snapshot tests.
*
* @return RequestSummary Representative request metadata.
*/
private function summary(): RequestSummary
{
return RequestSummary::create('tag-1')
->withRequest('https://example.test/', 'GET', '127.0.0.1', 1_700_000_000.0)
->withResponse(200);
}
}