packages/sql-catalog/tests/Unit/Reporter/Html/PaletteTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Reporter\Html;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\DataProvider;
9use PHPUnit\Framework\TestCase;
10use SqlCatalog\Core\Catalog\Resolution;
11use SqlCatalog\Core\Catalog\Severity;
12use SqlCatalog\Core\Sql\StatementKind;
13use SqlCatalog\Reporter\Html\Palette;
14
15#[CoversClass(Palette::class)]
16final class PaletteTest extends TestCase
17{
18 /**
19 * @return list<array{StatementKind, string}>
20 */
21 public static function providerKind(): array
22 {
23 return [
24 [StatementKind::Select, 'tone-blue'],
25 [StatementKind::Insert, 'tone-teal'],
26 [StatementKind::Replace, 'tone-teal'],
27 [StatementKind::Merge, 'tone-teal'],
28 [StatementKind::Update, 'tone-violet'],
29 [StatementKind::Delete, 'tone-pink'],
30 [StatementKind::Create, 'tone-indigo'],
31 [StatementKind::Alter, 'tone-indigo'],
32 [StatementKind::Drop, 'tone-indigo'],
33 [StatementKind::Truncate, 'tone-indigo'],
34 [StatementKind::Call, 'tone-slate'],
35 [StatementKind::Show, 'tone-slate'],
36 [StatementKind::Explain, 'tone-slate'],
37 [StatementKind::Transaction, 'tone-slate'],
38 [StatementKind::Other, 'tone-slate'],
39 [StatementKind::Unknown, 'tone-slate'],
40 ];
41 }
42
43 #[DataProvider('providerKind')]
44 public function testKindWritesEachKindInItsOwnHue(StatementKind $kind, string $expected): void
45 {
46 self::assertSame($expected, (new Palette())->kind($kind->value));
47 }
48
49 public function testKindGroupFallsBackForAKindItDoesNotKnow(): void
50 {
51 self::assertSame('other', (new Palette())->kindGroup('lateral-join'));
52 self::assertSame('schema', (new Palette())->kindGroup('alter'));
53 }
54
55 /**
56 * @return list<array{Resolution, string}>
57 */
58 public static function providerResolution(): array
59 {
60 return [
61 [Resolution::Resolved, 'tone-ok'],
62 [Resolution::ExternalInput, 'tone-danger'],
63 [Resolution::IncompleteModel, 'chip-ghost'],
64 [Resolution::Incomplete, 'chip-ghost'],
65 [Resolution::NotAnalyzed, 'tone-neutral'],
66 ];
67 }
68
69 #[DataProvider('providerResolution')]
70 public function testResolutionWritesTheStateOfTheReading(Resolution $resolution, string $expected): void
71 {
72 self::assertSame($expected, (new Palette())->resolution($resolution));
73 }
74
75 /**
76 * @return list<array{Severity, string}>
77 */
78 public static function providerSeverity(): array
79 {
80 return [
81 [Severity::High, 'tone-danger'],
82 [Severity::Medium, 'tone-warn'],
83 [Severity::Low, 'tone-neutral'],
84 [Severity::Info, 'tone-neutral'],
85 ];
86 }
87
88 #[DataProvider('providerSeverity')]
89 public function testSeverityWritesHowMuchAttentionIsWanted(Severity $severity, string $expected): void
90 {
91 self::assertSame($expected, (new Palette())->severity($severity));
92 }
93
94 public function testBarKeepsAToneAndHatchesAnOpenSearch(): void
95 {
96 self::assertSame('tone-ok', (new Palette())->bar('tone-ok'));
97 self::assertSame('is-open', (new Palette())->bar(Palette::OPEN));
98 }
99}
100