How can I dump the SQL query of something like
$searchResult = $this->propertyGroupOptionRepository->search($criteria, $context);
I know there is a the debug bar, but this is inside of a PHPUnit test and the debug bar is not available there?
How can I dump the SQL query of something like
$searchResult = $this->propertyGroupOptionRepository->search($criteria, $context);
I know there is a the debug bar, but this is inside of a PHPUnit test and the debug bar is not available there?
Update 2: This is also included in FroshDevelopmentHelper
Something like this before the test basically works:
Kernel::getConnection()->getConfiguration()->setSQLLogger(new EchoSQLLogger());
This will print out the SQL queries to the console.
Drawbacks:
Improved version - using the Core code to format the query:
Warning, not perfect, see comments
class EchoRunableSQLLogger implements \Doctrine\DBAL\Logging\SQLLogger
{
public function startQuery($sql, ?array $params = null, ?array $types = null)
{
$doctrineExtension = new \Shopware\Core\Profiling\Twig\DoctrineExtension();
echo $doctrineExtension->replaceQueryParameters(
$sql,
array_merge($params ?? array(), $types ?? array())
) . ';' . PHP_EOL;
}
public function stopQuery()
{
}
}
\Shopware\Core\Kernel::getConnection()->getConfiguration()->setSQLLogger(new EchoRunableSQLLogger());
array_merge($params ?? array(), $types ?? array())
overwrites the params with the type, so I thought my query has the wrong parameters - but no, the debug output was wrong 🙈 No offense - it was fun to debug. I only thinks this is a fun story about "be careful with assumptions" sometimes the eye is broken, not the reality
Jul 11, 2022 at 14:01
I have the problem, that @Alex doesn't work for me, because on dev, Shopware is interfering at two positions:
src/Kernel.php:49
vendor/shopware/core/HttpKernel.php:179
So I just hacked the core:
\Shopware\Core\Profiling\Doctrine\DebugStack::startQuery
And added the few lines directly into DebugStack:
public function startQuery($sql, ?array $params = null, ?array $types = null): void
{
$this->ensureMasterSlaveCompatibility($sql);
$doctrineExtension = new \Shopware\Core\Profiling\Twig\DoctrineExtension();
echo $doctrineExtension->replaceQueryParameters(
$sql,
array_merge($params ?? array())
) . ';' . PHP_EOL;
parent::startQuery($sql, $params, $types);
}