Ltloafer's avatar

How do I mock s3?

Hi,

I'm trying to test my file uploads to s3. At the moment I'm physically hitting s3 which is okay but slow. I don't quite understand how I would go about mocking s3 to avoid that. So, if I'm using Taylor's example in the docs:

public function testPhotoCanBeUploaded()
{
    $this->visit('/upload')
         ->type('File Name', 'name')
         ->attach($absolutePathToFile, 'photo')
         ->press('Upload')
         ->see('Upload Successful!');
}

How do i mock the storage facade so I don't actually upload to s3? I've read the docs but it doesn't click with me.... Thanks

0 likes
2 replies
ohffs's avatar

Can't you just do something like :

Storage::shouldReceive('put')->once()->with('/path/thing', $contents);

Whatever is inside your upload code?

salamwaddah's avatar

Try Storage::fake('s3'); before you hit the endpoint in the test

5 likes

Please or to participate in this conversation.