/**
  * @expectedException \RuntimeException
  */
 public function testDebugResponse()
 {
     $app = new Application();
     $app['debug'] = true;
     $app->handlers([new ResponseMiddleware($app), function () {
         throw new \RuntimeException();
     }]);
     $response = $app->handle(new Request());
 }
Example #2
0
 public function testIntegerParam()
 {
     $app = new Application();
     $app->handlers([new RouterMiddleware($app)]);
     $app->route('/blog/{id:[0-9]+}', function () {
         $this->response($this->params('id'));
     });
     $response = $app->handle(Request::create('/blog/12345'));
     $this->assertSame('12345', $response->getContent());
     $this->assertSame(200, $response->getStatusCode());
 }
Example #3
0
 /**
  * @expectedException \Exception
  */
 public function testHandleExceptionGivenSubRequestShouldThrowException()
 {
     if (!class_exists('Whoops\\Run')) {
         $this->markTestSkipped();
     }
     $app = new Application();
     $app->handlers([new WhoopsMiddleware($app), function () {
         throw new \Exception('foo');
     }]);
     $app['app.context']->request(new Request(), HttpKernelInterface::SUB_REQUEST);
     $app->run();
 }
Example #4
0
 /**
  * Register the route collector and dispatcher.
  *
  * @param Application $app The application container
  */
 public function __construct(Application $app)
 {
     $app['router.collector'] = $app->share(function ($app) {
         return new RouteCollector(new RouteParser(), new DataGenerator());
     });
     $app['router.dispatcher'] = $app->share(function ($app) {
         foreach ($app['app.routes']->dump() as $route => $methods) {
             foreach ($methods as $method => $handlers) {
                 $app['router.collector']->addRoute($method, $route, $handlers);
             }
         }
         return new Dispatcher($app['router.collector']->getData());
     });
     parent::__construct($app);
 }
Example #5
0
 /**
  * @expectedException \LogicException
  */
 public function testRunWithUncaughtException()
 {
     $app = new Application();
     $context = $app['app.context'];
     $probe = $this->getMock('Durian\\Handler');
     $probe->expects($this->once())->method('context')->will($this->throwException(new \LogicException()));
     $callback = function () use($probe) {
         try {
             yield;
         } catch (\RuntimeException $e) {
         }
     };
     $generator = $callback();
     $handler1 = $this->getMock('Durian\\Handler');
     $handler1->expects($this->once())->method('__invoke')->will($this->returnValue($generator));
     $handler2 = function () use($probe, $context) {
         $probe->context($context);
     };
     $app->handlers([$handler1, $handler2]);
     $app->run();
 }