Skip to content

Commit

Permalink
Add fix + failing test for custom array prototype (#1705)
Browse files Browse the repository at this point in the history
* Add failing test for custom array prototype

* Use forEach

* Use array.forEach
  • Loading branch information
barryvdh authored Nov 25, 2024
1 parent ed9a305 commit 6a09266
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/Resources/queries/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@
const $li = $('<li />').addClass(csscls('table-list-item'));
const $muted = $('<span />').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}:`), '&nbsp;', $('<span/>').text(value)]));
} else {
Expand All @@ -354,7 +353,7 @@
$ul.append($li.clone().text(value));
}
}
}
});

return this.renderDetail(caption, icon, $ul);
},
Expand Down
43 changes: 42 additions & 1 deletion tests/DebugbarBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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';
}
]);
Expand Down Expand Up @@ -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()
{
Expand Down
13 changes: 13 additions & 0 deletions tests/resources/views/custom-prototype.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html>
<body>

<script>
Array.prototype.customRemove = function(item) {
const i = this.indexOf(item)
if (i > -1) {
this.splice(i, 1)
}
return this
}
</script>
</body>

0 comments on commit 6a09266

Please sign in to comment.