Skip to content

Commit 16949d5

Browse files
authored
[1.x] Rename highlighting prop (#362)
* Rename highlighting prop * Make test output verbose * Formatting * Require latest due to casing changes
1 parent 24c71bf commit 16949d5

File tree

5 files changed

+61
-7
lines changed

5 files changed

+61
-7
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
composer update --prefer-dist --no-interaction --no-progress --${{ matrix.stability }}
6161
6262
- name: Execute tests
63-
run: vendor/bin/pest
63+
run: vendor/bin/pest -vvv
6464
env:
6565
DB_CONNECTION: mysql
6666
DB_DATABASE: pulse
@@ -118,7 +118,7 @@ jobs:
118118
composer update --prefer-dist --no-interaction --no-progress --${{ matrix.stability }}
119119
120120
- name: Execute tests
121-
run: vendor/bin/pest
121+
run: vendor/bin/pest -vvv
122122
env:
123123
DB_CONNECTION: mariadb
124124
DB_DATABASE: pulse
@@ -175,7 +175,7 @@ jobs:
175175
composer update --prefer-dist --no-interaction --no-progress
176176
177177
- name: Execute tests
178-
run: vendor/bin/pest
178+
run: vendor/bin/pest -vvv
179179
env:
180180
DB_CONNECTION: pgsql
181181
DB_DATABASE: pulse
@@ -222,6 +222,6 @@ jobs:
222222
composer update --prefer-dist --no-interaction --no-progress --${{ matrix.stability }}
223223
224224
- name: Execute tests
225-
run: vendor/bin/pest
225+
run: vendor/bin/pest -vvv
226226
env:
227227
DB_CONNECTION: sqlite

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"require": {
1818
"php": "^8.1",
19-
"doctrine/sql-formatter": "^1.1",
19+
"doctrine/sql-formatter": "^1.2",
2020
"guzzlehttp/promises": "^1.0|^2.0",
2121
"illuminate/auth": "^10.48.4|^11.0.8",
2222
"illuminate/cache": "^10.48.4|^11.0.8",

resources/views/livewire/slow-queries.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use \Doctrine\SqlFormatter\HtmlHighlighter;
33
use \Doctrine\SqlFormatter\SqlFormatter;
44
5-
if (! $this->disableHighlighting) {
5+
if ($this->wantsHighlighting()) {
66
$sqlFormatter = new SqlFormatter(new HtmlHighlighter([
77
HtmlHighlighter::HIGHLIGHT_RESERVED => 'class="font-semibold"',
88
HtmlHighlighter::HIGHLIGHT_QUOTE => 'class="text-purple-200"',
@@ -62,7 +62,7 @@
6262
<x-pulse::td class="!p-0 truncate max-w-[1px]">
6363
<div class="relative">
6464
<div class="bg-gray-700 dark:bg-gray-800 py-4 rounded-md text-gray-100 block text-xs whitespace-nowrap overflow-x-auto [scrollbar-color:theme(colors.gray.500)_transparent] [scrollbar-width:thin]">
65-
<code class="px-3">{!! $this->disableHighlighting ? $query->sql : $sqlFormatter->highlight($query->sql) !!}</code>
65+
<code class="px-3">{!! $this->wantsHighlighting() ? $sqlFormatter->highlight($query->sql) : $query->sql !!}</code>
6666
@if ($query->location)
6767
<p class="px-3 mt-3 text-xs leading-none text-gray-400 dark:text-gray-500">
6868
{{ $query->location }}

src/Livewire/SlowQueries.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ class SlowQueries extends Card
2626
/**
2727
* Indicates that SQL highlighting should be disabled.
2828
*/
29+
public bool $withoutHighlighting = false;
30+
31+
/**
32+
* Indicates that SQL highlighting should be disabled.
33+
*
34+
* @deprecated
35+
*/
2936
public bool $disableHighlighting = false;
3037

3138
/**
@@ -61,4 +68,12 @@ public function render(): Renderable
6168
'slowQueries' => $slowQueries,
6269
]);
6370
}
71+
72+
/**
73+
* Determine if the view should highlight SQL queries.
74+
*/
75+
protected function wantsHighlighting(): bool
76+
{
77+
return ! ($this->withoutHighlighting || $this->disableHighlighting);
78+
}
6479
}

tests/Feature/Livewire/SlowQueriesTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,42 @@
4040
(object) ['sql' => 'select * from `users` where `id` = ?', 'location' => 'app/Bar.php:456', 'count' => 2, 'slowest' => 1234],
4141
]));
4242
});
43+
44+
it('highlights SQL queries', function () {
45+
Carbon::setTestNow('2000-01-01 13:00:00');
46+
$query = json_encode(['select * from `users`', 'app/Foo.php:123']);
47+
48+
Pulse::record('slow_query', $query, 1000)->max()->count();
49+
Pulse::ingest();
50+
51+
Livewire::test(SlowQueries::class, ['lazy' => false])
52+
->assertSeeHtml(<<<'HTML'
53+
<code class="px-3"><span class="font-semibold">SELECT</span> <span class="text-cyan-200">*</span> <span class="font-semibold">FROM</span> <span class="text-purple-200">`users`</span></code>
54+
HTML);
55+
});
56+
57+
it('can opt out of syntax highlighting', function () {
58+
Carbon::setTestNow('2000-01-01 13:00:00');
59+
$query = json_encode(['select * from `users`', 'app/Foo.php:123']);
60+
61+
Pulse::record('slow_query', $query, 1000)->max()->count();
62+
Pulse::ingest();
63+
64+
Livewire::test(SlowQueries::class, ['lazy' => false, 'withoutHighlighting' => true])
65+
->assertSeeHtml(<<<'HTML'
66+
<code class="px-3">select * from `users`</code>
67+
HTML);
68+
});
69+
70+
it('can opt out of syntax highlighting with deprecated property', function () {
71+
Carbon::setTestNow('2000-01-01 13:00:00');
72+
$query = json_encode(['select * from `users`', 'app/Foo.php:123']);
73+
74+
Pulse::record('slow_query', $query, 1000)->max()->count();
75+
Pulse::ingest();
76+
77+
Livewire::test(SlowQueries::class, ['lazy' => false, 'disableHighlighting' => true])
78+
->assertSeeHtml(<<<'HTML'
79+
<code class="px-3">select * from `users`</code>
80+
HTML);
81+
});

0 commit comments

Comments
 (0)