-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix: Reset Route arguments for each call #2431
Conversation
Why is process() called more than once for a given route? |
This is indeed a problem you will run into if you try to use Slim under PPM/ReactPHP, so this would be appreciated However spellcheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I call setArguments()
, then $savedArguments
needs resetting I think?
I don't think so @akrabat . |
This test fails: public function testInvokeSequentialProccessAfterAddingAnotherRouteArgument()
{
$app = new App();
$route = $app->get('/foo[/{bar}]', function ($req, $res, $args) {
return $res->write(count($args));
})->setArgument('baz', 'quux');
// Prepare request and response objects
$env = Environment::mock([
'SCRIPT_NAME' => '/index.php',
'REQUEST_URI' => '/foo/bar',
'REQUEST_METHOD' => 'GET',
]);
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = [];
$serverParams = $env->all();
$body = new RequestBody();
$req = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
$res = new Response();
// Invoke process with optional arg
$resOut = $app->process($req, $res);
$this->assertInstanceOf('\Psr\Http\Message\ResponseInterface', $resOut);
$this->assertEquals('2', (string)$resOut->getBody());
// Prepare request and response objects
$env = Environment::mock([
'SCRIPT_NAME' => '/index.php',
'REQUEST_URI' => '/foo/bar',
'REQUEST_METHOD' => 'GET',
]);
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = [];
$serverParams = $env->all();
$body = new RequestBody();
$req = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
$res = new Response();
// add another argument
$route->setArgument('one', '1');
// Invoke process with optional arg
$resOut2 = $app->process($req, $res);
$this->assertInstanceOf('\Psr\Http\Message\ResponseInterface', $resOut2);
$this->assertEquals('3', (string)$resOut2->getBody());
} Arguably, it's unlikely to happen, but this test works with |
This change should fix it. |
Seems reasonable to me. I've renamed the variable to make it a bit clearer though. |
@akrabat Should I patch this on 4.x? Or maybe raise an issue for review every change on 3.x tests since 4.x was created and add them to 4.x and fix it? |
@mathmarques Good point - this needs to go to 4.x too. A proportion of them have been ported forward, but it'd be good to go through and check. |
Route arguments weren't reset for each call of
App::process
and if the route had optional arguments on the url this could cause unexpected behaviors.This Fix #2430