Skip to content
Permalink
Browse files

Checking for presence of _method and using over getMethod()

  • Loading branch information...
cjquinn committed Oct 7, 2016
1 parent 98c4a6b commit fc1a4393e5402e74c915392c9064dfa18bde609b
@@ -40,7 +40,9 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
$params = (array)$request->getAttribute('params', []);
if (empty($params['controller'])) {
$path = $request->getUri()->getPath();
$request = $request->withAttribute('params', Router::parse($path, $request->getMethod()));
$parsedBody = $request->getParsedBody();
$method = is_array($parsedBody) && isset($parsedBody['_method']) ? $parsedBody['_method'] : $request->getMethod();
$request = $request->withAttribute('params', Router::parse($path, $method));
}
} catch (RedirectException $e) {
return new RedirectResponse(
@@ -133,4 +133,33 @@ public function testMissingRouteNotCaught()
$middleware = new RoutingMiddleware();
$middleware($request, $response, $next);
}
/**
* Test route with _method being parsed correctly.
*
* @return void
*/
public function testFakedRequestMethodParsed()
{
Router::connect('/articles-patch', [
'controller' => 'Articles',
'action' => 'index',
'_method' => 'PATCH'
]);
$request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/articles-patch'], null, ['_method' => 'PATCH']);
$response = new Response();
$next = function ($req, $res) {
$expected = [
'controller' => 'Articles',
'action' => 'index',
'_method' => 'PATCH',
'plugin' => null,
'pass' => [],
'_matchedRoute' => '/articles-patch'
];
$this->assertEquals($expected, $req->getAttribute('params'));
};
$middleware = new RoutingMiddleware();
$middleware($request, $response, $next);
}
}

0 comments on commit fc1a439

Please sign in to comment.
You can’t perform that action at this time.