@@ -96,19 +96,17 @@ class Storage extends Facade
96
96
*/
97
97
public static function fake ($ disk = null , array $ config = [])
98
98
{
99
- $ disk = $ disk ?: static ::$ app ['config ' ]->get ('filesystems.default ' );
100
-
101
- $ root = storage_path ('framework/testing/disks/ ' .$ disk );
99
+ $ root = self ::getRootPath ($ disk = $ disk ?: static ::$ app ['config ' ]->get ('filesystems.default ' ));
102
100
103
101
if ($ token = ParallelTesting::token ()) {
104
102
$ root = "{$ root }_test_ {$ token }" ;
105
103
}
106
104
107
105
(new Filesystem )->cleanDirectory ($ root );
108
106
109
- static ::set ($ disk , $ fake = static ::createLocalDriver (array_merge ( $ config , [
110
- ' root ' => $ root,
111
- ]) ));
107
+ static ::set ($ disk , $ fake = static ::createLocalDriver (
108
+ self :: buildDiskConfiguration ( $ disk , $ config , root: $ root)
109
+ ));
112
110
113
111
return tap ($ fake )->buildTemporaryUrlsUsing (function ($ path , $ expiration ) {
114
112
return URL ::to ($ path .'?expiration= ' .$ expiration ->getTimestamp ());
@@ -126,13 +124,43 @@ public static function persistentFake($disk = null, array $config = [])
126
124
{
127
125
$ disk = $ disk ?: static ::$ app ['config ' ]->get ('filesystems.default ' );
128
126
129
- static ::set ($ disk , $ fake = static ::createLocalDriver (array_merge ( $ config , [
130
- ' root ' => storage_path ( ' framework/testing/disks/ ' . $ disk ),
131
- ]) ));
127
+ static ::set ($ disk , $ fake = static ::createLocalDriver (
128
+ self :: buildDiskConfiguration ( $ disk , $ config , root: self :: getRootPath ( $ disk ))
129
+ ));
132
130
133
131
return $ fake ;
134
132
}
135
133
134
+ /**
135
+ * Get the root path of the given disk.
136
+ *
137
+ * @param string $disk
138
+ * @return string
139
+ */
140
+ protected static function getRootPath (string $ disk ): string
141
+ {
142
+ return storage_path ('framework/testing/disks/ ' .$ disk );
143
+ }
144
+
145
+ /**
146
+ * Assemble the configuration of the given disk.
147
+ *
148
+ * @param string $disk
149
+ * @param array $config
150
+ * @param string $root
151
+ * @return array
152
+ */
153
+ protected static function buildDiskConfiguration (string $ disk , array $ config , string $ root ): array
154
+ {
155
+ $ originalConfig = static ::$ app ['config ' ]["filesystems.disks. {$ disk }" ] ?? [];
156
+
157
+ return array_merge ([
158
+ 'throw ' => $ originalConfig ['throw ' ] ?? false ],
159
+ $ config ,
160
+ ['root ' => $ root ]
161
+ );
162
+ }
163
+
136
164
/**
137
165
* Get the registered name of the component.
138
166
*
0 commit comments