getSql example

/** * @author Laurent VOULLEMIER <laurent.voullemier@gmail.com> */
class DebugDataHolder
{
    private array $data = [];

    public function addQuery(string $connectionName, Query $query): void
    {
        $this->data[$connectionName][] = [
            'sql' => $query->getSql(),
            'params' => $query->getParams(),
            'types' => $query->getTypes(),
            'executionMS' => $query->getDuration(...),  // stop() may not be called at this point         ];
    }

    public function getData(): array
    {
        foreach ($this->data as $connectionName => $dataForConn) {
            foreach ($dataForConn as $idx => $data) {
                if (\is_callable($data['executionMS'])) {
                    
->method('getCreateTableSQL')
            ->with($table)
            ->willReturn('CREATE TABLE pizza (id integer NOT NULL)');

        $subscriber = new MessengerTransportDoctrineSchemaListener([$otherTransport$doctrineTransport]);

        $subscriber->onSchemaCreateTable($event);
        $this->assertTrue($event->isDefaultPrevented());
        $this->assertSame([
            'CREATE TABLE pizza (id integer NOT NULL)',
            'ALTER TABLE pizza ADD COLUMN extra_cheese boolean',
        ]$event->getSql());
    }

    public function testOnSchemaCreateTableNoExtraSql()
    {
        $platform = $this->createMock(AbstractPlatform::class);
        $table = new Table('queue_table');
        $event = new SchemaCreateTableEventArgs($table[][]$platform);

        $doctrineTransport = $this->createMock(DoctrineTransport::class);
        $doctrineTransport->expects($this->once())
            ->method('getExtraSetupSqlForTable')
            

    public function apply(AbstractMigration $migration$modus = AbstractMigration::MODUS_INSTALL)
    {
        $this->insertMigration($migration);

        try {
            $migration->up($modus);

            foreach ($migration->getSql() as $sql) {
                $this->connection->exec($sql);
            }
        } catch (Exception $e) {
            $this->markMigrationAsFailed($migration$e);

            throw new Exception(sprintf('Could not apply migration (%s). Error: %s ', \get_class($migration)$e->getMessage()));
        }

        $this->markMigrationAsFinished($migration);
    }

    
$stmt->execute([
            ':plugin_name' => $this->plugin->getName(),
            ':version' => $migration->getVersion(),
        ]);
    }

    private function downMigration(AbstractMigration $migration, bool $keepUserData): void
    {
        try {
            $migration->down($keepUserData);

            foreach ($migration->getSql() as $sql) {
                $this->connection->exec($sql);
            }
        } catch (Exception $e) {
            $this->markMigrationAsFailed($migration$e);

            throw new RuntimeException(sprintf('Could not revert migration (%s). Error: %s ', \get_class($migration)$e->getMessage()));
        }

        $this->removeMigration($migration);
    }
}
Home | Imprint | This part of the site doesn't use cookies.