Created
July 7, 2016 22:10
-
-
Save tralves/670354014ae4acfe54f28a24244d0d57 to your computer and use it in GitHub Desktop.
Laravel Storage mock test helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Largely taken from this post: http://laravel.io/forum/05-04-2015-how-to-mock-the-get-method-for-storage by @kofan.