Query example

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

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

        $profile = new Profile('some-token');
        $profiler->expects(static::once())
            ->method('loadProfile')
            ->with('some-token')
            ->willReturn($profile);

        $query = new Query('select * from table where key = ?');
        $query->setValue(
            1,
            new class() {
                public function __toString(): string
                {
                    return 'value';
                }
            },
            ParameterType::STRING
        );
        $debugDataHolder->addQuery('default', $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']);
    }

    public function testReset(): void
    {
->disableOriginalConstructor()
            ->getMock();
        $connection->expects(static::any())
            ->method('getDatabasePlatform')
            ->willReturn(new MySqlPlatform());
        $connection->expects(static::any())
            ->method('getConfiguration')
            ->willReturn($config);

        $collector = new ConnectionProfiler($connection);
        foreach ($queries as $queryData) {
            $query = new Query($queryData['sql'] ?? '');
            foreach (($queryData['params'] ?? []) as $key => $value) {
                if (\is_int($key)) {
                    ++$key;
                }

                $query->setValue($key$value$queryData['types'][$key] ?? ParameterType::STRING);
            }

            $query->start();

            $debugDataHolder->addQuery('default', $query);

            

class CategoryNonExistentExceptionHandlerTest extends TestCase
{
    public function testExceptionHandler(): void
    {
        $handler = new CategoryNonExistentExceptionHandler();

        static::assertEquals(ExceptionHandlerInterface::PRIORITY_DEFAULT, $handler->getPriority());

        $afterException = new ForeignKeyConstraintViolationException(
            new PDOException('SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`shopware`.`category`, CONSTRAINT `fk.category.after_category_id` FOREIGN KEY (`after_category_id`, `after_category_version_id`) REFERENCES `category` (`id`, `version_id`) ON DELETE SET NULL O)'),
            new Query('SOME QUERY', [][])
        );

        $matched = $handler->matchException($afterException);

        static::assertInstanceOf(CategoryException::class$matched);
        static::assertEquals('Category to insert after not found.', $matched->getMessage());

        static::assertNull($handler->matchException(new \Exception('Some other exception')));
    }
}
Home | Imprint | This part of the site doesn't use cookies.