·

photo credit: keeping my books safe via photopin (license)

Unit testing frontend events in Magento

When you are creating unit tests for Magento and you want to test the events you’re dispatching you can use the following code to manually trigger your events:

However, you’ll find that when you’re running this test, your event doesn’t get fired at all! That’s because this particular event (and many others) are fired in the frontend  configuration scope of Magento and when you use Magento from the CLI (as Magento does), only the global  configuration scope is available.
Lucky for us, we can ‘trick’ Magento into dispatching frontend  events by adding it’s event area programatically:

Hurray! Now our event is dispatched and we can continue writing our test.

Visitors give this article an average rating of 5.0 out of 5.

How would you rate this article?

Leave a Reply