-
Notifications
You must be signed in to change notification settings - Fork 73
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
UploadedFile is invalid #67
Comments
can you try not using the facade to do the test setting. I think this example might help https://github.com/alnutile/recipes/blob/master/features/bootstrap/ProfileImageDomainContext.php |
@alnutile @laracasts @JeffreyWay I'm having the same problem, I'm dumping what isValid is parsing 1st time: test flag is set to true, error = 0 (fine, it should pass) $pathToFile = base_path('features/fixtures/iLean.pdf');
$files = [
'file' => new \Illuminate\Http\UploadedFile($pathToFile, 'iLean.pdf', filesize($pathToFile), 'application/pdf', null, true)
];
$this->sendRequest('post', $uri, [], $files);
|
I never actually managed to fix this problem. What I found out is that the test flag is not preserved when the request is created and send. When the request is being created it is recreating a file object but its not preserving the test flag. |
Allright, so I've found the bottleneck. There's a This happens in It loops over the files and creates a new I've overwritten it in the form request that was giving me trouble: protected function convertUploadedFiles(array $files)
{
return array_map(function ($file) {
if (is_null($file) || (is_array($file) && empty(array_filter($file)))) {
return $file;
}
return is_array($file)
? $this->convertUploadedFiles($file)
: UploadedFile::createFromBase($file, in_array(env('APP_ENV'), ['behat', 'testing']));
}, $files);
} It's strange though, since normally (if I go through the code) it should just copy the provided UploadFile object instead of creating a new one. |
@happyDemon is this a patch you want to sumbit for me to roll in? |
Hi,
I am not sure if this is a right place to ask about it but when trying to test file upload I am getting an validation failure when
Illuminate\Validation\Validator::validateAttribute
is called.I have an FormRequest with rules as follow:
I traced the problem to the
Symfony\Component\HttpFoundation\File\UploadedFile::isValid
function which return false. It class have an option to set an UploadedFile to test mode but it seems that the test flag is not preserve from my FeatureContext.I am using
UploadedFile::fake()->image('test.png')
to generate a test image with a test flag but the flag is not preserve when the request is made.The text was updated successfully, but these errors were encountered: