Skip to content

Commit

Permalink
Merge pull request #342 from tienvx/multipart-static-files
Browse files Browse the repository at this point in the history
Multipart static files
  • Loading branch information
YOU54F authored Oct 12, 2023
2 parents 6243fc0 + 8ae7b1c commit adeec02
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 37 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@
"extra": {
"downloads": {
"pact-ffi-headers": {
"version": "0.4.8",
"version": "0.4.9",
"url": "https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v{$version}/pact.h",
"path": "bin/pact-ffi-headers/pact.h"
},
"pact-ffi-lib": {
"version": "0.4.8",
"version": "0.4.9",
"variables": {
"{$prefix}": "PHP_OS_FAMILY === 'Windows' ? 'pact_ffi' : 'libpact_ffi'",
"{$os}": "PHP_OS === 'Darwin' ? 'osx' : strtolower(PHP_OS_FAMILY)",
Expand Down
6 changes: 3 additions & 3 deletions example/binary/pacts/binaryConsumer-binaryProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.7",
"mockserver": "1.2.3",
"models": "1.1.9"
"ffi": "0.4.9",
"mockserver": "1.2.4",
"models": "1.1.11"
},
"pactSpecification": {
"version": "3.0.0"
Expand Down
6 changes: 3 additions & 3 deletions example/json/pacts/jsonConsumer-jsonProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.7",
"mockserver": "1.2.3",
"models": "1.1.9"
"ffi": "0.4.9",
"mockserver": "1.2.4",
"models": "1.1.11"
},
"pactSpecification": {
"version": "3.0.0"
Expand Down
4 changes: 2 additions & 2 deletions example/message/pacts/messageConsumer-messageProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.7",
"models": "1.1.9"
"ffi": "0.4.9",
"models": "1.1.11"
},
"pactSpecification": {
"version": "3.0.0"
Expand Down
7 changes: 0 additions & 7 deletions example/multipart/consumer/src/Service/HttpClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public function updateUserProfile(): string
'name' => 'full_name',
'contents' => 'Zoey Turcotte',
'filename' => 'full_name.txt',
'headers' => [
'Content-Type' => 'application/octet-stream',
],
],
[
'name' => 'profile_image',
Expand All @@ -40,10 +37,6 @@ public function updateUserProfile(): string
'name' => 'personal_note',
'contents' => 'testing',
'filename' => 'note.txt',
'headers' => [
'X-Foo' => 'this is a note',
'Content-Type' => 'application/octet-stream',
],
],
],
'headers' => [
Expand Down
21 changes: 2 additions & 19 deletions example/multipart/consumer/tests/Service/HttpClientServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function testUpdateUserProfile()
],
])
->setBody(new Multipart([
new Part($fullNameTempFile = $this->createTempFile($fullName), 'full_name', 'text/plain'),
new Part(__DIR__ . '/../_resource/full_name.txt', 'full_name', 'text/plain'),
new Part(__DIR__ . '/../_resource/image.jpg', 'profile_image', in_array(php_uname('m'), ['AMD64', 'arm64']) ? 'application/octet-stream' : 'image/jpeg'),
new Part($personalNoteTempFile = $this->createTempFile($personalNote), 'personal_note', 'text/plain'),
new Part(__DIR__ . '/../_resource/note.txt', 'personal_note', 'text/plain'),
]));

$response = new ProviderResponse();
Expand Down Expand Up @@ -68,28 +68,11 @@ public function testUpdateUserProfile()
$userProfileResponse = $service->updateUserProfile();
$verifyResult = $builder->verify();

unlink($fullNameTempFile);
unlink($personalNoteTempFile);

$this->assertTrue($verifyResult);
$this->assertEquals([
'full_name' => $fullName,
'profile_image' => $profileImageUrl,
'personal_note' => $personalNote,
], \json_decode($userProfileResponse, true, 512, JSON_THROW_ON_ERROR));
}

private function createTempFile(string $contents): string
{
$path = tempnam(sys_get_temp_dir(), 'pact');
//$newPath = "$path.txt";
//rename($path, $newPath);
$newPath = $path;

$handle = fopen($newPath, 'w');
fwrite($handle, $contents);
fclose($handle);

return $newPath;
}
}
1 change: 1 addition & 0 deletions example/multipart/consumer/tests/_resource/full_name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Colten Ziemann
1 change: 1 addition & 0 deletions example/multipart/consumer/tests/_resource/note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testing
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.8",
"ffi": "0.4.9",
"mockserver": "1.2.4",
"models": "1.1.11"
},
Expand Down

0 comments on commit adeec02

Please sign in to comment.