public function testAdd() { $router = $this->app->router(); $router->get('/', function ($req, $res) { $res->end('success'); }); $this->app->add($router); $response = $this->app->__invoke($this->newRequest('/'), new Response()); $this->assertInstanceOf(TonisResponse::class, $response); $this->assertSame('success', $response->getBody()->__toString()); }
public function testDecoration() { $handler = function ($req, $res) { $this->assertInstanceOf(TonisRequest::class, $req); $this->assertInstanceOf(TonisResponse::class, $res); return $res->write('success'); }; $this->app->add($handler); $res = $this->app->__invoke($this->newRequest('/'), new Response()); $this->assertInstanceOf(TonisResponse::class, $res); $this->assertSame('success', $res->getBody()->__toString()); $res = $this->app->__invoke($this->newTonisRequest('/'), $this->newTonisResponse()); $this->assertInstanceOf(TonisResponse::class, $res); $this->assertSame('success', $res->getBody()->__toString()); }
/** * {@inheritDoc} */ public function register(App $app) { $app->add(function ($req, $res) { $this->ran = true; return $res; }); }