BacktraceDebugDataHolder example

use Symfony\Bridge\Doctrine\Middleware\Debug\Query;

/** * @internal * * @covers \Shopware\Core\Profiling\Doctrine\BacktraceDebugDataHolder */
class BacktraceDebugDataHolderTest extends TestCase
{
    public function testAddAndRetrieveData(): void
    {
        $sut = new BacktraceDebugDataHolder([]);
        $sut->addQuery('myconn', new Query('SELECT * FROM product'));

        $data = $sut->getData();
        static::assertCount(1, $data['myconn'] ?? []);
        $current = $data['myconn'][0];

        static::assertSame(0, strpos($current['sql'], 'SELECT * FROM product'));
        static::assertSame([]$current['params']);
        static::assertSame([]$current['types']);
    }

    


        static::assertTrue($collectedQueries['default'][0]['explainable']);
        static::assertTrue($collectedQueries['default'][0]['runnable']);
    }

    /** * @param array<array{sql: string, params: array<mixed>|null, types: array<mixed>|null, executionMS?: int}> $queries */
    private function createCollector(array $queries): ConnectionProfiler
    {
        $debugDataHolder = new BacktraceDebugDataHolder(['default']);
        $config = new Configuration();
        $config->setMiddlewares([new ProfilingMiddleware($debugDataHolder)]);

        $connection = $this->getMockBuilder(Connection::class)
            ->disableOriginalConstructor()
            ->getMock();
        $connection->expects(static::any())
            ->method('getDatabasePlatform')
            ->willReturn(new MySqlPlatform());
        $connection->expects(static::any())
            ->method('getConfiguration')
            
/** * @internal * * @covers \Shopware\Core\Profiling\Doctrine\ProfilingMiddleware */
class ProfilingMiddlewareTest extends TestCase
{
    public function testData(): void
    {
        $configuration = new Configuration();
        $debugDataHolder = new BacktraceDebugDataHolder(['default']);
        $middleware = new ProfilingMiddleware($debugDataHolder);
        $configuration->setMiddlewares([$middleware]);

        $conn = DriverManager::getConnection([
            'driver' => 'pdo_sqlite',
            'memory' => true,
        ]$configuration);

        $conn->executeQuery(
            <<<EOT CREATE TABLE products ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, price REAL NOT NULL, stock INTEGER NOT NULL );
use Doctrine\DBAL\Driver\Middleware;
use Shopware\Core\Framework\Log\Package;
use Symfony\Bridge\Doctrine\Middleware\Debug\Driver as DebugDriver;
use Symfony\Component\Stopwatch\Stopwatch;

#[Package('core')] class ProfilingMiddleware implements Middleware
{
    private const CONNECTION = 'default';

    public function __construct(
        public BacktraceDebugDataHolder $debugDataHolder = new BacktraceDebugDataHolder([self::CONNECTION]),
    ) {
    }

    public function wrap(Driver $driver): DebugDriver
    {
        return new DebugDriver(
            $driver,
            $this->debugDataHolder,
            new Stopwatch(),
            self::CONNECTION
        );
    }
'some-token',
            'app.connection_collector',
            'default',
            5
        );

        static::assertEquals('This query does not exist.', $response->getContent());
    }

    public function testErrorIsReturnedIfQueryIsNotExplainable(): void
    {
        $debugDataHolder = new BacktraceDebugDataHolder(['default']);
        $config = (new Configuration())
            ->setMiddlewares([new ProfilingMiddleware($debugDataHolder)]);

        $twig = $this->createMock(Environment::class);
        $profiler = $this->createMock(Profiler::class);
        $connection = $this->createMock(Connection::class);

        $connection
            ->method('getConfiguration')
            ->willReturn($config);

        
Home | Imprint | This part of the site doesn't use cookies.