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

File type empty in SendPOST #5548

Closed
noloop opened this issue Jun 12, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@noloop
Copy link

commented Jun 12, 2019

I'm tried send file to my php server with codeception, using REST, so I try:

    $I->sendPOST('/uploads/upload-file', 
                 ['idFile' => $idFile],
                 ['file' => [
                    'name' => 'sample_file.odt',
                    'type' => 'application/vnd.oasis.opendocument.text',
                    'error' => UPLOAD_ERR_OK,
                    'size' => filesize(codecept_data_dir('sample_file.odt')),
                    'tmp_name' => codecept_data_dir('sample_file.odt')]]);

The file arrives in $ _FILES, however there is a problem, the "type" property is empty, and from what I checked in the codeception code:

https://github.com/Codeception/Codeception/blob/3.0/src/Codeception/Module/REST.php#L727

Even though I pass a value to "type" it is calling the function getFileType that uses the mime_content_type function, it may not be working well with .odt files.

What are you trying to achieve?

echo $_FILES['file']['type']; // => 'application/vnd.oasis.opendocument.text'

What do you get instead?

echo $_FILES['file']['type']; // => ''

Details

  • Codeception version: 3.0.1
  • PHP Version: 7.3.3
  • Operating System: Linux
  • Installation type: Composer
  • List of installed packages (composer show):
