/** * {@inheritDoc} */ public function register(App $app) { $app->add(function ($req, $res) { $this->ran = true; return $res; }); }
public function configure(App $app) { $router = $app->router(); $router->get('/', function ($req, $res) { $res->write('foo'); }); return $router; }
public function testRegister() { $app = new App(); $container = $app->getContainer(); $package = new Package(['alias' => 'foo']); $package->register($app); $this->assertTrue($container->has('foo')); }
public function testRedirectToRoute() { $this->app->get('/foo', function ($req, Response $res) { return $res->write('foo'); })->name('foo'); $response = $this->response->redirectToRoute('foo'); $this->assertNotEmpty($response->getHeader('Location')); $this->assertSame('/foo', $response->getHeader('Location')[0]); }
public function testDecoration() { $result = $this->app->__invoke($this->newRequest('/'), new Response(), function ($req, $res) { $this->assertInstanceOf(TonisRequest::class, $req); $this->assertInstanceOf(TonisResponse::class, $res); $res->write('success'); }); $this->assertSame('success', $result->getBody()->__toString()); $result = $this->app->__invoke($this->newTonisRequest('/'), $this->newTonisResponse(), function ($req, $res) { $this->assertInstanceOf(TonisRequest::class, $req); $this->assertInstanceOf(TonisResponse::class, $res); $res->write('success'); }); $this->assertSame('success', $result->getBody()->__toString()); }
/** * Attempts to render the `$template` with `$params` using the ViewManager. If a strategy * is not available then the Tonis fallback strategy is used. * * @param string $template * @param array $params * @return string */ public function render($template, array $params = []) { return $this->write($this->app->getView()->render($template, $params)); }
protected function setUp() { $app = new App(); $app->package(new DoctrineORMPackage()); $this->app = $app; }