ProfilingMiddleware example

if (InstalledVersions::isInstalled('shopware/platform')) {
            $shopwareVersion = InstalledVersions::getVersion('shopware/platform')
                . '@' . InstalledVersions::getReference('shopware/platform');
        } else {
            $shopwareVersion = InstalledVersions::getVersion('shopware/core')
                . '@' . InstalledVersions::getReference('shopware/core');
        }

        $middlewares = [];
        if (\PHP_SAPI !== 'cli' && $this->environment !== 'prod' && InstalledVersions::isInstalled('symfony/doctrine-bridge')) {
            $middlewares = [new ProfilingMiddleware()];
        }

        $connection = self::getConnection($middlewares);

        $pluginLoader = $this->createPluginLoader($connection);

        $storage = new MySQLKeyValueStorage($connection);
        $cacheId = (new CacheIdLoader($storage))->load();

        return $this->kernel = new static::$kernelClass(
            $this->environment,
            
/** * @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 );
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')
            ->willReturn($config);

        
// noop             }
        });

        $response = $controller->explainAction('some-token', 'some-panel', 'default', 5);
        static::assertEquals('This collector does not exist.', $response->getContent());
    }

    public function testErrorIsReturnedIfQueryDoesNotExist(): void
    {
        $config = (new Configuration())
            ->setMiddlewares([new ProfilingMiddleware()]);

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

        $connection->expects(static::any())
            ->method('getConfiguration')
            ->willReturn($config);

        $controller = new ProfilerController($twig$profiler$connection);

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