Skip to content

Commit

Permalink
Add failing test for custom array prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Nov 25, 2024
1 parent ed9a305 commit 5ef7c1b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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 5ef7c1b

Please sign in to comment.