behat/gherkin                      v4.6.0     Gherkin DSL parser for PHP 5.3
codeception/codeception            3.0.1      BDD-style testing framework
codeception/phpunit-wrapper        8.0.4      PHPUnit classes used by Codeception
codeception/stub                   2.1.0      Flexible Stub wrapper for PHPUnit's Mock Builder
doctrine/instantiator              1.2.0      A small, lightweight utility to instantiate objects in ...
facebook/webdriver                 1.6.0      A PHP client for Selenium WebDriver
flow/jsonpath                      0.4.0      JSONPath implementation for parsing, searching and flat...
gargron/fileupload                 v1.5.1     File uploading library capable of handling large/chunke...
guzzlehttp/guzzle                  6.3.3      Guzzle is a PHP HTTP client library
guzzlehttp/promises                v1.3.1     Guzzle promises library
guzzlehttp/psr7                    1.5.2      PSR-7 message implementation that also provides common ...
hoa/consistency                    1.17.05.02 The Hoa\Consistency library.
hoa/console                        3.17.05.02 The Hoa\Console library.
hoa/event                          1.17.01.13 The Hoa\Event library.
hoa/exception                      1.17.01.16 The Hoa\Exception library.
hoa/file                           1.17.07.11 The Hoa\File library.
hoa/iterator                       2.17.01.10 The Hoa\Iterator library.
hoa/protocol                       1.17.01.14 The Hoa\Protocol library.
hoa/stream                         1.17.02.21 The Hoa\Stream library.
hoa/ustring                        4.17.01.16 The Hoa\Ustring library.
izniburak/pdox                     v1.3.5     Useful Query Builder, PDO Class for PHP. A simple acces...
lindelius/php-jwt                  0.8.1      Convenience library for working with JSON Web Tokens (J...
myclabs/deep-copy                  1.9.1      Create deep copies (clones) of your objects
nezamy/route                       v1.2.5     Route - Fast, flexible routing for PHP, enabling you to...
nezamy/support                     v1.0.1     Support
phar-io/manifest                   1.0.3      Component for reading phar.io manifest information from...
phar-io/version                    2.0.1      Library for handling version information and constraints
phpdocumentor/reflection-common    1.0.1      Common reflection classes used by phpdocumentor to refl...
phpdocumentor/reflection-docblock  4.3.1      With this component, a library can provide support for ...
phpdocumentor/type-resolver        0.4.0     
phpmailer/phpmailer                v6.0.7     PHPMailer is a full-featured email creation and transfe...
phpspec/prophecy                   1.8.0      Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage          7.0.4      Library that provides collection, processing, and rende...
phpunit/php-file-iterator          2.0.2      FilterIterator implementation that filters files based ...
phpunit/php-text-template          1.2.1      Simple template engine.
phpunit/php-timer                  2.1.1      Utility class for timing
phpunit/php-token-stream           3.0.1      Wrapper around PHP's tokenizer extension.
phpunit/phpunit                    8.1.6      The PHP Unit Testing framework.
psr/http-message                   1.0.1      Common interface for HTTP messages
ralouphie/getallheaders            2.0.5      A polyfill for getallheaders.
sebastian/code-unit-reverse-lookup 1.0.1      Looks up which function or method a line of code belong...
sebastian/comparator               3.0.2      Provides the functionality to compare PHP values for eq...
sebastian/diff                     3.0.2      Diff implementation
sebastian/environment              4.2.2      Provides functionality to handle HHVM/PHP environments
sebastian/exporter                 3.1.0      Provides the functionality to export PHP variables for ...
sebastian/global-state             3.0.0      Snapshotting of global state
sebastian/object-enumerator        3.0.3      Traverses array structures and object graphs to enumera...
sebastian/object-reflector         1.1.1      Allows reflection of object attributes, including inher...
sebastian/recursion-context        3.0.0      Provides functionality to recursively process PHP varia...
sebastian/resource-operations      2.0.1      Provides a list of PHP built-in functions that operate ...
sebastian/version                  2.0.1      Library that helps with managing the version number of ...
symfony/browser-kit                v4.3.0     Symfony BrowserKit Component
symfony/console                    v4.3.0     Symfony Console Component
symfony/css-selector               v4.3.0     Symfony CssSelector Component
symfony/dom-crawler                v4.3.0     Symfony DomCrawler Component
symfony/event-dispatcher           v4.3.0     Symfony EventDispatcher Component
symfony/event-dispatcher-contracts v1.1.1     Generic abstractions related to dispatching event
symfony/finder                     v4.3.0     Symfony Finder Component
symfony/polyfill-ctype             v1.11.0    Symfony polyfill for ctype functions
symfony/polyfill-mbstring          v1.11.0    Symfony polyfill for the Mbstring extension
symfony/polyfill-php73             v1.11.0    Symfony polyfill backporting some PHP 7.3+ features to ...
symfony/process                    v4.3.0     Symfony Process Component
symfony/service-contracts          v1.1.2     Generic abstractions related to writing services
symfony/yaml                       v4.3.0     Symfony Yaml Component
theseer/tokenizer                  1.1.2      A small library for converting tokenized PHP source cod...
webmozart/assert
  • Suite configuration(api.suite.yml):
actor: ApiTester
modules:
    enabled:
        - REST:
            url: http://localhost:3000/my-server/api
            depends: PhpBrowser
            part: Json
        - Helper\Api
        - Asserts
@Naktibalda

This comment has been minimized.

Copy link
Member

commented Jun 12, 2019

Guzzle connector used by PhpBrowser ignores type field of file array: https://github.com/Codeception/Codeception/blob/3.0.1/src/Codeception/Lib/Connector/Guzzle.php#L300

@noloop

This comment has been minimized.

Copy link
Author

commented Jun 12, 2019

@Naktibalda I had not seen, why?

Naktibalda added a commit that referenced this issue Jun 13, 2019

@Naktibalda

This comment has been minimized.

Copy link
Member

commented Jun 13, 2019

Please test this patch by setting Codeception version constaint to "dev-fix-phpbrowser-filetype" in composer.json of your project, running composer update and then running your test.

@noloop

This comment has been minimized.

Copy link
Author

commented Jun 13, 2019

ok.

@noloop noloop closed this Jun 13, 2019

@Naktibalda

This comment has been minimized.

Copy link
Member

commented Jun 14, 2019

@noloop does it make your file upload work correctly?

Naktibalda added a commit that referenced this issue Jun 19, 2019

[PhpBrowser] Pass file type option to Guzzle if specified (#5550)
* [PhpBrowser] Pass file type option to Guzzle if specified

Fixes #5548

* Fix syntax error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.