Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Functional Testing Events and Subscribers in Symfony 4

$
0
0

I need to functionally test the a subscriber in Symfony 4 and I'm having problems finding how. The Subscriber has the following structure

/**
* Class ItemSubscriber
*/
class ItemSubscriber implements EventSubscriberInterface
{
    /**
     * @var CommandBus
     */
    protected $commandBus;

    /**
     * Subscriber constructor.
     *
     * @param CommandBus $commandBus
     */
    public function __construct(CommandBus $commandBus)
    {
        $this->commandBus = $commandBus;
    }

    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents()
    {
        return [
            CommandFailedEvent::NAME => 'onCommandFailedEvent',
        ];
    }

    /**
     * @param CommandFailedEvent $event
     *
     * @throws Exception
     */
    public function onCommandFailedEvent(CommandFailedEvent $event)
    {
        $item = $event->getItem();
        $this->processFailed($item);
    }

    /**
     * Sends message 
     *
     * @param array $item
     *
     * @throws Exception
     */
    private function processFailed(array $item)
    {
        $this->commandBus->handle(new UpdateCommand($item));
    }
}

The flow of the subscriber is receiving an internal event and send a message by rabbit through the command bus to another project.

How can I test that dispatching the event CommandFailedEvent the line in processFailed(array $item) is executed?

Does anyone has documentation on best practices to test Events and Subscribers in Symfony 4?


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>