Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.x] Add test coverage for Uri::withQueryIfMissing method #54923

Conversation

mohammadrasoulasghari
Copy link
Contributor

Add test coverage for Uri::withQueryIfMissing method

This PR adds test coverage for the withQueryIfMissing method which previously had no tests. The test suite covers the following scenarios:

🔹 Adding new parameters while preserving existing ones with simple key-value pairs
🔹 Adding complex nested arrays to an empty query string with both associative and indexed arrays
🔹 Merging partial arrays while preserving existing values at the top level
🔹 Handling indexed arrays correctly by preserving them as complete entities
🔹 Adding missing nested properties in associative arrays while keeping existing ones intact
🔹 Verifying both the encoded query string format and the parsed array structure

🛡️These tests ensure that withQueryIfMissing correctly adds parameters only when they don't exist in the original URI, preserves all existing values regardless of the hierarchy level, and properly handles both simple and complex data structures in query parameters.🚀

This test verifies that the withQueryIfMissing method adds parameters only when they don't exist
while preserving the values of existing parameters.
This commit adds cases for complex nested arrays and indexed arrays to ensure
the method correctly handles multi-dimensional data structures in query parameters.
@mohammadrasoulasghari mohammadrasoulasghari force-pushed the feature/test-uri-with-query-if-missing branch from d04a8a0 to a536748 Compare March 6, 2025 17:36
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
@mohammadrasoulasghari mohammadrasoulasghari force-pushed the feature/test-uri-with-query-if-missing branch from a536748 to 15a4490 Compare March 6, 2025 17:37
@mohammadrasoulasghari mohammadrasoulasghari force-pushed the feature/test-uri-with-query-if-missing branch from d13ea28 to 218c5e6 Compare March 6, 2025 18:27
@mohammadrasoulasghari
Copy link
Contributor Author

mohammadrasoulasghari commented Mar 6, 2025

Also added complete PHPDoc annotation for the withQueryIfMissing method. 📝

@taylorotwell taylorotwell merged commit 8bed88d into laravel:12.x Mar 6, 2025
32 checks passed
@mohammadrasoulasghari mohammadrasoulasghari deleted the feature/test-uri-with-query-if-missing branch March 6, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants