get('filesystems.default')); if ($token = ParallelTesting::token()) { $root = "{$root}_test_{$token}"; } (new Filesystem)->cleanDirectory($root); static::set($disk, $fake = static::createLocalDriver( self::buildDiskConfiguration($disk, $config, root: $root) )); return tap($fake)->buildTemporaryUrlsUsing(function ($path, $expiration) { return URL::to($path.'?expiration='.$expiration->getTimestamp()); }); } /** * Replace the given disk with a persistent local testing disk. * * @param string|null $disk * @param array $config * @return \Illuminate\Contracts\Filesystem\Filesystem */ public static function persistentFake($disk = null, array $config = []) { $disk = $disk ?: static::$app['config']->get('filesystems.default'); static::set($disk, $fake = static::createLocalDriver( self::buildDiskConfiguration($disk, $config, root: self::getRootPath($disk)) )); return $fake; } /** * Get the root path of the given disk. * * @param string $disk * @return string */ protected static function getRootPath(string $disk): string { return storage_path('framework/testing/disks/'.$disk); } /** * Assemble the configuration of the given disk. * * @param string $disk * @param array $config * @param string $root * @return array */ protected static function buildDiskConfiguration(string $disk, array $config, string $root): array { $originalConfig = static::$app['config']["filesystems.disks.{$disk}"] ?? []; return array_merge([ 'throw' => $originalConfig['throw'] ?? false], $config, ['root' => $root] ); } /** * Get the registered name of the component. * * @return string */ protected static function getFacadeAccessor() { return 'filesystem'; } }