I am trying to write a unit test for a multipart PUT using Symfony2 and phpUnit. I am not quite sure the best way to handle this, and I am not able to find any documentation on the topic.
Here is what I have to start, but I am not sure how to make the next step to a multipart.
$client = static::createClient();
//test put method for new file
$xml = new UploadedFile(
dirname ( __FILE__ ).'/testfile.xml',
'testfile.xml',
'application/xml'
);
$crawler = $client->request('PUT', '/file.xml',array(),
array('xml'=>$xml),
array(
'CONTENT_TYPE' => 'application/xml'
));
EDIT
Ultimately I would like my put to look like this
PUT /v1/files HTTP/1.1
host: files.bimfs.com
date: 2009-07-07T12:49:08-06:00
Content-MD5: 5a1d2ffa5b1fd1d11d694428a6f4b808
Authorization: f9ea57af8da1b02ff8fa6e99736ed3c6cbb95c1b:YTc4NDcyZjI1ZTFjN2E3MzAxODIwZGNlZGNlMTczODQyYjIwODVhMzI4ZDhjZTY4MmY4NmYyZGJjZTUyZjBiNg==
Content-Type: multipart/formdata; boundary=c7ecb1abb999a3de5ab26c49b5ac7f87
--c7ecb1abb999a3de5ab26c49b5ac7f87
Content-Type: application/xml
<?xml version="1.0" encoding="UTF-8"?>
<file>
<name>foo.gif</name>
<dead_date></dead_date>
</file>
--c7ecb1abb999a3de5ab26c49b5ac7f87
Content-Disposition: file; filename=blank.gif
Content-Type: image/gif
Content-Transfer-Encoding: binary
{file binary}
--c7ecb1abb999a3de5ab26c49b5ac7f87--
Thanks,
CG
By default
createClient()returns aSymfony\Component\HttpKernel\Client. As far as I know it does not support building a multipart message on it’s own, but you could add the header on your own and create the request body on your own.As you already have outlined in your question you’re aware which additional header is needed and how the request body has to be build.