mercredi 3 février 2016

How to test in functional test if event has been dispatched

I am testing a controller action using a functional test in Symfony. In this test I am doing something like this:

$client->request(
    'PUT',
    '/api/nodes/',
    $data
);

Afterwards I would like to test if a certain event has been dispatched. I already tried to enable the profiler previously (and set the config accordingly) and check the data in the EventDataCollector:

$client->enableProfiler();
$client->request(
    'PUT',
    '/api/nodes/' . $data[0]['id'] . '?webspace=sulu_io&language=en',
    $data[0]
);

/** @var EventDataCollector $eventDataCollector */
$eventDataCollector = $client->getProfile()->getCollector('events');

This works as expected, but the problem is that the $eventDataCollector only contains data about the events for which some listeners have actually been executed. Fortunately there is an event listener executed in this specific case, but I would like that to work also without any event listeners attached, since I can't say for sure that this situation will continue to be like that.

So my question is if there is a way to test if a event is dispatched, which is save, even if there wasn't a event listener attached.

Aucun commentaire:

Enregistrer un commentaire