Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* Zend Framework (
* @link for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (
* @license New BSD License
namespace ZendTest\EventManager;
use Zend\EventManager\Event;
use Zend\EventManager\EventManager;
use Zend\EventManager\Exception\RuntimeException;
class TestFoo
public static $isTriggered = false;
public function __invoke()
self::$isTriggered = true;
class EventManagerTest extends \PHPUnit_Framework_TestCase
public function testLazyInstantiator()
TestFoo::$isTriggered = false;
$eventManager = new EventManager(function ($requestedListener) {
// The method name isn't being passed here (I defined as __invoke, but I don't think it matters??)
$this->assertSame('ZendTest\EventManager\TestFoo', $requestedListener);
return new TestFoo();
$eventManager->attach('MyEvent', [TestFoo::class, '__invoke']);
$event = new Event();
$eventManager->trigger('MyEvent', $event);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment