Exemplo n.º 1
0
 public function testGlobalHandlersAreCalled()
 {
     $ev = new Event("whatever", array());
     $handlerMock = $this->_getEventHandlerMock();
     $eventHandlerList = new EventHandlerList();
     $eventHandlerList->register('EventHandlerMock', $handlerMock);
     $e = new EventEmitter($eventHandlerList);
     $e->registerHandler("myHandler1", $handlerMock);
     $called = $e->broadcast($ev);
     $this->assertEquals($called, 2);
 }
Exemplo n.º 2
0
<?php

include_once 'vendor/autoload.php';
include_once 'TestEvent.php';
include_once 'TextFileDumpSampleHandler.php';
use Mamoreno\Sample\TestEvent;
use Mamoreno\Sample\TextFileDumpSampleHandler;
use Mamoreno\Pesy\HandlersCentre;
use Mamoreno\Pesy\EventEmitter;
$handlersCentre = HandlersCentre::getWithHandlers(array('TextFileDump' => new TextFileDumpSampleHandler(array("sample:*")), 'OtherTextFileDump' => new TextFileDumpSampleHandler(array("another:path:*"))));
$eventEmitter = new EventEmitter($handlersCentre->getList());
$e = new TestEvent();
$e->setPath("sample:path");
$e->addData("key1", "value1");
$e->addData("key2", array(1, 2, 3));
$eventEmitter->broadcast($e);
$e = new TestEvent();
$e->setPath("wontBeHandled");
$e->addData("wontAppear", "in text file");
$eventEmitter->broadcast($e);
$e = new TestEvent();
$e->setPath("another:path:like:this");
$e->addData("will appear", "in text file");
$eventEmitter->broadcast($e);