public function testNotFoundHandling() { try { $response = $this->application->handle(Request::create('/invalid-url')); throw new \RuntimeException('Application in debug mode should throws NotFoundHttpException'); } catch (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e) { $this->assertTrue(true); } }
<?php require_once __DIR__ . '/bootstrap.php'; use Minima\Provider\DatabaseProvider; use Minima\Provider\LoggerProvider; use Minima\Http\Request; use Minima\FrontendController\FrontendController; use Symfony\Component\EventDispatcher\EventDispatcher; // Configuration $configuration = array('root' => __DIR__); // Stateful Components $dispatcher = new EventDispatcher(); $database = DatabaseProvider::getConnection(); $frontendController = FrontendController::build($configuration); // Add your routes here // Build Application $application = ApplicationFactory::build($configuration, $dispatcher, $frontendController); // Handle the request $request = Request::createFromGlobals(); $response = $application->handle($request); $response->send();
public function testRedirectToLoginIfNotLogged() { $request = Request::create('/account'); $response = $this->application->handle($request); $this->assertEquals(302, $response->getStatusCode()); $this->assertTrue($this->containsString($response->getContent(), 'Redirecting to /login')); }
public function check(Request $request) { return $request->getSession()->get('user') != null; }
public function testNotFoundHandling() { $response = $this->application->handle(Request::create('/invalid-url')); $this->assertEquals('Something went wrong! (No route found for "GET /invalid-url")', $response->getContent()); }