Created
May 18, 2015 22:51
-
-
Save asgrim/60c73a0fffab11c60528 to your computer and use it in GitHub Desktop.
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
<?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