ProductStatesChangedEvent example

$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[] */
    private function getNewStates(array $product): array
    {
        $states = [];

        

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.