jeytekdev / explain-lint-doctrine
Doctrine DBAL bridge for jeytekdev/explain-lint — captures queries via a Driver\Middleware and re-runs EXPLAIN on the same connection.
Package info
github.com/jeytekdev/explain-lint-doctrine
pkg:composer/jeytekdev/explain-lint-doctrine
Requires
- php: ^8.1
- doctrine/dbal: ^3.2 || ^4.0
- jeytekdev/explain-lint: ^1.0
Requires (Dev)
- phpunit/phpunit: ^10.5 || ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Doctrine DBAL bridge for jeytekdev/explain-lint — re-runs EXPLAIN against every query your test suite executes, and fails the build on full table scans, lost indexes, filesort and temporary tables.
Implemented as a Doctrine\DBAL\Driver\Middleware, not the old SQLLogger — SQLLogger is deprecated and has been removed entirely in DBAL 4.x. Compatible with doctrine/dbal: ^3.2 || ^4.0.
Install (2 minutes)
composer require --dev jeytekdev/explain-lint-doctrine
Register the middleware wherever you build your Doctrine\DBAL\Configuration (in a plain DBAL app, or via Symfony's doctrine.yaml):
use Doctrine\DBAL\Configuration; use Doctrine\DBAL\DriverManager; use ExplainLint\Doctrine\ExplainLintMiddleware; $configuration = new Configuration(); $configuration->setMiddlewares([new ExplainLintMiddleware('default')]); $connection = DriverManager::getConnection($connectionParams, $configuration);
Symfony (config/packages/doctrine.yaml):
doctrine: dbal: connections: default: middlewares: - ExplainLint\Doctrine\ExplainLintMiddleware
Then wire up the PHPUnit extension (see core README):
vendor/bin/explain-lint explain-lint:install
Known limitation: PDO-only drivers
explain-lint needs the real \PDO handle behind a connection to re-run EXPLAIN on the exact same session. This bridge supports the pdo_mysql and pdo_pgsql drivers only — native drivers (mysqli, pgsql, sqlite3) have no \PDO to hand back, so queries on those simply aren't captured (no error, nothing to analyze).
License
MIT