public function testBindContextToClosure() { $handler = new Handler(function () { return $this->request(); }, function () { return $this->master(); }); $request = new Request(); $context = $this->getMock('Durian\\Context'); $context->expects($this->once())->method('request')->will($this->returnValue($request)); $context->expects($this->once())->method('master')->will($this->returnValue(true)); $handler->context($context); $this->assertSame($context, $handler->context()); $this->assertSame($request, call_user_func($handler)); }
/** * Constructor. * * @param array $values Defaults to override */ public function __construct(array $values = []) { parent::__construct(); $this['debug'] = false; $this['app.catch_errors'] = true; $this['app.handler'] = $this->share(function ($app) { $handler = new Handler(null, null, ['iterate' => true]); $handler->handlers(array_map([$handler, 'handler'], $app['app.handlers'])); return $handler; }); $this['app.handlers'] = $this->share(function ($app) { return [new Middleware\ResponseMiddleware($app), new Middleware\RouterMiddleware($app)]; }); $this['app.context'] = $this->share(function ($app) { return new ContextProxy(); }); $this['app.routes'] = $this->share(function ($app) { return new Route(); }); foreach ($values as $key => $value) { $this[$key] = $value; } }