34
loading...
This website collects cookies to deliver better user experience
postJson
post
file
PhotosController
we notice that it throws an error every time it encounters an image that doesn't contain location data. It's easy to test this case because, by default, Laravel's fake files have no location data. We just log in, create a fake image, try to upload it, and test that the server returns with a 500 error code. And that's it. We could also check for the exact error message, but since the current implementation of the error pages doesn't show the error, we only check for the status code.public/local-uploads
directory. We've already tested for non-production environments, let's test it the other way.app()->detectEnvironment()
from which we swap the environment to production during this test's lifetime.WithoutMiddleware
, which basically tells the app to ignore all middleware. After we use this trait the test works fine, the image gets uploaded to the S3 disk and has the right properties. However, the authentication test is now failing, because, duh, we disabled all middleware for the test class, including the auth
middleware. Too bad. At this point, we just extract this last test for production environments into its own class, called UploadPhotoToProductionTest
.The code used for illustration is taken from the OpenLitterMap project. They're doing a great job creating the world's most advanced open database on litter, brands & plastic pollution. The project is open-sourced and would love your contributions, both as users and developers.