/** * @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()); }
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()); }
/** * @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(); }
/** * @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(); }