Skip to content

Commit

Permalink
Add queries tab tests (#1687)
Browse files Browse the repository at this point in the history
  • Loading branch information
mccahan authored Oct 10, 2024
1 parent dab9380 commit b705c56
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/DebugbarBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Routing\Router;
use Laravel\Dusk\Browser;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Database\Connection;

class DebugbarBrowserTest extends BrowserTestCase
{
Expand Down Expand Up @@ -65,6 +67,26 @@ protected function addWebRoutes(Router $router)
return view('ajax');
}
]);

$router->get('web/query', [
'uses' => function () {
debugbar()->boot();

/** @var Connection $connection */
$connection = $this->app['db']->connectUsing(
'runtime-connection',
[
'driver' => 'sqlite',
'database' => ':memory:',
],
);

$executedQuery = new QueryExecuted('SELECT * FROM users WHERE username = ?', ['debuguser'], 0, $connection);
event($executedQuery);

return 'PONG';
}
]);
}

/**
Expand Down Expand Up @@ -138,4 +160,42 @@ public function testItCapturesAjaxRequests()
->assertSee('GET api/ping');
});
}

public function testDatabaseTabIsClickable()
{
$this->browse(function (Browser $browser) {
$browser->visit('web/plain')
->waitFor('.phpdebugbar')
->assertDontSee('0 statements were executed')
->click('.phpdebugbar-tab[data-collector="queries"]')
->assertSee('0 statements were executed');
});
}

public function testDatabaseCollectsQueries()
{
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/query')
->waitFor('.phpdebugbar')
->click('.phpdebugbar-tab-history')
->assertSeeIn('.phpdebugbar-tab[data-collector="queries"] .phpdebugbar-badge', 2)
->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');
});
}
}

0 comments on commit b705c56

Please sign in to comment.