Created
July 14, 2015 12:27
-
-
Save dancourse/597e809b1bae8fca84e2 to your computer and use it in GitHub Desktop.
Behat and Laravel simple solution to listen for Events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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