Skip to content

Commit

Permalink
Complete withQueryIfMissing tests for advanced array handling
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mohammadrasoulasghari committed Mar 6, 2025
1 parent fb5d447 commit d04a8a0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/Support/SupportUriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,37 @@ public function test_with_query_if_missing()
]);

$this->assertEquals('name=Taylor&role[title]=Developer&role[focus]=PHP&tags[0]=person&tags[1]=employee', $uri->query()->decode());

// Test partial array merging and preserving indexed arrays
$uri = Uri::of('https://laravel.com?name=Taylor&tags[0]=person');

$uri = $uri->withQueryIfMissing([
'name' => 'Changed',
'age' => 38,
'tags' => ['should', 'not', 'change']
]);

$this->assertEquals('name=Taylor&tags[0]=person&age=38', $uri->query()->decode());
$this->assertEquals(['name' => 'Taylor', 'tags' => ['person'], 'age' => 38], $uri->query()->all());

$uri = Uri::of('https://laravel.com?user[name]=Taylor');

$uri = $uri->withQueryIfMissing([
'user' => [
'name' => 'Should Not Change',
'age' => 38
],
'settings' => [
'theme' => 'dark'
]
]);
$this->assertEquals([
'user' => [
'name' => 'Taylor',
],
'settings' => [
'theme' => 'dark'
]
], $uri->query()->all());
}
}

0 comments on commit d04a8a0

Please sign in to comment.