Tests do not start and and website returns Fatal Error if routes are not defined.
If there is no routes defined, fatal error in the php error logs:
[29-Jul-2021 14:08:26 UTC] PHP Fatal error: Uncaught Slim\Exception\HttpMethodNotAllowedException: Method not allowed. Must be one of: OPTIONS in /Applications/MAMP/htdocs/flextype/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php:94
Stack trace:
#0 /Applications/MAMP/htdocs/flextype/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(58): Slim\Middleware\RoutingMiddleware->performRouting(Object(Slim\Psr7\Request))
#1 /Applications/MAMP/htdocs/flextype/vendor/slim/slim/Slim/MiddlewareDispatcher.php(147): Slim\Middleware\RoutingMiddleware->process(Object(Slim\Psr7\Request), Object(class@anonymous))
#2 /Applications/MAMP/htdocs/flextype/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): class@anonymous->handle(Object(Slim\Psr7\Request))
#3 /Applications/MAMP/htdocs/flextype/vendor/slim/slim/Slim/App.php(215): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request))
#4 /Applications/MAMP/htdocs/flextype/vendor/slim/slim/Slim/App.php(199): Slim\App->handle(Object(Slim\Psr7\Request))
#5 /Applications/MAMP/htdocs/flextype/src/flextype/flextype.p in /Applications/MAMP/htdocs/flextype/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php on line 94
if I will add any route like this:
app()->get('/hello/{name}', function ($name, Request $request, Response $response) {
$response->getBody()->write("Hello, $name");
return $response;
});
There is no fatal errors on the website,
but when I will run ./vendor/bin/pest
I will get Fatal Error in the console
MacBook-Pro-Sergey:flextype awilum$ ./vendor/bin/pest
Slim\Exception\HttpNotFoundException
Not found.
at vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php:91
87β ->prepare($routeArguments);
88β return $request->withAttribute(RouteContext::ROUTE, $route);
89β
90β case RoutingResults::NOT_FOUND:
β 91β throw new HttpNotFoundException($request);
92β
93β case RoutingResults::METHOD_NOT_ALLOWED:
94β $exception = new HttpMethodNotAllowedException($request);
95β $exception->setAllowedMethods($routingResults->getAllowedMethods());
+5 vendor frames
6 src/flextype/flextype.php:467
Slim\App::run()
7 tests/Pest.php:17
include("/Applications/MAMP/htdocs/flextype/src/flextype/flextype.php")
I donβt have such issue previously in the Slim3
How to fix this in Slim4?