From 5ddd640c76e0ce8c6efe72d77181c23cf81c590f Mon Sep 17 00:00:00 2001 From: Chris Lloyd Date: Thu, 18 Jan 2024 11:49:48 +0000 Subject: [PATCH] WIP --- src/PathSegment/Batch/JSON.php | 2 +- src/Transaction/MultipartDocument.php | 2 +- tests/Protocol/BatchJSONTest.php | 18 ++++++++++++++ tests/Protocol/BatchMultipartTest.php | 21 ++++++++++++++++ .../BatchJSONTest__test_query_param__1.json | 24 +++++++++++++++++++ .../BatchJSONTest__test_query_param__2.json | 14 +++++++++++ ...atchMultipartTest__test_query_param__1.txt | 9 +++++++ ...tchMultipartTest__test_query_param__2.json | 14 +++++++++++ 8 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 tests/__snapshots__/Protocol/BatchJSONTest__test_query_param__1.json create mode 100644 tests/__snapshots__/Protocol/BatchJSONTest__test_query_param__2.json create mode 100644 tests/__snapshots__/Protocol/BatchMultipartTest__test_query_param__1.txt create mode 100644 tests/__snapshots__/Protocol/BatchMultipartTest__test_query_param__2.json diff --git a/src/PathSegment/Batch/JSON.php b/src/PathSegment/Batch/JSON.php index 6b1cadc87..2cd53ed6c 100644 --- a/src/PathSegment/Batch/JSON.php +++ b/src/PathSegment/Batch/JSON.php @@ -71,7 +71,7 @@ public function emitJson(Transaction $transaction): void $uri = Url::http_build_url( ServiceProvider::endpoint(), $requestURI, - Url::HTTP_URL_JOIN_PATH + Url::HTTP_URL_JOIN_PATH | Url::HTTP_URL_JOIN_QUERY ); break; } diff --git a/src/Transaction/MultipartDocument.php b/src/Transaction/MultipartDocument.php index bf1009d92..9c03fe4f7 100644 --- a/src/Transaction/MultipartDocument.php +++ b/src/Transaction/MultipartDocument.php @@ -162,7 +162,7 @@ public function toRequest(): Request $uri = Url::http_build_url( ServiceProvider::endpoint(), $requestURI, - Url::HTTP_URL_JOIN_PATH + Url::HTTP_URL_JOIN_PATH | Url::HTTP_URL_JOIN_QUERY ); break; } diff --git a/tests/Protocol/BatchJSONTest.php b/tests/Protocol/BatchJSONTest.php index fcdb86cd9..278cf5edf 100644 --- a/tests/Protocol/BatchJSONTest.php +++ b/tests/Protocol/BatchJSONTest.php @@ -60,6 +60,24 @@ public function test_full_url() ); } + public function test_query_param() + { + $this->assertJsonMetadataResponse( + (new Request) + ->path('/$batch') + ->post() + ->body([ + 'requests' => [ + [ + 'id' => 0, + 'method' => 'get', + 'url' => 'http://localhost/odata/flights?$top=1', + ] + ] + ]) + ); + } + public function test_any_response_type() { $this->assertJsonMetadataResponse( diff --git a/tests/Protocol/BatchMultipartTest.php b/tests/Protocol/BatchMultipartTest.php index 4a1add07e..0dd440aa2 100644 --- a/tests/Protocol/BatchMultipartTest.php +++ b/tests/Protocol/BatchMultipartTest.php @@ -102,6 +102,27 @@ public function test_full_url() ); } + public function test_query_param() + { + $this->assertTextMetadataResponse( + (new Request) + ->path('/$batch') + ->header('content-type', 'multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77c') + ->post() + ->multipart(<<assertTextMetadataResponse( diff --git a/tests/__snapshots__/Protocol/BatchJSONTest__test_query_param__1.json b/tests/__snapshots__/Protocol/BatchJSONTest__test_query_param__1.json new file mode 100644 index 000000000..515d8911a --- /dev/null +++ b/tests/__snapshots__/Protocol/BatchJSONTest__test_query_param__1.json @@ -0,0 +1,24 @@ +{ + "responses": [ + { + "id": 0, + "status": 200, + "headers": { + "content-type": "application/json;metadata=minimal" + }, + "body": { + "@context": "http://localhost/odata/$metadata#flights", + "value": [ + { + "id": 1, + "origin": "lhr", + "destination": "lax", + "gate": null, + "duration": "PT11H25M0S" + } + ], + "@nextLink": "http://localhost/odata/flights?top=1&skip=1" + } + } + ] +} diff --git a/tests/__snapshots__/Protocol/BatchJSONTest__test_query_param__2.json b/tests/__snapshots__/Protocol/BatchJSONTest__test_query_param__2.json new file mode 100644 index 000000000..eca223c46 --- /dev/null +++ b/tests/__snapshots__/Protocol/BatchJSONTest__test_query_param__2.json @@ -0,0 +1,14 @@ +{ + "headers": { + "cache-control": [ + "no-cache, private" + ], + "content-type": [ + "application/json" + ], + "odata-version": [ + "4.01" + ] + }, + "status": 200 +} diff --git a/tests/__snapshots__/Protocol/BatchMultipartTest__test_query_param__1.txt b/tests/__snapshots__/Protocol/BatchMultipartTest__test_query_param__1.txt new file mode 100644 index 000000000..fb1f085fb --- /dev/null +++ b/tests/__snapshots__/Protocol/BatchMultipartTest__test_query_param__1.txt @@ -0,0 +1,9 @@ + +--00000000-0000-0000-0000-000000000002 +content-type: application/http + +HTTP/1.0 200 OK +content-type: application/json;metadata=minimal + +{"@context":"http://localhost/odata/$metadata#flights","value":[{"id":1,"origin":"lhr","destination":"lax","gate":null,"duration":"PT11H25M0S"}],"@nextLink":"http://localhost/odata/flights?top=1&skip=1"} +--00000000-0000-0000-0000-000000000002-- diff --git a/tests/__snapshots__/Protocol/BatchMultipartTest__test_query_param__2.json b/tests/__snapshots__/Protocol/BatchMultipartTest__test_query_param__2.json new file mode 100644 index 000000000..020300581 --- /dev/null +++ b/tests/__snapshots__/Protocol/BatchMultipartTest__test_query_param__2.json @@ -0,0 +1,14 @@ +{ + "headers": { + "cache-control": [ + "no-cache, private" + ], + "content-type": [ + "multipart/mixed;boundary=00000000-0000-0000-0000-000000000002" + ], + "odata-version": [ + "4.01" + ] + }, + "status": 200 +}