📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials PHPUnit Testing Testing Events

Testing Events

4 min read
Write BDD Gherkin feature files with Behat and implement PHP step definitions in context classes.

Testing Events

// Plain PHP
public function testEventFiresOnCreate(): void {
    $eventFired = false;
    $dispatcher = new EventDispatcher();
    $dispatcher->listen(PostCreated::class, function() use (&$eventFired) {
        $eventFired = true;
    });
    $service = new PostService($dispatcher);
    $service->create(["title"=>"Hello","body"=>"World"]);
    $this->assertTrue($eventFired);
}