Skip to content

Commit

Permalink
Env REQUEST_URI can contain query params.
Browse files Browse the repository at this point in the history
This is a typical scenario on tests, where REQUEST_URI contains path and
all params to perform a request. No need to set QUERY_STRING in
environment separately.
  • Loading branch information
adambro committed May 27, 2016
1 parent 30cfe3c commit ab5fa78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Slim/Http/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ public static function createFromEnvironment(Environment $env)

// Query string
$queryString = $env->get('QUERY_STRING', '');
if ($queryString === '') {
$queryString = parse_url('http://example.com' . $env->get('REQUEST_URI'), PHP_URL_QUERY);
}

// Fragment
$fragment = '';
Expand Down
12 changes: 12 additions & 0 deletions tests/Http/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,16 @@ public function testRequestURIContainsIndexDotPhp()
);
$this->assertSame('/foo/index.php', $uri->getBasePath());
}

public function testRequestURICanContainParams()
{
$uri = Uri::createFromEnvironment(
Environment::mock(
[
'REQUEST_URI' => '/foo?abc=123',
]
)
);
$this->assertEquals('abc=123', $uri->getQuery());
}
}

0 comments on commit ab5fa78

Please sign in to comment.