CustomAppEvent example

private Context $context;

    protected function setUp(): void
    {
        $this->context = Context::createDefaultContext();
        $this->customAppStorer = new CustomAppStorer();
    }

    public function testStoreWithAwareAndEmptyCustomData(): void
    {
        $event = new CustomAppEvent('custom_app_event', []$this->context);

        $stored = [];
        $stored = $this->customAppStorer->store($event$stored);
        static::assertEmpty($stored);
    }

    public function testStoreWithAware(): void
    {
        $customerId = Uuid::randomHex();

        $data = [
            
/** * @Since("6.5.2.0") */
    #[Route(path: '/api/_action/trigger-event/{eventName}', name: 'api.action.trigger_event', methods: ['POST'])]     public function trigger(string $eventName, Request $request, Context $context): JsonResponse
    {
        $data = $request->request->all();

        $this->checkAppEventIsExist($eventName$context);

        $this->eventDispatcher->dispatch(new CustomAppEvent($eventName$data$context)$eventName);

        return new JsonResponse([
            'message' => \sprintf('The trigger `%s`successfully dispatched!', $eventName),
        ], Response::HTTP_OK);
    }

    private function checkAppEventIsExist(string $eventName, Context $context): void
    {
        $criteria = new Criteria();
        $criteria->setLimit(1);
        $criteria->addFilter(new EqualsFilter('name', $eventName));
        
Home | Imprint | This part of the site doesn't use cookies.