Skip to content

Commit 1644b0c

Browse files
committed
Apply fixed Coderabbitai review.
1 parent 4a2b8b5 commit 1644b0c

7 files changed

Lines changed: 302 additions & 50 deletions

File tree

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"ext-intl": "*",
2525
"ext-mbstring": "*",
2626
"ui-awesome/html": "^0.6",
27-
"ui-awesome/html-core-component": "^0.5@dev",
27+
"ui-awesome/html-core-component": "^0.4",
2828
"ui-awesome/html-helper": "^0.7",
2929
"ui-awesome/html-interop": "^0.4",
3030
"ui-awesome/html-mixin": "^0.8.2",

‎src/Panel/Config/ConfigMessage.php‎

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,6 @@ enum ConfigMessage: string
5454
*/
5555
case CURRENT_LANGUAGE = 'Current language';
5656

57-
/**
58-
* Overview field label of the debug flag.
59-
*/
60-
case DEBUG_MODE = 'Debug mode';
61-
62-
/**
63-
* Badge label of a disabled debug flag.
64-
*/
65-
case DEBUG_OFF = 'off';
66-
67-
/**
68-
* Badge label of an enabled debug flag.
69-
*/
70-
case DEBUG_ON = 'on';
71-
7257
/**
7358
* Explanation of the empty state when the capture carried no package roster.
7459
*/
@@ -84,16 +69,6 @@ enum ConfigMessage: string
8469
*/
8570
case ENVIRONMENT = 'Environment';
8671

87-
/**
88-
* Badge label of a bundled PHP extension reported as loaded.
89-
*/
90-
case EXTENSION_LOADED = 'loaded';
91-
92-
/**
93-
* Badge label of a bundled PHP extension reported as missing.
94-
*/
95-
case EXTENSION_MISSING = 'missing';
96-
9772
/**
9873
* Suffix appended to a single installed extension in the summary header.
9974
*/
@@ -109,11 +84,6 @@ enum ConfigMessage: string
10984
*/
11085
case ID = 'config';
11186

112-
/**
113-
* `sprintf()` template of the heading above the installed-package roster.
114-
*/
115-
case INSTALLED = 'Installed extensions (%d)';
116-
11787
/**
11888
* Title of the installed-extension section.
11989
*/
@@ -149,11 +119,6 @@ enum ConfigMessage: string
149119
*/
150120
case PACKAGE_MEMCACHED = 'Memcached';
151121

152-
/**
153-
* Header of the package name column.
154-
*/
155-
case PACKAGE_NAME = 'Package';
156-
157122
/**
158123
* Label of the Xdebug extension in the runtime overview.
159124
*/
@@ -190,14 +155,19 @@ enum ConfigMessage: string
190155
case SOURCE_LANGUAGE = 'Source language';
191156

192157
/**
193-
* Panel title used in the debugger navigation.
158+
* Negative state, shown as the debug-flag caption and on the pill of a PHP extension the runtime did not load.
194159
*/
195-
case TITLE = 'Configuration';
160+
case STATE_OFF = 'off';
196161

197162
/**
198-
* Header of the package version column.
163+
* Positive state, shown as the debug-flag caption and on the pill of a PHP extension the runtime loaded.
199164
*/
200-
case VERSION = 'Version';
165+
case STATE_ON = 'on';
166+
167+
/**
168+
* Panel title used in the debugger navigation.
169+
*/
170+
case TITLE = 'Configuration';
201171

