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

[PHP] Allows passing filename to deserialize #11582

Merged
merged 2 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace {{invokerPackage}};

use {{modelPackage}}\ModelInterface;
use GuzzleHttp\Psr7\Utils;

/**
* ObjectSerializer Class Doc Comment
Expand Down Expand Up @@ -337,6 +338,8 @@ class ObjectSerializer
}

if ($class === '\SplFileObject') {
$data = Utils::streamFor($data);

/** @var \Psr\Http\Message\StreamInterface $data */

// determine file name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
namespace OpenAPI\Client;

use OpenAPI\Client\Model\ModelInterface;
use GuzzleHttp\Psr7\Utils;

/**
* ObjectSerializer Class Doc Comment
Expand Down Expand Up @@ -346,6 +347,8 @@ public static function deserialize($data, $class, $httpHeaders = null)
}

if ($class === '\SplFileObject') {
$data = Utils::streamFor($data);

/** @var \Psr\Http\Message\StreamInterface $data */

// determine file name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use GuzzleHttp\Psr7\Utils;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\StreamInterface;

// test object serializer
class ObjectSerializerTest extends TestCase
Expand Down Expand Up @@ -34,7 +33,7 @@ public function testSanitizeFilename()
* @covers ObjectSerializer::serialize
* @dataProvider provideFileStreams
*/
public function testDeserializeFile(StreamInterface $stream, ?array $httpHeaders = null, ?string $expectedFilename = null): void
public function testDeserializeFile($stream, ?array $httpHeaders = null, ?string $expectedFilename = null): void
{
$s = new ObjectSerializer();

Expand Down Expand Up @@ -62,6 +61,11 @@ public function provideFileStreams()
['Content-Disposition' => 'inline; filename=\'foobar.php\''],
'foobar.php',
],
'File path' => [
__FILE__,
null,
null,
],
];
}

Expand Down