Skip to content

Commit 67f7496

Browse files
committed
Apply fixed Coderabbitai review.
1 parent 2e23950 commit 67f7496

3 files changed

Lines changed: 98 additions & 2 deletions

File tree

‎src/PanelView.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function blocks(): array
117117
*/
118118
public function callout(Tone $tone, mixed ...$content): self
119119
{
120-
return $this->append(self::paragraphBlock(array_values($content), $tone));
120+
return $this->append(self::paragraphBlock($content, $tone));
121121
}
122122

123123
/**
@@ -271,7 +271,7 @@ public function overview(array $values, bool $compact = false): self
271271
*/
272272
public function paragraph(mixed ...$content): self
273273
{
274-
return $this->append(self::paragraphBlock(array_values($content), null));
274+
return $this->append(self::paragraphBlock($content, null));
275275
}
276276

277277
/**

‎tests/PanelViewTest.php‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66

77
use InvalidArgumentException;
88
use PHPForge\Debug\{ColumnStyle, PanelView, Tone};
9+
use PHPForge\Debug\Tests\Provider\InlineScalarProvider;
10+
use PHPUnit\Framework\Attributes\DataProviderExternal;
911
use PHPUnit\Framework\TestCase;
1012
use stdClass;
1113

1214
/**
1315
* Unit tests for the validated shapes {@see PanelView} exports to the host renderer.
16+
*
17+
* {@see InlineScalarProvider} for test case data providers.
1418
*/
1519
final class PanelViewTest extends TestCase
1620
{
@@ -116,6 +120,72 @@ public function testMetricsAndFieldsShareOneLabelAndValueShape(): void
116120
);
117121
}
118122

123+
/**
124+
* @param array{kind: 'text', value: string, style: 'plain'} $expected
125+
*/
126+
#[DataProviderExternal(InlineScalarProvider::class, 'plainText')]
127+
public function testScalarContentBecomesPlainInlineText(mixed $value, array $expected): void
128+
{
129+
self::assertSame(
130+
[['kind' => 'paragraph', 'content' => [$expected], 'tone' => null]],
131+
PanelView::create()->paragraph($value)->blocks(),
132+
'Conversion must keep the literal and the plain style.',
133+
);
134+
self::assertSame(
135+
[
136+
[
137+
'kind' => 'overview',
138+
'fields' => [['label' => 'Field', 'value' => $expected]],
139+
'compact' => false,
140+
],
141+
],
142+
PanelView::create()->overview(['Field' => $value])->blocks(),
143+
'Overview fields must convert identically.',
144+
);
145+
}
146+
147+
public function testStringKeyedSpreadContentStaysAList(): void
148+
{
149+
$parts = ['first' => 'A', 'second' => PanelView::code('B')];
150+
151+
$content = [PanelView::text('A'), PanelView::code('B')];
152+
153+
self::assertSame(
154+
[['kind' => 'paragraph', 'content' => $content, 'tone' => null]],
155+
PanelView::create()->paragraph(...$parts)->blocks(),
156+
'String keys must not reach the paragraph content.',
157+
);
158+
self::assertSame(
159+
[['kind' => 'paragraph', 'content' => $content, 'tone' => Tone::WARNING]],
160+
PanelView::create()->callout(Tone::WARNING, ...$parts)->blocks(),
161+
'String keys must not reach the callout content.',
162+
);
163+
}
164+
165+
public function testTableKeepsEveryStyledColumnUnderItsIndex(): void
166+
{
167+
$view = PanelView::create()
168+
->table(
169+
['Key', 'Value', 'Hits'],
170+
[['home', 'cached', 3]],
171+
styles: [0 => ColumnStyle::MONOSPACE, 2 => ColumnStyle::NUMBER],
172+
);
173+
174+
self::assertSame(
175+
[
176+
[
177+
'kind' => 'table',
178+
'headers' => ['Key', 'Value', 'Hits'],
179+
'rows' => [[PanelView::text('home'), PanelView::text('cached'), PanelView::text('3')]],
180+
'styles' => [0 => ColumnStyle::MONOSPACE, 2 => ColumnStyle::NUMBER],
181+
'collapsible' => false,
182+
],
183+
],
184+
$view->blocks(),
185+
'Every styled column must survive, not only the first.',
186+
);
187+
}
188+
119189
public function testThrowInvalidArgumentExceptionForAssociativeParagraph(): void
120190
{
121191
$this->expectException(InvalidArgumentException::class);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PHPForge\Debug\Tests\Provider;
6+
7+
use PHPForge\Debug\Tests\PanelViewTest;
8+
9+
/**
10+
* Provides scalar and `null` inputs whose conversion to plain inline text is verified by {@see PanelViewTest}.
11+
*/
12+
final class InlineScalarProvider
13+
{
14+
/**
15+
* @return iterable<string, array{mixed, array{kind: 'text', value: string, style: 'plain'}}>
16+
*/
17+
public static function plainText(): iterable
18+
{
19+
yield 'false' => [false, ['kind' => 'text', 'value' => 'false', 'style' => 'plain']];
20+
yield 'float' => [1.5, ['kind' => 'text', 'value' => '1.5', 'style' => 'plain']];
21+
yield 'int' => [7, ['kind' => 'text', 'value' => '7', 'style' => 'plain']];
22+
yield 'null' => [null, ['kind' => 'text', 'value' => 'null', 'style' => 'plain']];
23+
yield 'string' => ['<raw>', ['kind' => 'text', 'value' => '<raw>', 'style' => 'plain']];
24+
yield 'true' => [true, ['kind' => 'text', 'value' => 'true', 'style' => 'plain']];
25+
}
26+
}

0 commit comments

Comments
 (0)