Skip to content

Instantly share code, notes, and snippets.

@dancourse
Created July 14, 2015 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dancourse/597e809b1bae8fca84e2 to your computer and use it in GitHub Desktop.
Save dancourse/597e809b1bae8fca84e2 to your computer and use it in GitHub Desktop.
Behat and Laravel simple solution to listen for Events
Feature: XXX
XXX
Scenario: Our Behat BDD will listen for events
When I listen for the event "PodcastPurchasedEvent"
And I got to "buy"
And I press "Submit"
Then I heard the event "PodcastPurchasedEvent"
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{
/**
* @When I listen for the event :event
*/
public function iListenForTheEvent($event)
{
$redis = Redis::connection();
$redis->set('eventHeard', false);
Event::listen("App\Events\\$event", function($event) use($redis)
{
$redis->set('eventHeard', true);
});
}
/**
* @Then I heard the event :event
*/
public function iHeardTheEvent($event)
{
$redis = Redis::connection();
PHPUnit::assertEquals(1, $redis->get('eventHeard'), 'Event expected and was not fired, $event');
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment