Response: add decode_body() method#559
Merged
schlessera merged 12 commits intodevelopfrom Oct 11, 2021
Merged
Conversation
decode_body() method
b4d528a to
cfe76e8
Compare
* Add json() which returns decoded json from the response body if the response body is a valid json else throws an exception
* Use namespaced names. * Namespace test class and rename test file to match. * Use `expectException()` method instead of annotation.
... to be more descriptive.
... to be in-line with the parameter name used in PHP itself. Ref: https://www.php.net/json-decode
As of PHP 5.5.0, PHP contains the `json_last_error_msg()` function which will return the last error message. This removes the need for the error decoding array, which was outdated by now anyway due to new error codes having been introduced in PHP since the PR was originally pulled. Ref: https://www.php.net/manual/en/function.json-last-error-msg.php
... to be in-line with the documentation for the same parameters in the PHP native function. Ref: https://www.php.net/json-decode
* Use type safe `assertSame()` instead of `assertEquals()` and remove the unnecessary `foreach`. * Rework the "invalid JSON" test to a data provider and add some adidtional test cases. * Add `@covers` tags. * Add `@requires` tags for the JSON extension as while that extension has been bundled with PHP for a long time, it could still be disabled until PHP 8.0. * Add documentation.
cfe76e8 to
f454910
Compare
schlessera
approved these changes
Oct 11, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Recreation of PR #214 as updating that PR failed.
Props @ccrims0n
Add json() for json responses
if the response body is a valid json else throws an exception
Fix json_decode() for php 5.2 and 5.3
Fix json() for php5.4
Response::json(): revert changes for PHP 5.2 -5.4 compatibility
PHP 5.6 is the new minimum PHP version, so these accommodations for PHP 5.2 - 5.4 can be reverted again.
This reverts commit 8ea4334 and 2d2ecf3.
Response::json(): update to make code runnable again
expectException()method instead of annotation.Response::json(): update to comply with coding standards
Response::json(): rename the method
... to be more descriptive.
Response::decode_body(): rename parameter
... to be in-line with the parameter name used in PHP itself.
Ref: https://www.php.net/json-decode
Response::decode_body(): modernize the error handling
As of PHP 5.5.0, PHP contains the
json_last_error_msg()function which will return the last error message.This removes the need for the error decoding array, which was outdated by now anyway due to new error codes having been introduced in PHP since the PR was originally pulled.
Ref: https://www.php.net/manual/en/function.json-last-error-msg.php
Response::decode_body(): improve the method documentation
... to be in-line with the documentation for the same parameters in the PHP native function.
Ref: https://www.php.net/json-decode
Response::decode_body(): improve the tests
assertSame()instead ofassertEquals()and remove the unnecessaryforeach.@coverstags.@requirestags for the JSON extension as while that extension has been bundled with PHP for a long time, it could still be disabled until PHP 8.0.Composer: make the dependency on the JSON extension explicit
Fixes #167
Closes #214