From 6a09266c89802946fb15d5f2f74906d48734a7b5 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 25 Nov 2024 13:49:44 +0100 Subject: [PATCH] Add fix + failing test for custom array prototype (#1705) * Add failing test for custom array prototype * Use forEach * Use array.forEach --- src/Resources/queries/widget.js | 5 +-- tests/DebugbarBrowserTest.php | 43 ++++++++++++++++++- .../views/custom-prototype.blade.php | 13 ++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 tests/resources/views/custom-prototype.blade.php diff --git a/src/Resources/queries/widget.js b/src/Resources/queries/widget.js index 5e5b9b40..242565ac 100644 --- a/src/Resources/queries/widget.js +++ b/src/Resources/queries/widget.js @@ -343,8 +343,7 @@ const $li = $('
  • ').addClass(csscls('table-list-item')); const $muted = $('').addClass(css('text-muted')); - for (const i in values) { - const value = values[i]; + values.forEach((value, i) => { if (showLineNumbers) { $ul.append($li.clone().append([$muted.clone().text(`${i}:`), ' ', $('').text(value)])); } else { @@ -354,7 +353,7 @@ $ul.append($li.clone().text(value)); } } - } + }); return this.renderDetail(caption, icon, $ul); }, diff --git a/tests/DebugbarBrowserTest.php b/tests/DebugbarBrowserTest.php index 4e6f8a49..1542ecc5 100644 --- a/tests/DebugbarBrowserTest.php +++ b/tests/DebugbarBrowserTest.php @@ -68,6 +68,22 @@ protected function addWebRoutes(Router $router) } ]); + $router->get('web/custom-prototype', [ + 'uses' => function () { + + /** @var Connection $connection */ + $connection = $this->app['db']->connectUsing( + 'runtime-connection', + [ + 'driver' => 'sqlite', + 'database' => ':memory:', + ], + ); + event(new QueryExecuted('SELECT * FROM users WHERE username = ?', ['debuguser'], 0, $connection)); + return view('custom-prototype'); + } + ]); + $router->get('web/query/{num?}', [ 'uses' => function ($num = 1) { debugbar()->boot(); @@ -85,7 +101,6 @@ protected function addWebRoutes(Router $router) $executedQuery = new QueryExecuted('SELECT * FROM users WHERE username = ?', ['debuguser' . $i], 0, $connection); event($executedQuery); } - return 'PONG'; } ]); @@ -201,6 +216,32 @@ public function testDatabaseCollectsQueries() }); } + public function testDatabaseCollectsQueriesWithCustomPrototype() + { + if (version_compare($this->app->version(), '10', '<')) { + $this->markTestSkipped('This test is not compatible with Laravel 9.x and below'); + } + + $this->browse(function (Browser $browser) { + $browser->visit('web/custom-prototype') + ->waitFor('.phpdebugbar') + ->click('.phpdebugbar-tab-history') + ->waitForTextIn('.phpdebugbar-tab[data-collector="queries"] .phpdebugbar-badge', 1) + ->click('.phpdebugbar-tab[data-collector="queries"]') + ->screenshotElement('.phpdebugbar', 'queries-tab') + ->waitForText('executed') + ->assertSee('1 statement was executed') + ->with('.phpdebugbar-widgets-sqlqueries', function ($queriesPane) { + $queriesPane->assertSee('SELECT * FROM users') + ->click('.phpdebugbar-widgets-expandable:nth-child(2)') + ->assertSee('Bindings') + ->assertSee('debuguser') + ->assertSee('Backtrace') + ->assertSee('LaravelDebugbar.php:'); + }) + ->screenshotElement('.phpdebugbar', 'queries-expanded'); + }); + } public function testDatabaseCollectsQueriesWithSoftLimit() { diff --git a/tests/resources/views/custom-prototype.blade.php b/tests/resources/views/custom-prototype.blade.php new file mode 100644 index 00000000..7d976c40 --- /dev/null +++ b/tests/resources/views/custom-prototype.blade.php @@ -0,0 +1,13 @@ + + + + +