Ejemplo n.º 1
0
 public function testEventPropagationIsStopped()
 {
     $l1 = new DemoEventListener('A');
     $l2 = new DemoEventListener('B', true);
     $l3 = new DemoEventListener('C');
     $l4 = new DemoEventListener('D');
     $event = new DemoEvent('DEMO');
     $dispatcher = new EventManager();
     $dispatcher->addEventListener('demo.event', $l1);
     $dispatcher->addEventListener('demo.event', $l2);
     $dispatcher->addEventListener('demo.event', $l3);
     $dispatcher->addEventListener('other.event', $l4);
     $result = $dispatcher->dispatch('demo.event', $event);
     // Check event state
     $this->assertSame($result, $event);
     $this->assertTrue($event->isStopped());
     $this->assertSame('B', $event->getState());
     $this->assertCount(2, $event->getStackedListeners());
     $this->assertContains($l1, $event->getStackedListeners());
     $this->assertContains($l2, $event->getStackedListeners());
     $this->assertNotContains($l3, $event->getStackedListeners());
     $this->assertNotContains($l4, $event->getStackedListeners());
     // Check listeners state
     $this->assertTrue($l1->isCalled());
     $this->assertTrue($l1->isCalled());
     $this->assertFalse($l3->isCalled());
     $this->assertFalse($l4->isCalled());
 }
Ejemplo n.º 2
0
 /**
  * @expectedException \RuntimeException
  */
 public function testNoGeneratedResponseForException()
 {
     $em = new EventManager();
     $em->addEventListener(KernelEvents::EXCEPTION, function (ExceptionEvent $event) {
         // do not generate a response!
     });
     $kernel = new HttpKernel($em, new ClosureControllerFactory());
     $kernel->handle(Request::create('GET', '/home'));
 }
Ejemplo n.º 3
0
});
$dic->register('router', function (ServiceLocator $dic) {
    $loader = new CompositeFileLoader();
    $loader->add(new PhpFileLoader());
    $loader->add(new XmlFileLoader());
    return new Router($dic->getParameter('router.file'), $loader);
});
$dic->register('error_handler', function (ServiceLocator $dic) {
    return new ErrorHandler($dic->getService('renderer'), $dic->getParameter('app.environment'), $dic->getParameter('app.debug'));
});
$dic->register('session', function (ServiceLocator $dic) {
    return new Session(new NativeDriver(), $dic->getParameter('session.options'));
});
$dic->register('logger', function (ServiceLocator $dic) {
    $level = $dic->getParameter('app.debug') ? Logger::WARNING : Logger::CRITICAL;
    $logger = new Logger('blog');
    $logger->pushHandler(new StreamHandler($dic->getParameter('logger.log_file'), $level));
    return $logger;
});
$dic->register('event_manager', function (ServiceLocator $dic) {
    $manager = new EventManager();
    $manager->addEventListener(KernelEvents::REQUEST, [new RouterListener($dic->getService('router')), 'onKernelRequest']);
    $manager->addEventListener(KernelEvents::CONTROLLER, [new ControllerListener($dic), 'onKernelController']);
    $manager->addEventListener(KernelEvents::EXCEPTION, [new LoggerHandler($dic->getService('logger')), 'onKernelException']);
    $manager->addEventListener(KernelEvents::EXCEPTION, [$dic->getService('error_handler'), 'onKernelException']);
    return $manager;
});
$dic->register('http_kernel', function (ServiceLocator $dic) {
    return new HttpKernel($dic->getService('event_manager'), new ControllerFactory());
});
return $dic;