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

Fake file creation fails #30641

Closed
vroomfondle opened this issue Nov 21, 2019 · 5 comments
Closed

Fake file creation fails #30641

vroomfondle opened this issue Nov 21, 2019 · 5 comments
Labels

Comments

@vroomfondle
Copy link
Contributor

  • Laravel Version: 6.5.2
  • PHP Version: 7.3
  • Database Driver & Version:
    n/a

Description:

In our tests we create a fake file:

        use Illuminate\Http\UploadedFile;
        $uploadedFile = UploadedFile::fake()->create('foo.docx', '20');

This causes an error:

ErrorException : file_put_contents() expects parameter 1 to be a valid path, resource given
 /var/www/api/vendor/laravel/framework/src/Illuminate/Http/Testing/FileFactory.php:21
 /var/www/api/tests/Api/v2/File/Controllers/FileControllerTest.php:42

I believe the bug was introduced in 181db51

The return value of tmpfile() is being passed to file_put_contents(). However, tmpfile() returns a resource, whereas file_put_contents() expects a string containing a path.

Steps To Reproduce:

        use Illuminate\Http\UploadedFile;
        $uploadedFile = UploadedFile::fake()->create('foo.docx', '20');
@vroomfondle
Copy link
Contributor Author

For now we can "work around" the problem by just passing the number of kilobytes as an integer (which is probably what the developer who wrote our test intended anyway) but I thought I should flag this up.

@driesvints
Copy link
Member

Bit torn on this being a bug or not since the docblock clearly marked it that you should pass an int. I think I'm gonna close this up as the current api was just expanded rather than changed. Thanks for reporting this though.

@vroomfondle
Copy link
Contributor Author

Well, okay, but it seems odd to me that the call to file_put_contents() is there at all, given that it will never succeed. It's a useless line of code.

We've worked around the problem in our code so in future we'll just remember to always pass an int.

@driesvints driesvints reopened this Nov 21, 2019
@driesvints
Copy link
Member

@vroomfondle ah I misunderstood the actual problem. Thanks for mentioning this. We'll look into it 👍

@driesvints
Copy link
Member

Seems like this is already fixed in #30632. Will be good for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants