Skip to content

Commit 56d7f71

Browse files
committed
Add test for useRawQueryString constructor parameter
1 parent effd152 commit 56d7f71

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

system/HTTP/URI.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,13 @@ public static function removeDotSegments(string $path): string
245245
*/
246246
public function __construct(?string $uri = null, bool $useRawQueryString = false)
247247
{
248-
$this->useRawQueryString($useRawQueryString)->setUri($uri);
248+
$this->useRawQueryString($useRawQueryString);
249+
250+
if ($uri === null) {
251+
return;
252+
}
253+
254+
$this->setUri($uri);
249255
}
250256

251257
/**
@@ -285,12 +291,8 @@ public function useRawQueryString(bool $raw = true)
285291
*
286292
* @throws HTTPException
287293
*/
288-
private function setUri(?string $uri = null): self
294+
private function setUri(string $uri): self
289295
{
290-
if ($uri === null) {
291-
return $this;
292-
}
293-
294296
$parts = parse_url($uri);
295297

296298
if (is_array($parts)) {

tests/system/HTTP/URITest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,16 +477,24 @@ public function testSetQuerySetsValue(): void
477477
$this->assertSame($expected, (string) $uri);
478478
}
479479

480-
public function testSetQuerySetsValueWithUseRawQueryString(): void
480+
public function testUseRawQueryStringAtConstructor(): void
481+
{
482+
$url = 'http://example.com/path?key=value&second.key=value.2';
483+
$uri = new URI($url, true);
484+
485+
$this->assertSame('key=value&second.key=value.2', $uri->getQuery());
486+
$this->assertSame($url, (string) $uri);
487+
}
488+
489+
public function testUseRawQueryStringAtSetter(): void
481490
{
482491
$url = 'http://example.com/path';
483492
$uri = new URI($url);
484493

485494
$uri->useRawQueryString()->setQuery('?key=value&second.key=value.2');
486495

487496
$this->assertSame('key=value&second.key=value.2', $uri->getQuery());
488-
$expected = 'http://example.com/path?key=value&second.key=value.2';
489-
$this->assertSame($expected, (string) $uri);
497+
$this->assertSame('http://example.com/path?key=value&second.key=value.2', (string) $uri);
490498
}
491499

492500
public function testSetQueryArraySetsValue(): void

0 commit comments

Comments
 (0)