Beispiel #1
0
 /**
  * Test dispatch chained middlewares.
  */
 public function testDispatchChainedMiddlewares()
 {
     $this->given($eventBus = EventBus::create())->and($event = new LoginUserEvent('*****@*****.**'))->and($eventBus->addListener($event->eventName(), function (LoginUserEvent $event) {
         $this->string($event->email())->isEqualTo('*****@*****.**');
         $event->setEmail('*****@*****.**');
     }))->and($eventBus->dispatch($event))->then()->string($event->email())->isEqualTo('*****@*****.**');
 }
 /**
  * Test Handle method.
  */
 public function testHandle()
 {
     $this->given($dispatcher = new EventDispatcher())->and($middleware = new EventDispatcherMiddleware($dispatcher))->and($event = new LoginUserEvent('*****@*****.**'))->and($dispatcher->addListener($event->eventName(), array(new LoginUserEventListener(), 'loginUser')))->and($dispatcher->addListener($event->eventName(), function (LoginUserEvent $event) {
         $this->string($event->email())->isEqualTo('*****@*****.**');
         $event->setEmail('*****@*****.**');
     }))->and($callable = function (LoginUserEvent $event) {
         $event->setEmail('*****@*****.**');
     })->when($result = $middleware->handle($event, $callable))->then()->string($event->email())->isEqualTo('*****@*****.**')->exception(function () use($middleware, $callable) {
         $middleware->handle(new \StdClass(), $callable);
     })->isInstanceOf(\InvalidArgumentException::class);
 }
 /**
  * @param LoginUserEvent $event
  *
  * @return bool
  */
 public function onLoginSuccess(LoginUserEvent $event)
 {
     $event->setEmail('*****@*****.**');
 }