Skip to content

Instantly share code, notes, and snippets.

@asgrim
Created May 18, 2015 22:51
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 asgrim/60c73a0fffab11c60528 to your computer and use it in GitHub Desktop.
Save asgrim/60c73a0fffab11c60528 to your computer and use it in GitHub Desktop.
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd 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);
$this->assertTrue(TestFoo::$isTriggered);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment