restore example

$this->createMock(SalesChannelContext::class),
            new CustomerEntity(),
            'context-token'
        );

        $storer = new ScalarValuesStorer();

        $stored = $storer->store($event[]);

        $flow = new StorableFlow('foo', Context::createDefaultContext()$stored);

        $storer->restore($flow);

        static::assertArrayHasKey('contextToken', $flow->data());
        static::assertEquals('context-token', $flow->data()['contextToken']);
    }
}
new CustomerEntity(),
            $this->createMock(SalesChannelContext::class),
            'my-confirm-url'
        );

        $storer = new ScalarValuesStorer();

        $stored = $storer->store($event[]);

        $flow = new StorableFlow('foo', Context::createDefaultContext()$stored);

        $storer->restore($flow);

        static::assertArrayHasKey('confirmUrl', $flow->data());
        static::assertEquals('my-confirm-url', $flow->data()['confirmUrl']);
    }
}

        $event = $this->createMock(CustomerRegisterEvent::class);
        $stored = [];
        $stored = $this->storer->store($event$stored);
        static::assertArrayNotHasKey(ProductAware::PRODUCT_ID, $stored);
    }

    public function testRestoreHasStored(): void
    {
        $storable = new StorableFlow('name', Context::createDefaultContext()['productId' => 'test_id']);

        $this->storer->restore($storable);

        static::assertArrayHasKey('product', $storable->data());
    }

    public function testRestoreEmptyStored(): void
    {
        $storable = new StorableFlow('name', Context::createDefaultContext());

        $this->storer->restore($storable);

        static::assertEmpty($storable->data());
    }

        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->rename(...\func_get_args());
    }

    public function renameNx($key$newkey)
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->renameNx(...\func_get_args());
    }

    public function restore($ttl$key$value)
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->restore(...\func_get_args());
    }

    public function role()
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->role(...\func_get_args());
    }

    public function rpoplpush($src$dst)
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->rpoplpush(...\func_get_args());
    }

    
/** * @param FlowStorer[] $storer */
    public function __construct(private $storer)
    {
    }

    public function create(FlowEventAware $event): StorableFlow
    {
        $stored = $this->getStored($event);

        return $this->restore($event->getName()$event->getContext()$stored);
    }

    /** * @param array<string, mixed> $stored * @param array<string, mixed> $data */
    public function restore(string $name, Context $context, array $stored = [], array $data = []): StorableFlow
    {
        $systemContext = new Context(
            new SystemSource(),
            $context->getRuleIds(),
            


        // check new value are stored correctly         static::assertArrayHasKey(ScalarValuesAware::STORE_VALUES, $stored);
        static::assertArrayHasKey('shopName', $stored[ScalarValuesAware::STORE_VALUES]);
        static::assertArrayHasKey('whatWhenIChooseAnotherName', $stored[ScalarValuesAware::STORE_VALUES]);
        static::assertEquals('my-shop-name', $stored[ScalarValuesAware::STORE_VALUES]['shopName']);
        static::assertEquals('my-shop-name', $stored[ScalarValuesAware::STORE_VALUES]['whatWhenIChooseAnotherName']);

        $flow = new StorableFlow('foo', Context::createDefaultContext()$stored[]);

        (new ScalarValuesStorer())->restore($flow);

        if (!Feature::isActive('v6.6.0.0')) {
            (new ShopNameStorer())->restore($flow);
        }

        static::assertEquals('my-shop-name', $flow->getData('shopName'));
        static::assertEquals('my-shop-name', $flow->getData('whatWhenIChooseAnotherName'));
    }

    public function testCallNewFirst(): void
    {
        
'sales-channel-id',
            new MailRecipientStruct(['foo', 'bar']),
            new DataBag(['foo' => 'bar', 'bar' => 'baz'])
        );

        $storer = new ScalarValuesStorer();

        $stored = $storer->store($event[]);

        $flow = new StorableFlow('foo', Context::createDefaultContext()$stored);

        $storer->restore($flow);

        static::assertArrayHasKey('contactFormData', $flow->data());
        static::assertEquals(['foo' => 'bar', 'bar' => 'baz']$flow->data()['contactFormData']);
    }
}
$entity->set($default_langcode_key, TRUE);
        }

        // Set the 'revision_translation_affected' field to TRUE to match the         // return value of the case when the field does not exist.         if ((!$original->isRevisionable() || !$original->isTranslatable()) && $entity_type->isRevisionable() && $entity_type->isTranslatable()) {
          $entity->set($revision_translation_affected_key, TRUE);
        }

        // Finally, save the entity in the temporary storage.         $temporary_storage->restore($entity);
      }
      catch (\Exception $e) {
        $this->handleEntityTypeSchemaUpdateExceptionOnDataCopy($entity_type$original$sandbox);

        // Re-throw the original exception with a helpful message.         $error_revision_id = $load_revisions ? ", revision ID: {$entity->getLoadedRevisionId()}" : '';
        throw new EntityStorageException("The entity update process failed while processing the entity type {$entity_type->id()}, ID: {$entity->id()}$error_revision_id.", $e->getCode()$e);
      }

      $sandbox['progress']++;
      $sandbox['current_id'] = $identifier;
    }
