Skip to content

Commit 007ea50

Browse files
committed
Apply fixed Coderabbitai review.
1 parent 29f90d8 commit 007ea50

3 files changed

Lines changed: 76 additions & 1 deletion

File tree

src/Panel/Event/EventInspectorRenderer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ private static function groups(array $rows, Closure|null $filterUrl, string $att
262262
];
263263

264264
foreach (array_slice($groups, 0, 8, true) as $name => $total) {
265+
// PHP converts integer-string array keys to integers.
266+
$name = "{$name}";
267+
265268
$label = Fqcn::renderLabel($name) . Span::tag()->content((string) $total)->render();
269+
266270
$items[] = $filterUrl === null
267271
? Span::tag()
268272
->class('yii-debug-event-group')

tests/Panel/Event/EventInspectorRendererTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,64 @@ public function testRenderPreservesFullContextWhenBoundingPreview(string $value,
220220
);
221221
}
222222

223+
#[DataProviderExternal(EventInspectorRendererProvider::class, 'numericGroupKeys')]
224+
public function testRenderPreservesNumericGroupKeys(string $attribute, string $value, bool $withFilter): void
225+
{
226+
$row = new EventRow(
227+
10.0,
228+
$attribute === 'name' ? $value : 'event',
229+
$attribute === 'class' ? $value : 'Event',
230+
'0',
231+
$attribute === 'senderClass' ? $value : 'Worker',
232+
);
233+
234+
$eventAttribute = $attribute === 'class' ? 'class' : 'name';
235+
$filters = [];
236+
237+
$filterUrl = static function (string $attribute, string $value) use (&$filters): string {
238+
$filters[] = [$attribute, $value];
239+
240+
return "/debug?{$attribute}={$value}";
241+
};
242+
243+
$html = EventInspectorRenderer::render(
244+
[$row, $row],
245+
[],
246+
$withFilter ? $filterUrl : null,
247+
$eventAttribute,
248+
'Coverage',
249+
);
250+
251+
self::assertStringContainsString(
252+
"<span title=\"{$value}\"><strong>{$value}</strong></span><span>2</span>",
253+
$html,
254+
'Numeric group labels must retain their original string representation and complete capture count.',
255+
);
256+
self::assertSame(
257+
2,
258+
substr_count($html, 'class="yii-debug-event-group"'),
259+
'Repeated observations must share one event group and one source group.',
260+
);
261+
self::assertSame(
262+
$withFilter
263+
? [
264+
[$eventAttribute, $eventAttribute === 'class' ? $row->class : $row->name],
265+
['senderClass', $row->senderClass],
266+
]
267+
: [],
268+
$filters,
269+
'Filter callbacks must receive the original group values as strings.',
270+
);
271+
272+
if ($withFilter) {
273+
self::assertStringContainsString(
274+
"href=\"/debug?{$attribute}={$value}\"",
275+
$html,
276+
'Numeric group links must retain their filter attribute and value.',
277+
);
278+
}
279+
}
280+
223281
public function testRenderUsesEventClassAsNameWithoutInspection(): void
224282
{
225283
$row = new EventRow(10.0, 'App\\Started', 'App\\Started', '1', '');

tests/Provider/EventInspectorRendererProvider.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use function str_repeat;
1010

1111
/**
12-
* Provides capture states, preview boundaries, and group limits for {@see EventInspectorRendererTest}.
12+
* Provides capture states, preview boundaries, and group values and limits for {@see EventInspectorRendererTest}.
1313
*/
1414
final class EventInspectorRendererProvider
1515
{
@@ -53,6 +53,19 @@ public static function groupLimits(): iterable
5353
yield 'two overflow groups' => [10, 2];
5454
}
5555

56+
/**
57+
* @return iterable<string, array{string, string, bool}>
58+
*/
59+
public static function numericGroupKeys(): iterable
60+
{
61+
foreach (['name', 'class', 'senderClass'] as $attribute) {
62+
foreach (['0', '123', '-123', '0123'] as $value) {
63+
yield "{$attribute} {$value} without filters" => [$attribute, $value, false];
64+
yield "{$attribute} {$value} with filters" => [$attribute, $value, true];
65+
}
66+
}
67+
}
68+
5669
/**
5770
* @return iterable<string, array{string, string}>
5871
*/

0 commit comments

Comments
 (0)