Ejemplo n.º 1
0
 public function test_that_all_events_key_subscribes_to_any_event()
 {
     $subscriber = new EventLogSubscriber();
     $this->dispatcher->register($subscriber);
     $event = new UserRegisteredEvent('*****@*****.**', 'James', 'Smith', 'D');
     $this->dispatcher->dispatch($event);
     $logs = $subscriber->getLogs();
     $payload = '{prefix:NULL,first_name:James,middle_name:D,last_name:Smith,suffix:NULL,email:jsmith@example.com}';
     $this->assertContains($payload, $logs[0]);
 }
Ejemplo n.º 2
0
 public function test_that_event_is_logged_by_subscriber()
 {
     $event = new UserRegisteredEvent('*****@*****.**', 'James', 'Smith', 'D');
     $this->dispatcher->dispatch($event);
     $this->assertTrue($this->logHandler->hasInfoThatContains(sprintf('Event dispatched {%s}', ClassName::canonical(UserRegisteredEvent::class))));
 }
Ejemplo n.º 3
0
 /**
  * Lazy loads event handlers from the service container
  *
  * @param string $eventType The event type
  *
  * @return void
  */
 protected function lazyLoad(string $eventType)
 {
     if (isset($this->serviceIds[$eventType])) {
         foreach ($this->serviceIds[$eventType] as $args) {
             list($serviceId, $method, $priority) = $args;
             $service = $this->container->get($serviceId);
             $key = $serviceId . '.' . $method;
             if (!isset($this->services[$eventType][$key])) {
                 $this->addHandler($eventType, [$service, $method], $priority);
             } elseif ($service !== $this->services[$eventType][$key]) {
                 parent::removeHandler($eventType, [$this->services[$eventType][$key], $method]);
                 $this->addHandler($eventType, [$service, $method], $priority);
             }
             $this->services[$eventType][$key] = $service;
         }
     }
 }