Skip to content

Commit d33aa2b

Browse files
pl-githubtemp
authored andcommitted
fix: Ignore empty query string
1 parent 2a6f6a7 commit d33aa2b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/HttpClientMock/MockRequestBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,10 @@ private function applyEncodedQueryParams(string $encodedParams): void
437437
*/
438438
private function parseEncodedParams(string $encodedParams): array
439439
{
440+
if ($encodedParams === '') {
441+
return [];
442+
}
443+
440444
$params = [];
441445

442446
foreach (explode('&', $encodedParams) as $keyValue) {

tests/HttpClientMock/MockRequestBuilderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ public function testSupportsQueryParams(): void
118118
self::assertSame(['one' => '1', 'two' => '2', 'three' => 'a b c'], $mockRequestBuilder->getQueryParams());
119119
}
120120

121+
public function testIgnoresEmptyQueryString(): void
122+
{
123+
$mockRequestBuilder = new MockRequestBuilder();
124+
$mockRequestBuilder->uri('http://example.org?');
125+
126+
self::assertNull($mockRequestBuilder->getQueryParams());
127+
self::assertSame('http://example.org', $mockRequestBuilder->getUri());
128+
}
129+
121130
public function testExceptionIsResettable(): void
122131
{
123132
$mockRequestBuilder = (new MockRequestBuilder())

0 commit comments

Comments
 (0)