$storable->expects(static::exactly(1))
            ->method('hasStore')
            ->willReturn(false);

        $storable->expects(static::never())
            ->method('getStore');

        $storable->expects(static::never())
            ->method('setData');

        $this->storer->restore($storable);
    }

    public function testRestoreWithAlreadyStored(): void
    {
        Feature::skipTestIfActive('v6.6.0.0', $this);

        $confirmUrl = 'shopware-test.com';

        /** @var MockObject&StorableFlow $storable */
        $storable = $this->createMock(StorableFlow::class);

        
->method('hasStore')
            ->willReturn(true);

        $storable->expects(static::exactly(1))
            ->method('getStore')
            ->willReturn($recipients);

        $storable->expects(static::exactly(1))
            ->method('setData')
            ->with(RecipientsAware::RECIPIENTS, $recipients);

        $this->storer->restore($storable);
    }

    public function testRestoreEmptyStored(): void
    {
        $recipients = ['test'];

        /** @var MockObject&StorableFlow $storable */
        $storable = $this->createMock(StorableFlow::class);

        $storable->expects(static::exactly(1))
            ->method('hasStore')
            

        $event = $this->createMock(CustomerRegisterEvent::class);
        $stored = [];
        $stored = $this->storer->store($event$stored);
        static::assertArrayNotHasKey(CustomerRecoveryAware::CUSTOMER_RECOVERY_ID, $stored);
    }

    public function testRestoreHasStored(): void
    {
        $storable = new StorableFlow('name', Context::createDefaultContext()['customerRecoveryId' => 'test_id']);

        $this->storer->restore($storable);

        static::assertArrayHasKey('customerRecovery', $storable->data());
    }

    public function testRestoreEmptyStored(): void
    {
        $storable = new StorableFlow('name', Context::createDefaultContext());

        $this->storer->restore($storable);

        static::assertEmpty($storable->data());
    }

        $event = $this->createMock(CustomerRegisterEvent::class);
        $stored = [];
        $stored = $this->storer->store($event$stored);
        static::assertArrayNotHasKey(OrderTransactionAware::ORDER_TRANSACTION_ID, $stored);
    }

    public function testRestoreHasStored(): void
    {
        $storable = new StorableFlow('name', Context::createDefaultContext()['orderTransactionId' => 'test_id']);

        $this->storer->restore($storable);

        static::assertArrayHasKey('orderTransaction', $storable->data());
    }

    public function testRestoreEmptyStored(): void
    {
        $storable = new StorableFlow('name', Context::createDefaultContext());

        $this->storer->restore($storable);

        static::assertEmpty($storable->data());
    }
public function testRestore(): void
    {
        $expectedToken = Uuid::randomHex();
        $expectedContext = $this->createSalesChannelContext($expectedToken);

        $currentContext = $this->createSalesChannelContext('currentToken', $this->customerId);

        $this->contextPersister->save($expectedContext->getToken()[]$currentContext->getSalesChannel()->getId()$this->customerId);

        $this->eventDispatcher->addListener(SalesChannelContextRestoredEvent::class$this->callbackFn);

        $restoredContext = $this->cartRestorer->restore($this->customerId, $currentContext);

        static::assertSame($expectedContext->getToken()$restoredContext->getToken());

        static::assertArrayHasKey(SalesChannelContextRestoredEvent::class$this->events);
        $salesChannelRestoredEvent = $this->events[SalesChannelContextRestoredEvent::class];
        static::assertInstanceOf(SalesChannelContextRestoredEvent::class$salesChannelRestoredEvent);
    }

    public function testGuestContextAndCartAreDeleted(): void
    {
        $currentContextToken = Random::getAlphanumericString(32);

        

        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->rename(...\func_get_args());
    }

    public function renamenx($key$newkey): \RedisCluster|bool
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->renamenx(...\func_get_args());
    }

    public function restore($key$timeout$value$options = null): \RedisCluster|bool
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->restore(...\func_get_args());
    }

    public function role($key_or_address): mixed
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->role(...\func_get_args());
    }

    public function rpop($key$count = 0): \RedisCluster|array|bool|string
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->rpop(...\func_get_args());
    }

    

        $event = $this->createMock(CustomerRegisterEvent::class);
        $stored = [];
        $stored = $this->storer->store($event$stored);
        static::assertArrayNotHasKey(UserAware::USER_RECOVERY_ID, $stored);
    }

    public function testRestoreHasStored(): void
    {
        $storable = new StorableFlow('name', Context::createDefaultContext()['userRecoveryId' => 'test_id']);

        $this->storer->restore($storable);

        static::assertArrayHasKey('userRecovery', $storable->data());
    }

    public function testRestoreEmptyStored(): void
    {
        $storable = new StorableFlow('name', Context::createDefaultContext());

        $this->storer->restore($storable);

        static::assertEmpty($storable->data());
    }
Home | Imprint | This part of the site doesn't use cookies.