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

Is there a way to handle file uploads? #2

Open
miogalang opened this issue Jun 18, 2015 · 1 comment
Open

Is there a way to handle file uploads? #2

miogalang opened this issue Jun 18, 2015 · 1 comment

Comments

@miogalang
Copy link

Is there a way to handle file uploads when mocking requests? Uploading of attachment files? An example is pictures?

I try it with image uploads and I get errors.

PHP Fatal error:  Call to undefined method GuzzleHttp\Stream\Stream::getFields() in vendor/aeris/guzzle-http-mock/src/Helper/RequestChecker.php on line 104

Here is my mocking code

        $fileStream = Stream::factory(fopen(getcwd() . '/tests/assets/UK.png', 'r'));
        $this->httpMock->shouldReceiveRequest()
                       ->withMethod('POST')
                       ->withUrl($this->client->getApiUrl() . 'uploads.json')
                       ->withQueryParams(['filename' => 'UK test non-alpha chars.png'])
                       ->withBody($fileStream)

Any help or direction would be greatly appreciated?

@eschwartz
Copy link
Contributor

It doesn't look like file streams in the request body are supported right now.

GuzzleHttpMock works by creating a Request object using the mock expectations, then comparing it against an actual request. Take a look at the logic for comparing request bodies. If the request is made with an application/json content type, it runs a comparison of the json data. Otherwise, it just compares $body->getFields().

You should be able to add another check in there for file-upload requests. I'm not sure exactly how comparing file streams would work, but you could give it a shot.

There is a suite of PHPUnit integration tests in MockTest.php. They are pretty straight forward. You can try adding one for your file-upload use case, and see if you can get it to work :)

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

No branches or pull requests

2 participants