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

Merged
merged 1 commit into from Jun 21, 2016

Conversation

Projects
None yet
4 participants
@Naktibalda
Member

Naktibalda commented Jun 19, 2016

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

src/Codeception/Module/REST.php
+
+ private function getFileType($file)
+ {
+ if (function_exists('mime_content_type') && mime_content_type($file) ) {

This comment has been minimized.

@Nitpick-CI

Nitpick-CI Jun 19, 2016

Expected 0 spaces before closing bracket; 1 found

@Nitpick-CI

Nitpick-CI Jun 19, 2016

Expected 0 spaces before closing bracket; 1 found

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Jun 21, 2016

Member

Thank you!

Member

DavertMik commented Jun 21, 2016

Thank you!

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

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
semaphoreci The build passed on Semaphore.
Details
@VincentClair

This comment has been minimized.

Show comment
Hide comment
@VincentClair

VincentClair Jun 30, 2016

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 ?

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

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jun 30, 2016

Member

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

Could you raise it as an issue?

Member

Naktibalda commented Jun 30, 2016

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

Could you raise it as an issue?

@VincentClair

This comment has been minimized.

Show comment
Hide comment

Here it is #3298 :)

@Naktibalda Naktibalda deleted the Naktibalda:2.2-rest-simple-file-upload branch Dec 31, 2016

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