getUpdatedStates example


class ProductStatesBeforeChangeEventTest extends TestCase
{
    public function testProductStatesBeforeChangeEvent(): void
    {
        $updatedStates = [new UpdatedStates('foobar', ['foo']['bar'])];
        $context = Context::createDefaultContext();

        $event = new ProductStatesBeforeChangeEvent($updatedStates$context);

        static::assertEquals($updatedStates$event->getUpdatedStates());
        static::assertEquals($context$event->getContext());

        $updatedStates = [new UpdatedStates('foobar', ['foo']['baz'])];
        $event->setUpdatedStates($updatedStates);

        static::assertEquals($updatedStates$event->getUpdatedStates());
    }
}
return;
        }

        $query = new RetryableQuery(
            $this->connection,
            $this->connection->prepare('UPDATE `product` SET `states` = :states WHERE `id` = :id AND `version_id` = :version')
        );

        $event = new ProductStatesBeforeChangeEvent($updates$context);
        $this->eventDispatcher->dispatch($event);

        foreach ($event->getUpdatedStates() as $updatedStates) {
            $query->execute([
                'states' => json_encode($updatedStates->getNewStates(), \JSON_THROW_ON_ERROR),
                'id' => Uuid::fromHexToBytes($updatedStates->getId()),
                'version' => Uuid::fromHexToBytes($context->getVersionId()),
            ]);
        }

        $this->eventDispatcher->dispatch(new ProductStatesChangedEvent($event->getUpdatedStates()$context));
    }

    /** * @param mixed[] $product * * @return string[] */

class ProductStatesChangedEventTest extends TestCase
{
    public function testProductStatesChangedEvent(): void
    {
        $updatedStates = [new UpdatedStates('foobar', ['foo']['bar'])];
        $context = Context::createDefaultContext();

        $event = new ProductStatesChangedEvent($updatedStates$context);

        static::assertEquals($updatedStates$event->getUpdatedStates());
        static::assertEquals($context$event->getContext());
    }
}
Home | Imprint | This part of the site doesn't use cookies.