With all the previous work in place for the file upload, now I want to cover file validation. For this, we will let the Laravel request
method handle the logic for us. This way, we can deal with all of this outside the controller, so when we plug it in we will be ready to go. I will cover checking file size and type.
Use the previous recipe to set up sound groundwork. I will use that recipe to then create a test around size and type of file.
Make the custom form validation request:
>php artisan make:request ProfileUploadRequest
Now add to our Behat feature
features/profile/profile_image.feature
some of the things we are looking for:Then we run the step in the following image to stub out our steps in the context file. This is due to the
--append-snippets
switch:And we are set to start writing the code needed to handle this!
Our test will look like this as it verifies the file type, in this case, I pass in
png
but in my form request I set...