beginTransaction example

EOF;
        $this->connection->rollBack();
        $this->connection->executeStatement($table);
        $this->connection->beginTransaction();
    }

    protected function tearDown(): void
    {
        $this->connection->rollBack();
        $this->connection->executeStatement('DROP TABLE IF EXISTS `_test_lock`');
        $this->connection->executeStatement('DROP TABLE IF EXISTS `_test_lock_translation`');
        $this->connection->beginTransaction();

        parent::tearDown();
    }

    


        $this->connection->beginTransaction();
    }

    protected function tearDown(): void
    {
        $this->connection->rollBack();

        $this->connection->executeStatement('DROP TABLE `extended_product`');
        $this->connection->beginTransaction();

        $this->removeExtension(ProductExtension::class);

        

        );

        $this->connection->executeStatement(
            'ALTER TABLE `set_null_on_delete_parent` ADD FOREIGN KEY (`set_null_on_delete_many_to_one_id`) REFERENCES `set_null_on_delete_many_to_one` (`id`) ON DELETE SET NULL;'
        );

        $this->connection->beginTransaction();
    }

    protected function tearDown(): void
    {
        $this->connection->rollBack();

        $this->connection->executeStatement(
            'DROP TABLE IF EXISTS set_null_on_delete_child; DROP TABLE IF EXISTS set_null_on_delete_parent; DROP TABLE IF EXISTS set_null_on_delete_many_to_one;'
        );

        
'deviceType' => $this->deviceType,
            'is_proportional_calculation' => isset($this->sBasketData[CheckoutKey::SHIPPING_COSTS_TAX_PROPORTIONAL]) ? 1 : 0,
        ];

        $orderParams = $this->eventManager->filter(
            'Shopware_Modules_Order_SaveOrder_FilterParams',
            $orderParams,
            ['subject' => $this]
        );

        try {
            $this->db->beginTransaction();
            $affectedRows = $this->db->insert('s_order', $orderParams);
            $orderID = (int) $this->db->lastInsertId();
            $this->db->commit();
        } catch (Exception $e) {
            $this->db->rollBack();
            throw new Enlight_Exception(sprintf('Shopware Order Fatal-Error %s :%s', $_SERVER['HTTP_HOST']$e->getMessage()), 0, $e);
        }

        if (!$affectedRows || !$orderID) {
            throw new Enlight_Exception(sprintf('Shopware Order Fatal-Error %s : No rows affected or no order id created.', $_SERVER['HTTP_HOST']), 0);
        }

        


        $this->connection->executeStatement(' ALTER TABLE `app` ADD CONSTRAINT `fk.app.integration_id` FOREIGN KEY (`integration_id`) REFERENCES `integration` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `fk.app.acl_role_id` FOREIGN KEY (`acl_role_id`) REFERENCES `acl_role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ');

        $migration = new Migration1623391399ChangeConstraintAclRoleAndIntegrationInApp();
        $migration->update($this->connection);

        $this->connection->beginTransaction();
    }

    public function testItChangeConstraintAclRoleAndIntegrationInApp(): void
    {
        $context = Context::createDefaultContext();

        $appId = Uuid::randomHex();
        $aclRoleId = Uuid::randomHex();
        $integrationId = Uuid::randomHex();

        $appRepository = $this->getContainer()->get('app.repository');
        
static::$lastTestCase,
            'The previous test case\'s transaction was not closed properly. This may affect following Tests in an unpredictable manner! Previous Test case: ' . (new \ReflectionClass($this))->getName() . '::' . static::$lastTestCase
        );

        $this->getContainer()->get(Connection::class)
            ->setNestTransactionsWithSavepoints(self::$nextNestTransactionsWithSavepoints);

        $this->getContainer()
            ->get(Connection::class)
            ->beginTransaction();

        static::$lastTestCase = $this->getName();
    }

    /** * @after */
    public function stopTransactionAfter(): void
    {
        $connection = $this->getContainer()
            ->get(Connection::class);

        


        $this->connection->beginTransaction();
    }

    protected function tearDown(): void
    {
        $this->connection->rollBack();
        $this->connection->executeStatement('DROP TABLE `extended_product`');
        $this->connection->beginTransaction();

        $this->removeExtension(ProductExtension::class);

        parent::tearDown();
    }
use KernelTestBehaviour;

    /** * @beforeClass */
    public static function startTransactionBefore(): void
    {
        $connection = KernelLifecycleManager::getKernel()
            ->getContainer()
            ->get(Connection::class);

        $connection->beginTransaction();
    }

    /** * @afterClass */
    public static function stopTransactionAfter(): void
    {
        $connection = KernelLifecycleManager::getKernel()
            ->getContainer()
            ->get(Connection::class);

        
use Symfony\Component\Messenger\Stamp\HandledStamp;

/** * Wraps all handlers in a single doctrine transaction. * * @author Tobias Nyholm <tobias.nyholm@gmail.com> */
class DoctrineTransactionMiddleware extends AbstractDoctrineMiddleware
{
    protected function handleForManager(EntityManagerInterface $entityManager, Envelope $envelope, StackInterface $stack): Envelope
    {
        $entityManager->getConnection()->beginTransaction();
        try {
            $envelope = $stack->next()->handle($envelope$stack);
            $entityManager->flush();
            $entityManager->getConnection()->commit();

            return $envelope;
        } catch (\Throwable $exception) {
            $entityManager->getConnection()->rollBack();

            if ($exception instanceof HandlerFailedException) {
                // Remove all HandledStamp from the envelope so the retry will execute all handlers again.
/** * @internal */
trait MigrationTestTrait
{
    /** * @before */
    public function startTransaction(): void
    {
        KernelLifecycleManager::getConnection()->beginTransaction();
    }

    /** * @after */
    public function rollbackTransaction(): void
    {
        KernelLifecycleManager::getConnection()->rollBack();
    }
}
return parent::_quote($value);
    }

    /** * Begin a transaction. * Opening a zend connection and a dbalconnection results in a fatal error, so we use the doctrine transaction levels * * @return void */
    protected function _beginTransaction()
    {
        $this->dbalConnection->beginTransaction();
    }

    /** * Commit a transaction. * * @return void */
    protected function _commit()
    {
        $this->dbalConnection->commit();
    }

    
public static function tearDownAfterClass(): void
    {
        $_ENV['SHOPWARE_HTTP_CACHE_ENABLED'] = $_SERVER['SHOPWARE_HTTP_CACHE_ENABLED'] = self::$originalHttpCacheValue;
    }

    protected function setUp(): void
    {
        KernelLifecycleManager::bootKernel();

        $this->getContainer()
            ->get(Connection::class)
            ->beginTransaction();
    }

    protected function tearDown(): void
    {
        $connection = $this->getContainer()->get(Connection::class);

        static::assertEquals(
            1,
            $connection->getTransactionNestingLevel(),
            'Too many Nesting Levels. Probably one transaction was not closed properly. This may affect following Tests in an unpredictable manner! Current nesting level: "'


        // Persist a copy of the previous token for authentication         // in verifyToken should the old token still be sent by the browser         // in a request concurrent to the one that did this token update         $tmpSeries = preg_replace('{=+$}', '_', $token->getSeries());
        // if we cannot generate a unique series it is not worth trying further         if ($tmpSeries === $token->getSeries()) {
            return;
        }

        $this->conn->beginTransaction();
        try {
            $this->deleteTokenBySeries($tmpSeries);
            $lastUsed = \DateTime::createFromInterface($lastUsed);
            $this->createNewToken(new PersistentToken($token->getClass()$token->getUserIdentifier()$tmpSeries$token->getTokenValue()$lastUsed));

            $this->conn->commit();
        } catch (\Exception $e) {
            $this->conn->rollBack();
            throw $e;
        }
    }

    
/** * @var Connection */
    protected $connection;

    /** * @before */
    public function pluginIntegrationSetUp(): void
    {
        $this->connection = Kernel::getConnection();
        $this->connection->beginTransaction();
        $this->connection->executeStatement('DELETE FROM plugin');

        $this->classLoader = clone KernelLifecycleManager::getClassLoader();
        KernelLifecycleManager::getClassLoader()->unregister();
        $this->classLoader->register();
    }

    /** * @after */
    public function pluginIntegrationTearDown(): void
    {

    }

    /** * @dataProvider provideEndTransactionMethod */
    public function testTransaction(callable $endTransactionMethod, string $expectedEndTransactionDebug)
    {
        $this->init();

        $this->conn->setNestTransactionsWithSavepoints(true);
        $this->conn->beginTransaction();
        $this->conn->beginTransaction();
        $this->conn->executeStatement('INSERT INTO products(name, price, stock) VALUES ("product1", 12.5, 5)');
        $endTransactionMethod($this->conn);
        $endTransactionMethod($this->conn);
        $this->conn->beginTransaction();
        $this->conn->executeStatement('INSERT INTO products(name, price, stock) VALUES ("product2", 15.5, 12)');
        $endTransactionMethod($this->conn);

        $debug = $this->debugDataHolder->getData()['default'] ?? [];
        $this->assertCount(9, $debug);
        $this->assertSame('"START TRANSACTION"', $debug[1]['sql']);
        
Home | Imprint | This part of the site doesn't use cookies.