Skip to content

Commit 6a09266

Browse files
authored
Add fix + failing test for custom array prototype (#1705)
* Add failing test for custom array prototype * Use forEach * Use array.forEach
1 parent ed9a305 commit 6a09266

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

Diff for: src/Resources/queries/widget.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,7 @@
343343
const $li = $('<li />').addClass(csscls('table-list-item'));
344344
const $muted = $('<span />').addClass(css('text-muted'));
345345

346-
for (const i in values) {
347-
const value = values[i];
346+
values.forEach((value, i) => {
348347
if (showLineNumbers) {
349348
$ul.append($li.clone().append([$muted.clone().text(`${i}:`), '&nbsp;', $('<span/>').text(value)]));
350349
} else {
@@ -354,7 +353,7 @@
354353
$ul.append($li.clone().text(value));
355354
}
356355
}
357-
}
356+
});
358357

359358
return this.renderDetail(caption, icon, $ul);
360359
},

Diff for: tests/DebugbarBrowserTest.php

+42-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ protected function addWebRoutes(Router $router)
6868
}
6969
]);
7070

71+
$router->get('web/custom-prototype', [
72+
'uses' => function () {
73+
74+
/** @var Connection $connection */
75+
$connection = $this->app['db']->connectUsing(
76+
'runtime-connection',
77+
[
78+
'driver' => 'sqlite',
79+
'database' => ':memory:',
80+
],
81+
);
82+
event(new QueryExecuted('SELECT * FROM users WHERE username = ?', ['debuguser'], 0, $connection));
83+
return view('custom-prototype');
84+
}
85+
]);
86+
7187
$router->get('web/query/{num?}', [
7288
'uses' => function ($num = 1) {
7389
debugbar()->boot();
@@ -85,7 +101,6 @@ protected function addWebRoutes(Router $router)
85101
$executedQuery = new QueryExecuted('SELECT * FROM users WHERE username = ?', ['debuguser' . $i], 0, $connection);
86102
event($executedQuery);
87103
}
88-
89104
return 'PONG';
90105
}
91106
]);
@@ -201,6 +216,32 @@ public function testDatabaseCollectsQueries()
201216
});
202217
}
203218

219+
public function testDatabaseCollectsQueriesWithCustomPrototype()
220+
{
221+
if (version_compare($this->app->version(), '10', '<')) {
222+
$this->markTestSkipped('This test is not compatible with Laravel 9.x and below');
223+
}
224+
225+
$this->browse(function (Browser $browser) {
226+
$browser->visit('web/custom-prototype')
227+
->waitFor('.phpdebugbar')
228+
->click('.phpdebugbar-tab-history')
229+
->waitForTextIn('.phpdebugbar-tab[data-collector="queries"] .phpdebugbar-badge', 1)
230+
->click('.phpdebugbar-tab[data-collector="queries"]')
231+
->screenshotElement('.phpdebugbar', 'queries-tab')
232+
->waitForText('executed')
233+
->assertSee('1 statement was executed')
234+
->with('.phpdebugbar-widgets-sqlqueries', function ($queriesPane) {
235+
$queriesPane->assertSee('SELECT * FROM users')
236+
->click('.phpdebugbar-widgets-expandable:nth-child(2)')
237+
->assertSee('Bindings')
238+
->assertSee('debuguser')
239+
->assertSee('Backtrace')
240+
->assertSee('LaravelDebugbar.php:');
241+
})
242+
->screenshotElement('.phpdebugbar', 'queries-expanded');
243+
});
244+
}
204245

205246
public function testDatabaseCollectsQueriesWithSoftLimit()
206247
{

Diff for: tests/resources/views/custom-prototype.blade.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<html>
2+
<body>
3+
4+
<script>
5+
Array.prototype.customRemove = function(item) {
6+
const i = this.indexOf(item)
7+
if (i > -1) {
8+
this.splice(i, 1)
9+
}
10+
return this
11+
}
12+
</script>
13+
</body>

0 commit comments

Comments
 (0)