Skip to content

[REST] Support simple key-value format for file uploads - #3244

Merged
DavertMik merged 1 commit into
Codeception:2.2from
Naktibalda:2.2-rest-simple-file-upload
Jun 21, 2016
Merged

DavertMik merged 1 commit into
Codeception:2.2from
Naktibalda:2.2-rest-simple-file-upload

Conversation

@Naktibalda

Copy link
Copy Markdown
Member

When REST module was used with PhpBrowser(or more specifically with Guzzle), file upload could be done in 2 formats: https://github.com/Codeception/Codeception/blob/2.2.1/tests/unit/Codeception/Module/PhpBrowserRestTest.php#L205

        $files = [
            'file' => [
                'name' => 'file.txt',
                'type' => 'text/plain',
                'size' => 9,
                'tmp_name' => $tmpFileName,
            ]
        ];

and

        $files = [
            'file' => $tmpFileName,
        ];

The magic happened in in the Guzzle (if I remember correctly).
When REST module was used with framework modules, the user had to provide a complete $_FILES array (the first type).

I added support for the second type of file upload for all frameworks, but I only tested it with ZF2,
I will test it with ZF1 and Zend-Expressive tomorrow.
Naktibalda/codeception-rest-testcase@024d387

Comment thread src/Codeception/Module/REST.php Outdated

private function getFileType($file)
{
if (function_exists('mime_content_type') && mime_content_type($file) ) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 0 spaces before closing bracket; 1 found

@Naktibalda
Naktibalda force-pushed the 2.2-rest-simple-file-upload branch from 56215b0 to f1e494b Compare June 20, 2016 20:34
@DavertMik

Copy link
Copy Markdown
Member

Thank you!

@DavertMik
DavertMik merged commit e433c03 into Codeception:2.2 Jun 21, 2016
@VincentClair

Copy link
Copy Markdown

Before, with version 2.1.8, we could pass a Symfony\Component\HttpFoundation\File\UploadedFile as value. Something like:

$I->sendPOST('/ui/options/images',
    ['name'  => 'logo'],
    ['image' => new UploadedFile($filePath, $filename, $mimeType, filesize($filePath))]
);

Since version 2.2.2, it seems to be broken. I get an error that the value of key image is invalid.
I changed to the indexed array and it works.
Is it normal ?

@Naktibalda

Copy link
Copy Markdown
Member Author

@VincentClair Thanks for report, I will change the code to allow objects.

Could you raise it as an issue?

@VincentClair

Copy link
Copy Markdown

Here it is #3298 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants