Repository navigation
Expand file tree
/
Copy pathPanelDefinitionTest.php
More file actions
81 lines (72 loc) · 2.39 KB
/
Copy pathPanelDefinitionTest.php
File metadata and controls
81 lines (72 loc) · 2.39 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
<?php
declare(strict_types=1);
namespace PHPForge\Debug\Tests;
use InvalidArgumentException;
use PHPForge\Debug\{Panel, PanelView};
use PHPUnit\Framework\TestCase;
/**
* Unit tests for extension-owned panel metadata.
*/
final class PanelDefinitionTest extends TestCase
{
public function testExtensionDefinesItsMetadataAndContent(): void
{
$panel = new class extends Panel {
protected const string ID = 'cache';
protected const string TITLE = 'Application cache';
protected const string ICON = 'database';
public function present(array $data): PanelView
{
return PanelView::create()
->heading('Cache entries')
->table(['Key', 'Hits'], [['home', 5]]);
}
};
self::assertSame(
'cache',
$panel->id(),
'The extension must own its stable ID.',
);
self::assertSame(
'Application cache',
$panel->name(),
'The extension must own its navigation title.',
);
self::assertSame(
'database',
$panel->icon(),
'The extension must choose its icon.',
);
self::assertEquals(
PanelView::create()
->heading('Cache entries')
->table(['Key', 'Hits'], [['home', 5]]),
$panel->present([]),
'The extension must own section titles, table headers, and values.',
);
}
public function testRejectsMissingMetadataExplicitly(): void
{
$panel = new class extends Panel {
public function present(array $data): PanelView
{
return PanelView::create();
}
};
$accessors = ['ICON' => $panel->icon(...), 'ID' => $panel->id(...), 'TITLE' => $panel->name(...)];
foreach ($accessors as $field => $accessor) {
try {
$accessor();
self::fail(
'Missing definition metadata must be rejected.',
);
} catch (InvalidArgumentException $exception) {
self::assertSame(
"A panel definition must declare {$field}.",
$exception->getMessage(),
'The error must identify the missing metadata.',
);
}
}
}
}