Forked from stevebauman/FilesystemMockProvider.php
Created
February 19, 2023 19:42
-
-
Save bhaidar/d4edabca2397049515c0f51db1671e7a to your computer and use it in GitHub Desktop.
Filesystem Cloud Mocking
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 | |
namespace App\Providers; | |
class FilesystemMockProvider extends ServiceProvider | |
{ | |
public function boot() | |
{ | |
if (App::isProduction()) { | |
return; | |
} | |
if (! config('filesystems.mock', false)) { | |
return; | |
} | |
$public = config('filesystems.disks.public'); | |
foreach (config('filesystems.disks') as $disk => $config) { | |
if ('local' !== $config['driver']) { | |
$root = $config['root'] ?? $config['bucket'] ?? '/'; | |
Storage::set($disk, Storage::createLocalDriver(array_merge($config, $public, [ | |
'root' => implode(DIRECTORY_SEPARATOR, [$public['root'], $root]), | |
'url' => implode(DIRECTORY_SEPARATOR, [$public['url'], $root]), | |
]))); | |
} | |
} | |
} | |
} |
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 | |
// config/filesystems.php | |
return [ | |
// ... | |
/* | |
|-------------------------------------------------------------------------- | |
| Filesystem Mocking | |
|-------------------------------------------------------------------------- | |
| | |
| The application may store files in several different cloud providers. | |
| Enabling filesystem mocking will swap these cloud provider drivers | |
| with local ones, storing these files locally for easier testing. | |
| | |
*/ | |
'mock' => env('FILESYSTEM_MOCK', env('APP_ENV') === 'local'), | |
// ... | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment