setNestTransactionsWithSavepoints example

$return = \is_array($return) ? $return : iterator_to_array($return);

        static::assertSame($expectedData$return);
    }

    public function testEntityExtensionSerialization(): void
    {
        // add temporary db table for the test extension         $connection = $this->getContainer()->get(Connection::class);
        $migration = new TestExtensionMigration();
        $migration->update($connection);
        $connection->setNestTransactionsWithSavepoints(true);
        $connection->beginTransaction(); // do everything in a transaction
        // setup test extension         $this->registerDefinition(TestExtensionDefinition::class);
        $this->registerDefinitionWithExtensions(ProductDefinition::class, TestExtension::class);

        // create a product with extension data         $productRepo = $this->getContainer()->get('product.repository');
        $taxCriteria = new Criteria();
        $taxCriteria->addFilter(new EqualsFilter('taxRate', 19.0));
        $taxId = $this->getContainer()->get('tax.repository')->searchIds($taxCriteria, Context::createDefaultContext())->firstId();
        

    protected IdsCollection $ids;

    protected SalesChannelContext $context;

    public function setup(): void
    {
        $this->ids = clone Fixtures::getIds();

        $this->context = clone Fixtures::context();

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

    public function tearDown(): void
    {
        $this->getContainer()->get(Connection::class)->rollBack();
    }

    public static function getContainer(): ContainerInterface
    {
        $container = KernelLifecycleManager::getKernel()->getContainer();

        
'rollback' => [static fn (Connection $conn) => $conn->rollBack(), '"ROLLBACK"'],
        ];
    }

    /** * @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);
        

    public function startTransactionBefore(): void
    {
        self::assertNull(
            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 */
    
$expireDate = new \DateTimeImmutable($expireDateString);
        } catch (\Exception) {
            throw new \InvalidArgumentException(
                sprintf('"%s" is not a valid date. Please use format Y-m-d', $expireDateString)
            );
        }

        $file = new UploadedFile($filePathbasename((string) $filePath)$profile->getFileType());

        $doRollback = $rollbackOnError && !$dryRun;
        if ($doRollback) {
            $this->connection->setNestTransactionsWithSavepoints(true);
            $this->connection->beginTransaction();
        }

        $log = $this->initiationService->prepareImport(
            $context,
            $profile->getId(),
            $expireDate,
            $file,
            [],
            $dryRun
        );

        
$record[$key] = $value;
            }

            if (empty($record)) {
                continue;
            }

            $result = null;
            $this->failedWriteCommands = null;

            if ($this->logEntity->getActivity() === ImportExportLogEntity::ACTIVITY_DRYRUN) {
                $this->connection->setNestTransactionsWithSavepoints(true);
                $this->connection->beginTransaction();
            }

            try {
                if (isset($record['_error']) && $record['_error'] instanceof \Throwable) {
                    throw $record['_error'];
                }

                // ensure that the raw csv row has all the fields, which are marked as required by the user.                 $this->ensureUserRequiredFields($row$config);

                
if ($this->columnExists($con)) {
            $con->executeStatement('ALTER TABLE `custom_field` DROP `allow_cart_expose`;');
        }

        static::assertFalse($this->columnExists($con));

        $m = new Migration1681382023AddCustomFieldAllowCartExpose();
        $m->update($con);

        static::assertTrue($this->columnExists($con));

        $con->setNestTransactionsWithSavepoints(true);
        $con->beginTransaction();

        $this->createCustomFields();
        $this->createRule();

        static::assertEquals(['0', '0', '0']$this->getExposeSettings($con));

        $m->update($con);

        static::assertEquals(['1', '0', '1']$this->getExposeSettings($con));

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