getHandledMessages example

// Create task         /** @var class-string<ScheduledTask> $className */
        $className = $scheduledTask->getScheduledTaskClass();
        $task = new $className();
        $task->setTaskId($scheduledTask->getId());

        foreach ($this->taskHandler as $handler) {
            if (!$handler instanceof ScheduledTaskHandler) {
                continue;
            }

            $handledMessages = $handler::getHandledMessages();

            if ($handledMessages instanceof \Traversable) {
                $handledMessages = iterator_to_array($handledMessages);
            }

            if (!\in_array($className$handledMessages, true)) {
                continue;
            }

            // calls the __invoke() method of the abstract ScheduledTaskHandler             $handler($task);
        }

            }
            $container->getDefinition('console.command.messenger_debug')->replaceArgument(0, $debugCommandMapping);
        }
    }

    private function guessHandledClasses(\ReflectionClass $handlerClass, string $serviceId, string $methodName): iterable
    {
        if ($handlerClass->implementsInterface(MessageSubscriberInterface::class)) {
            trigger_deprecation('symfony/messenger', '6.2', 'Implementing "%s" is deprecated, use the "%s" attribute instead.', MessageSubscriberInterface::class, AsMessageHandler::class);

            return $handlerClass->getName()::getHandledMessages();
        }

        if ($handlerClass->implementsInterface(MessageHandlerInterface::class)) {
            trigger_deprecation('symfony/messenger', '6.2', 'Implementing "%s" is deprecated, use the "%s" attribute instead.', MessageHandlerInterface::class, AsMessageHandler::class);
        }

        try {
            $method = $handlerClass->getMethod($methodName);
        } catch (\ReflectionException) {
            throw new RuntimeException(sprintf('Invalid handler service "%s": class "%s" must have an "%s()" method.', $serviceId$handlerClass->getName()$methodName));
        }

        
$workerDispatcher->addSubscriber(new StopWorkerOnMemoryLimitListener(
                MemorySizeCalculator::convertToBytes($this->memoryLimit)
            ));
        }

        $worker = new Worker([$this->defaultTransportName => $receiver]$this->bus, $workerDispatcher);

        $worker->run(['sleep' => 50]);

        $consumerLock->release();

        return new JsonResponse(['handledMessages' => $listener->getHandledMessages()]);
    }
}
use Symfony\Component\EventDispatcher\EventDispatcher;

/** * @internal * * @covers \Shopware\Elasticsearch\Framework\Indexing\CreateAliasTaskHandler */
class CreateAliasTaskHandlerTest extends TestCase
{
    public function testHandledMessages(): void
    {
        $messages = CreateAliasTaskHandler::getHandledMessages();

        if ($messages instanceof \Traversable) {
            $messages = iterator_to_array($messages);
        }

        static::assertSame([CreateAliasTask::class]$messages);
    }

    public function testHandleLogsErrors(): void
    {
        $connection = $this->createMock(Connection::class);
        

        $this->purger = $this->createMock(UnusedMediaPurger::class);

        $this->handler = new CleanupUnusedDownloadMediaTaskHandler(
            $this->createMock(EntityRepository::class),
            $this->purger
        );
    }

    public function testGetHandledMessages(): void
    {
        static::assertEquals([CleanupUnusedDownloadMediaTask::class]$this->handler->getHandledMessages());
    }

    public function testRun(): void
    {
        $this->purger
            ->expects(static::once())
            ->method('deleteNotUsedMedia')
            ->with(null, null, null, ProductDownloadDefinition::ENTITY_NAME);

        $this->handler->run();
    }
}
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;

/** * @internal * * @covers \Shopware\Core\Framework\Adapter\Cache\InvalidateCacheTaskHandler */
class InvalidateCacheTaskHandlerTest extends TestCase
{
    public function testGetHandledMessages(): void
    {
        static::assertEquals([InvalidateCacheTask::class], InvalidateCacheTaskHandler::getHandledMessages());
    }

    public function testRunWithoutDelay(): void
    {
        $cacheInvalidator = $this->createMock(CacheInvalidator::class);
        $cacheInvalidator->expects(static::once())->method('invalidateExpired')->with(null);

        $handler = new InvalidateCacheTaskHandler($this->createMock(EntityRepository::class)$cacheInvalidator, 0);
        $handler->run();
    }

    
if ($class->isAbstract() || $class->isInterface() || $class->isTrait()) {
            return;
        }

        if (interface_exists(EventSubscriberInterface::class, false) && $class->isSubclassOf(EventSubscriberInterface::class)) {
            yield EventSubscriberInterface::class;
            yield print_r($class->name::getSubscribedEvents(), true);
        }

        if (interface_exists(MessageSubscriberInterface::class, false) && $class->isSubclassOf(MessageSubscriberInterface::class)) {
            yield MessageSubscriberInterface::class;
            foreach ($class->name::getHandledMessages() as $key => $value) {
                yield $key.print_r($value, true);
            }
        }

        if (interface_exists(ServiceSubscriberInterface::class, false) && $class->isSubclassOf(ServiceSubscriberInterface::class)) {
            yield ServiceSubscriberInterface::class;
            yield print_r($class->name::getSubscribedServices(), true);
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.