|
6 | 6 |
|
7 | 7 | use InvalidArgumentException; |
8 | 8 | use PHPForge\Debug\{ColumnStyle, PanelView, Tone}; |
| 9 | +use PHPForge\Debug\Tests\Provider\InlineScalarProvider; |
| 10 | +use PHPUnit\Framework\Attributes\DataProviderExternal; |
9 | 11 | use PHPUnit\Framework\TestCase; |
10 | 12 | use stdClass; |
11 | 13 |
|
12 | 14 | /** |
13 | 15 | * Unit tests for the validated shapes {@see PanelView} exports to the host renderer. |
| 16 | + * |
| 17 | + * {@see InlineScalarProvider} for test case data providers. |
14 | 18 | */ |
15 | 19 | final class PanelViewTest extends TestCase |
16 | 20 | { |
@@ -116,6 +120,72 @@ public function testMetricsAndFieldsShareOneLabelAndValueShape(): void |
116 | 120 | ); |
117 | 121 | } |
118 | 122 |
|
| 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 | + |
119 | 189 | public function testThrowInvalidArgumentExceptionForAssociativeParagraph(): void |
120 | 190 | { |
121 | 191 | $this->expectException(InvalidArgumentException::class); |
|
0 commit comments