Skip to content

Instantly share code, notes, and snippets.

@tralves
Created July 7, 2016 22:10
Show Gist options
  • Save tralves/670354014ae4acfe54f28a24244d0d57 to your computer and use it in GitHub Desktop.
Save tralves/670354014ae4acfe54f28a24244d0d57 to your computer and use it in GitHub Desktop.
Laravel Storage mock test helper
<?php
use Illuminate\Support\Facades\Config;
class TestCase extends Laravel\Lumen\Testing\TestCase
{
/**
* Create a mock of a Storage disk.
*
* Usage:
* ```
* $storage = $this->mockStorageDisk('my-disk');
* $storage->shouldReceive('get')->once()->andReturn('test');
*
* // test
* Storage::disk('my-disk')->get('file.txt');
* ```
*
* @param String $disk Optional
* @return Filesystem
*/
protected function mockStorageDisk($disk = 'mock')
{
Storage::extend('mock', function () {
return \Mockery::mock(\Illuminate\Contracts\Filesystem\Filesystem::class);
});
Config::set('filesystems.disks.' . $disk, ['driver' => 'mock']);
Config::set('filesystems.default', $disk);
return Storage::disk($disk);
}
}
@tralves
Copy link
Author

tralves commented Jul 7, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment