public function test_invoke()
 {
     $shared = [];
     $invoker = new SubscriberInvoker();
     $event = new CustomEvent();
     $event->setShared($shared);
     $this->assertFalse($invoker->invoke(new EventSubscription(1, 'foo', 'bla'), $event));
     $this->assertEquals([], $shared);
     $this->assertTrue($invoker->invoke(new EventSubscription(1, 'foo', CustomSubscriber::class), $event));
     $this->assertEquals([2], $shared);
     $this->assertTrue($invoker->invoke(new EventSubscription(1, 'foo', new CustomSubscriber()), $event));
     $this->assertEquals([2, 2], $shared);
 }
Exemple #2
0
 public function test_invoke_subscriber()
 {
     $shared = [];
     $eventer = new Eventer();
     $eventer->subscribe(CustomEvent::class, function (CustomEvent $event) use(&$shared) {
         $shared[] = 1;
     });
     $eventer->dispatch(new CustomEvent());
     $this->assertEquals([1], $shared);
     $eventer->subscribe(CustomEvent::class, CustomSubscriber::class);
     $event = new CustomEvent();
     $event->setShared($shared);
     $eventer->dispatch($event);
     $this->assertEquals([1, 1, 2], $shared);
 }