202172
/**
203173
* Overview field label of the framework version.

‎src/Panel/Config/ConfigPanel.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public function present(array $data): PanelView
9292
$version = self::text($php, 'version');
9393

9494
$debug = ($application['debug'] ?? false) === true
95-
? ConfigMessage::DEBUG_ON->value
96-
: ConfigMessage::DEBUG_OFF->value;
95+
? ConfigMessage::STATE_ON->value
96+
: ConfigMessage::STATE_OFF->value;
9797

9898
$view = PanelView::create()
9999
->summary(
@@ -143,7 +143,7 @@ public function present(array $data): PanelView
143143

144144
$pills[] = PanelView::pill(
145145
$label->value,
146-
$loaded ? ConfigMessage::DEBUG_ON->value : ConfigMessage::DEBUG_OFF->value,
146+
$loaded ? ConfigMessage::STATE_ON->value : ConfigMessage::STATE_OFF->value,
147147
$loaded,
148148
);
149149
}

‎tests/Panel/Config/ConfigPanelTest.php‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@
2828
#[Group('config')]
2929
final class ConfigPanelTest extends TestCase
3030
{
31+
public function testARosterEntryThatIsNotAnObjectIsSkipped(): void
32+
{
33+
$view = self::present(
34+
[
35+
'extensions' => [
36+
'php-forge/debug',
37+
'yiisoft/arrays' => ['name' => 'yiisoft/arrays', 'version' => '3.2.1'],
38+
],
39+
],
40+
);
41+
42+
$roster = self::section(self::blockAt($view, 3));
43+
44+
self::assertSame(
45+
1,
46+
$roster['count'],
47+
'A malformed roster entry must not reach the tally.',
48+
);
49+
self::assertSame(
50+
[['kind' => 'package', 'name' => 'arrays', 'version' => 'v3.2.1']],
51+
self::manifest(self::blockAt($roster['content'], 0))['packages'],
52+
'Only the well-formed entry must survive.',
53+
);
54+
}
3155
public function testASingleInstalledExtensionUsesTheSingularLabel(): void
3256
{
3357
$view = self::present(
@@ -423,5 +447,4 @@ private static function section(array $block): array
423447
default => self::fail('Each part of the panel must be a titled section.'),
424448
};
425449
}
426-
427450
}

‎tests/Panel/PanelRendererTest.php‎

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use PHPUnit\Framework\Attributes\DataProviderExternal;
1313
use PHPUnit\Framework\TestCase;
1414

15+
use function array_fill;
16+
use function substr_count;
17+
1518
/**
1619
* Unit tests for {@see PanelRenderer} rendering provider-owned declarative panels through the debugger frontend.
1720
*
@@ -63,6 +66,33 @@ public function testCollapseRequiresOptInAndMoreRowsThanThreshold(int $count, bo
6366
);
6467
}
6568

69+
public function testFactStripRendersEveryPairAsADefinitionList(): void
70+
{
71+
$html = PanelRenderer::render(
72+
'Custom',
73+
PanelView::create()->facts(
74+
PanelView::fact('Charset', 'UTF-8'),
75+
PanelView::fact('Current language', 'en'),
76+
),
77+
);
78+
79+
self::assertStringContainsString(
80+
'<dl class="yii-debug-fact-strip">',
81+
$html,
82+
'Strip must be a definition list.',
83+
);
84+
self::assertStringContainsString(
85+
"<dt class=\"yii-debug-fact-label\">\nCharset\n</dt>",
86+
$html,
87+
'Label must be the term of its pair.',
88+
);
89+
self::assertStringContainsString(
90+
'<dd class="yii-debug-fact-value" title="UTF-8">',
91+
$html,
92+
'Value must carry the untruncated text as its title.',
93+
);
94+
}
95+
6696
public function testFilterableTablesReuseTheExistingRowFilter(): void
6797
{
6898
$html = PanelRenderer::render(
@@ -275,6 +305,46 @@ public function testLinksRenderAsAnchorsAndIsolateExternalTargets(): void
275305
);
276306
}
277307

308+
public function testManifestGroupsPackagesUnderTheirVendorWithATally(): void
309+
{
310+
$html = PanelRenderer::render(
311+
'Custom',
312+
PanelView::create()->manifest(
313+
'yiisoft/',
314+
PanelView::package('aliases', 'v3.1.1'),
315+
PanelView::package('arrays', 'v3.2.1'),
316+
),
317+
);
318+
319+
self::assertStringContainsString(
320+
'class="yii-debug-manifest" aria-label="yiisoft/"',
321+
$html,
322+
'Manifest must be labelled by its vendor.',
323+
);
324+
self::assertStringContainsString(
325+
'2 packages',
326+
$html,
327+
'Tally must be pluralised.',
328+
);
329+
self::assertStringContainsString(
330+
'<span class="yii-debug-manifest-version">v3.1.1</span>',
331+
$html,
332+
'Version must sit beside its package name.',
333+
);
334+
}
335+
336+
public function testManifestTallyUsesTheSingularForOnePackage(): void
337+
{
338+
self::assertStringContainsString(
339+
'1 package',
340+
PanelRenderer::render(
341+
'Custom',
342+
PanelView::create()->manifest('yiisoft/', PanelView::package('aliases', 'v3.1.1')),
343+
),
344+
'A single package must use the singular tally.',
345+
);
346+
}
347+
278348
public function testPanelsWithoutSummaryMetricsOmitTheSummaryStrip(): void
279349
{
280350
$html = PanelRenderer::render(
@@ -299,6 +369,60 @@ public function testPanelsWithoutSummaryMetricsOmitTheSummaryStrip(): void
299369
);
300370
}
301371

372+
public function testPillStripRendersEachSubjectWithItsState(): void
373+
{
374+
$html = PanelRenderer::render(
375+
'Custom',
376+
PanelView::create()->pills(
377+
PanelView::pill('APCu', 'on', true),
378+
PanelView::pill('Memcache', 'off', false),
379+
),
380+
);
381+
382+
self::assertStringContainsString(
383+
'<div class="yii-debug-ext-strip">',
384+
$html,
385+
'Pills must share one strip.',
386+
);
387+
self::assertStringContainsString(
388+
'yii-debug-ext-pill is-on',
389+
$html,
390+
'An enabled subject must read as on.',
391+
);
392+
self::assertStringContainsString(
393+
'yii-debug-ext-pill is-off',
394+
$html,
395+
'A disabled subject must read as off.',
396+
);
397+
}
398+
399+
public function testReadoutRowRendersCardsAndDropsAnEmptyCaption(): void
400+
{
401+
$html = PanelRenderer::render(
402+
'Custom',
403+
PanelView::create()->readouts(
404+
PanelView::readout('Yii', '3', 'framework'),
405+
PanelView::readout('PHP', '8.5.9'),
406+
),
407+
);
408+
409+
self::assertStringContainsString(
410+
'<div class="yii-debug-readout-grid">',
411+
$html,
412+
'Cards must share one row.',
413+
);
414+
self::assertStringContainsString(
415+
'<span class="yii-debug-readout-meta">framework</span>',
416+
$html,
417+
'A caption must follow its value.',
418+
);
419+
self::assertSame(
420+
1,
421+
substr_count($html, 'yii-debug-readout-meta'),
422+
'A card without a caption must omit the element.',
423+
);
424+
}
425+
302426
public function testRenderUsesExistingFrontendAndEscapesEveryTextPosition(): void
303427
{
304428
$hostile = '<script>alert("test")</script>';
@@ -366,6 +490,52 @@ public function testRenderUsesExistingFrontendAndEscapesEveryTextPosition(): voi
366490
);
367491
}
368492

493+
public function testSectionWithoutATallyOmitsTheCount(): void
494+
{
495+
self::assertStringNotContainsString(
496+
'yii-debug-section-count',
497+
PanelRenderer::render(
498+
'Custom',
499+
PanelView::create()->section('//', 'Application details', PanelView::create()->paragraph('None.')),
500+
),
501+
'A section without a tally must omit the count element.',
502+
);
503+
}
504+
505+
public function testSectionWrapsItsBlocksUnderAMarkedTitle(): void
506+
{
507+
$html = PanelRenderer::render(
508+
'Custom',
509+
PanelView::create()->section(
510+
'::',
511+
'Installed extensions',
512+
PanelView::create()->paragraph('Nothing captured.'),
513+
47,
514+
),
515+
);
516+
517+
self::assertStringContainsString(
518+
'class="yii-debug-section" aria-label="Installed extensions"',
519+
$html,
520+
'Section must be labelled by its title.',
521+
);
522+
self::assertStringContainsString(
523+
'<span class="yii-debug-section-mark">::</span>',
524+
$html,
525+
'Mark must precede the title.',
526+
);
527+
self::assertStringContainsString(
528+
'<span class="yii-debug-section-count">47</span>',
529+
$html,
530+
'Tally must close the title.',
531+
);
532+
self::assertStringContainsString(
533+
'Nothing captured.',
534+
$html,
535+
'Section must render its own blocks.',
536+
);
537+
}
538+
369539
public function testSqlStatementsAreHighlightedAndEscaped(): void
370540
{
371541
$html = PanelRenderer::render(

0 commit comments

Comments
 (0)