Skip to content

Commit a536748

Browse files
Complete withQueryIfMissing tests for advanced array handling
This commit finalizes tests for the withQueryIfMissing method, covering: - Partial merging of associative arrays - Preservation of indexed arrays - Verification of both encoded query strings and parsed arrays
1 parent fb5d447 commit a536748

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

tests/Support/SupportUriTest.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function test_with_query_if_missing()
134134

135135
$uri = $uri->withQueryIfMissing([
136136
'new' => 'parameter',
137-
'existing' => 'new_value'
137+
'existing' => 'new_value',
138138
]);
139139

140140
$this->assertEquals('existing=value&new=parameter', $uri->query()->decode());
@@ -151,9 +151,41 @@ public function test_with_query_if_missing()
151151
'tags' => [
152152
'person',
153153
'employee',
154-
]
154+
],
155155
]);
156156

157157
$this->assertEquals('name=Taylor&role[title]=Developer&role[focus]=PHP&tags[0]=person&tags[1]=employee', $uri->query()->decode());
158+
159+
// Test partial array merging and preserving indexed arrays
160+
$uri = Uri::of('https://laravel.com?name=Taylor&tags[0]=person');
161+
162+
$uri = $uri->withQueryIfMissing([
163+
'name' => 'Changed',
164+
'age' => 38,
165+
'tags' => ['should', 'not', 'change'],
166+
]);
167+
168+
$this->assertEquals('name=Taylor&tags[0]=person&age=38', $uri->query()->decode());
169+
$this->assertEquals(['name' => 'Taylor', 'tags' => ['person'], 'age' => 38], $uri->query()->all());
170+
171+
$uri = Uri::of('https://laravel.com?user[name]=Taylor');
172+
173+
$uri = $uri->withQueryIfMissing([
174+
'user' => [
175+
'name' => 'Should Not Change',
176+
'age' => 38,
177+
],
178+
'settings' => [
179+
'theme' => 'dark'
180+
],
181+
]);
182+
$this->assertEquals([
183+
'user' => [
184+
'name' => 'Taylor',
185+
],
186+
'settings' => [
187+
'theme' => 'dark'
188+
],
189+
], $uri->query()->all());
158190
}
159191
}

0 commit comments

Comments
 (0)