Skip to content

Commit

Permalink
include HyperPlug query param add/replace fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Vaughn committed Dec 20, 2020
1 parent 2582142 commit 92a1239
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 47 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
},
"require": {
"php": "^7.2.0",
"modethirteen/hyperplug": "^1.1.0",
"modethirteen/xarray": "^1.1.0",
"modethirteen/hyperplug": "^1.1.2",
"modethirteen/type-ex": "^1.0.0",
"modethirteen/xarray": "^1.2.2",
"ext-fileinfo": "*",
"ext-json": "*",
"ext-curl": "*"
},
"require-dev": {
"phpstan/phpstan": "~0.12",
"phpstan/phpstan": "~0.12.0",
"phpunit/phpunit": "~7.4.3"
},
"autoload": {
Expand Down
7 changes: 4 additions & 3 deletions src/ApiPlug.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
use modethirteen\Http\Result;
use modethirteen\Http\IMutableHeaders;
use modethirteen\Http\Parser\SerializedPhpArrayParser;
use modethirteen\Http\StringUtil;
use modethirteen\Http\XUri;
use modethirteen\TypeEx\StringEx;

/**
* Class ApiPlug - builder and invocation for MindTouch API requests
Expand Down Expand Up @@ -110,11 +110,12 @@ public function at(...$segments) : object {
$plug = clone $this;
$path = $plug->uri->getPath();
foreach($segments as $segment) {
$segment = StringUtil::stringify($segment);
$segment = StringEx::stringify($segment);
if(!in_array($segment, self::$rawUriPathSegments)) {
$string = new StringEx($segment);

// auto-double encode, check for '=' or ':' sign
$segment = StringUtil::startsWith($segment, '=') || StringUtil::startsWith($segment, ':')
$segment = $string->startsWith('=') || $string->startsWith(':')
? substr($segment, 0, 1) . self::urlEncode(substr($segment, 1), true)
: self::urlEncode($segment, true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ApiResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace MindTouch\Http;

use modethirteen\Http\Result;
use modethirteen\Http\StringUtil;
use modethirteen\TypeEx\StringEx;

/**
* Class ApiResult - wraps http result with MindTouch API specific accessors
Expand Down Expand Up @@ -49,7 +49,7 @@ public function getError() : ?string {

// curl error
$error = $this->getCurlError();
if(!StringUtil::isNullOrEmpty($error)) {
if(!StringEx::isNullOrEmpty($error)) {
return $error;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ApiPlug/atRaw_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class atRaw_Test extends MindTouchHttpUnitTestCase {
/**
* @test
*/
public function Can_add_non_urlencoded_segments() {
public function Can_add_non_urlencoded_segments() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com'));
Expand Down
34 changes: 17 additions & 17 deletions tests/ApiPlug/at_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class at_Test extends MindTouchHttpUnitTestCase {
/**
* @test
*/
public function Can_add_single_path_segment_to_hostname() {
public function Can_add_single_path_segment_to_hostname() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com'));
Expand All @@ -42,16 +42,16 @@ public function Can_add_single_path_segment_to_hostname() {
/**
* @test
*/
public function Can_add_multiple_path_segments_to_hostname_1() {
public function Can_add_multiple_path_segments_to_hostname_1() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com'));
$object = new class {
public function __toString() {
public function __toString() : string {
return 'xyz';
}
};
$func = function() {
$func = function() : string {
return 'asdf';
};

Expand All @@ -65,7 +65,7 @@ public function __toString() {
/**
* @test
*/
public function Can_add_multiple_path_segments_to_hostname_2() {
public function Can_add_multiple_path_segments_to_hostname_2() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com'));
Expand All @@ -80,7 +80,7 @@ public function Can_add_multiple_path_segments_to_hostname_2() {
/**
* @test
*/
public function Can_add_single_path_segment_to_existing_path() {
public function Can_add_single_path_segment_to_existing_path() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com/qux'));
Expand All @@ -95,7 +95,7 @@ public function Can_add_single_path_segment_to_existing_path() {
/**
* @test
*/
public function Can_add_multiple_path_segments_to_existing_path_1() {
public function Can_add_multiple_path_segments_to_existing_path_1() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com/qux'));
Expand All @@ -110,7 +110,7 @@ public function Can_add_multiple_path_segments_to_existing_path_1() {
/**
* @test
*/
public function Can_add_multiple_path_segments_to_existing_path_2() {
public function Can_add_multiple_path_segments_to_existing_path_2() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com/qux'));
Expand All @@ -127,7 +127,7 @@ public function Can_add_multiple_path_segments_to_existing_path_2() {
/**
* @test
*/
public function Can_add_single_path_segment_to_existing_path_query() {
public function Can_add_single_path_segment_to_existing_path_query() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com/qux?a=b&c=d'));
Expand All @@ -142,7 +142,7 @@ public function Can_add_single_path_segment_to_existing_path_query() {
/**
* @test
*/
public function Can_add_multiple_path_segments_to_existing_path_query_1() {
public function Can_add_multiple_path_segments_to_existing_path_query_1() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com/qux?a=b&c=d'));
Expand All @@ -157,7 +157,7 @@ public function Can_add_multiple_path_segments_to_existing_path_query_1() {
/**
* @test
*/
public function Can_add_multiple_path_segments_to_existing_path_query_2() {
public function Can_add_multiple_path_segments_to_existing_path_query_2() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com/qux?a=b&c=d'));
Expand All @@ -172,7 +172,7 @@ public function Can_add_multiple_path_segments_to_existing_path_query_2() {
/**
* @test
*/
public function Can_add_single_path_segment_to_existing_query() {
public function Can_add_single_path_segment_to_existing_query() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com?a=b&c=d'));
Expand All @@ -187,7 +187,7 @@ public function Can_add_single_path_segment_to_existing_query() {
/**
* @test
*/
public function Can_add_multiple_path_segments_to_existing_query_1() {
public function Can_add_multiple_path_segments_to_existing_query_1() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com?a=b&c=d'));
Expand All @@ -202,7 +202,7 @@ public function Can_add_multiple_path_segments_to_existing_query_1() {
/**
* @test
*/
public function Can_add_multiple_path_segments_to_existing_query_2() {
public function Can_add_multiple_path_segments_to_existing_query_2() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com?a=b&c=d'));
Expand All @@ -217,7 +217,7 @@ public function Can_add_multiple_path_segments_to_existing_query_2() {
/**
* @test
*/
public function Can_add_double_urlencoded_segments() {
public function Can_add_double_urlencoded_segments() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com/@api/deki?strict=true'));
Expand All @@ -232,7 +232,7 @@ public function Can_add_double_urlencoded_segments() {
/**
* @test
*/
public function Can_add_non_urlencoded_segments() {
public function Can_add_non_urlencoded_segments() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com/@api/deki?strict=true'));
Expand All @@ -247,7 +247,7 @@ public function Can_add_non_urlencoded_segments() {
/**
* @test
*/
public function Can_add_guid_segment() {
public function Can_add_guid_segment() : void {

// arrange
$plug = new ApiPlug(XUri::tryParse('http://foo.com/@api/deki?strict=true'));
Expand Down
2 changes: 1 addition & 1 deletion tests/ApiPlug/get_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class get_Test extends MindTouchHttpUnitTestCase {
/**
* @test
*/
public function Can_invoke_get() {
public function Can_invoke_get() : void {

// arrange
$uri = XUri::tryParse('test://example.com/@api/deki/pages/=foo');
Expand Down
6 changes: 3 additions & 3 deletions tests/ApiPlug/put_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class put_Test extends MindTouchHttpUnitTestCase {
/**
* @test
*/
public function Can_invoke_put() {
public function Can_invoke_put() : void {

// arrange
$uri = XUri::tryParse('test://example.com/@api/deki/pages/=foo/tags');
Expand Down Expand Up @@ -61,7 +61,7 @@ public function Can_invoke_put() {
/**
* @test
*/
public function Can_invoke_put_with_text_content() {
public function Can_invoke_put_with_text_content() : void {

// arrange
$uri = XUri::tryParse('test://example.com/@api/deki/pages/=foo/tags');
Expand Down Expand Up @@ -91,7 +91,7 @@ public function Can_invoke_put_with_text_content() {
/**
* @test
*/
public function Can_invoke_put_with_form_data_content() {
public function Can_invoke_put_with_form_data_content() : void {

// arrange
$uri = XUri::tryParse('test://example.com/@api/deki/pages/=foo/tags');
Expand Down
4 changes: 2 additions & 2 deletions tests/ApiPlug/urlEncode_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class urlEncode_Test extends MindTouchHttpUnitTestCase {
* @see ApiPlug::urlEncode()
* @test
*/
public function Can_url_encode_with_special_trailing_dot_handling() {
public function Can_url_encode_with_special_trailing_dot_handling() : void {

// act
$result = ApiPlug::urlEncode('abc/123/765?!/.');
Expand All @@ -39,7 +39,7 @@ public function Can_url_encode_with_special_trailing_dot_handling() {
/**
* @test
*/
public function Can_double_url_encode() {
public function Can_double_url_encode() : void {

// act
$result = ApiPlug::urlEncode('abc/123/765?!/.', true);
Expand Down
2 changes: 1 addition & 1 deletion tests/ApiPlug/withApiToken_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class withApiToken_Test extends MindTouchHttpUnitTestCase {
/**
* @test
*/
public function Can_invoke_with_api_token() {
public function Can_invoke_with_api_token() : void {

// arrange
$uri = XUri::tryParse('test://example.com/@api/deki/pages/=foo');
Expand Down
6 changes: 3 additions & 3 deletions tests/ApiPlug/withResultErrorHandler_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class withResultErrorHandler_Test extends MindTouchHttpUnitTestCase {
/**
* @test
*/
public function Can_invoke_with_result_error_handler_exception_supression() {
public function Can_invoke_with_result_error_handler_exception_supression() : void {

// arrange
$uri = XUri::tryParse('test://example.com/@api/deki/pages/=foo');
Expand Down Expand Up @@ -70,7 +70,7 @@ public function Can_invoke_with_result_error_handler_exception_supression() {
/**
* @test
*/
public function Result_error_handler_can_handle_parser_error() {
public function Result_error_handler_can_handle_parser_error() : void {

// arrange
$uri = XUri::tryParse('test://example.com/@api/deki/pages/=foo');
Expand Down Expand Up @@ -104,7 +104,7 @@ public function Result_error_handler_can_handle_parser_error() {
/**
* @test
*/
public function Result_error_handler_can_handle_content_length_parser_error() {
public function Result_error_handler_can_handle_content_length_parser_error() : void {

// arrange
$uri = XUri::tryParse('test://example.com/@api/deki/pages/=foo');
Expand Down
4 changes: 2 additions & 2 deletions tests/ApiPlug/withoutResultErrorHandler_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class withoutResultErrorHandler_Test extends MindTouchHttpUnitTestCase {
/**
* @test
*/
public function Can_remove_result_error_handler_exception_supression_before_invocation() {
public function Can_remove_result_error_handler_exception_supression_before_invocation() : void {

// arrange
$uri = XUri::tryParse('test://example.com/@api/deki/pages/=foo');
Expand All @@ -54,7 +54,7 @@ public function Can_remove_result_error_handler_exception_supression_before_invo
// act
$exceptionThrown = false;
try {
$plug->withResultErrorHandler(function () {
$plug->withResultErrorHandler(function () : bool {
return true;
})->withoutResultErrorHandler()->get();

Expand Down
4 changes: 2 additions & 2 deletions tests/ApiResult/getError_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function Can_get_error_from_body($body, string $expected) {
/**
* @test
*/
public function Can_get_curl_error() {
public function Can_get_curl_error() : void {

// arrange
$data = [
Expand All @@ -82,7 +82,7 @@ public function Can_get_curl_error() {
/**
* @test
*/
public function Will_get_null_if_no_error() {
public function Will_get_null_if_no_error() : void {

// arrange
$result = new ApiResult([]);
Expand Down
4 changes: 2 additions & 2 deletions tests/ApiResult/getException_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class getException_Test extends MindTouchHttpUnitTestCase {
/**
* @test
*/
public function Can_get_exception_type() {
public function Can_get_exception_type() : void {

// arrange
$data = [
Expand All @@ -50,7 +50,7 @@ public function Can_get_exception_type() {
/**
* @test
*/
public function Will_get_null_if_no_exception_type() {
public function Will_get_null_if_no_exception_type() : void {

// arrange
$data = [
Expand Down
4 changes: 2 additions & 2 deletions tests/ApiToken/toSignature_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class toSignature_Test extends MindTouchHttpUnitTestCase {
/**
* @test
*/
public function Can_convert_to_signature() {
public function Can_convert_to_signature() : void {

// arrange
$token = new ApiToken('foo', 'bar');
Expand All @@ -41,7 +41,7 @@ public function Can_convert_to_signature() {
/**
* @test
*/
public function Can_convert_to_signature_by_timestamp() {
public function Can_convert_to_signature_by_timestamp() : void {

// arrange
$token = new ApiToken('foo', 'bar');
Expand Down
2 changes: 1 addition & 1 deletion tests/ApiToken/withUserId_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class withUserId_Test extends MindTouchHttpUnitTestCase {
/**
* @test
*/
public function Can_update_user() {
public function Can_update_user() : void {

// arrange
$token = new ApiToken('foo', 'bar');
Expand Down
2 changes: 1 addition & 1 deletion tests/ApiToken/withUsername_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class withUsername_Test extends MindTouchHttpUnitTestCase {
/**
* @test
*/
public function Can_update_user() {
public function Can_update_user() : void {

// arrange
$token = new ApiToken('foo', 'bar');
Expand Down
Loading

0 comments on commit 92a1239

Please sign in to comment.