@@ -154,6 +154,8 @@ public static function pathProvider(): array
154154 [null , 'file.txt ' , false ],
155155 ['foo ' , 'foo/file.txt ' , true ],
156156 ['foo ' , 'foo/file.txt ' , false ],
157+ ['0 ' , '0/file.txt ' , true ],
158+ ['0 ' , '0/file.txt ' , false ],
157159 ];
158160 }
159161
@@ -180,6 +182,34 @@ public function testResolveUri(): void
180182 self ::assertEquals ('/uploads/file.txt ' , $ path );
181183 }
182184
185+ public function testResolveUriWithZeroDirectory (): void
186+ {
187+ $ this ->mapping
188+ ->expects (self ::once ())
189+ ->method ('getUriPrefix ' )
190+ ->willReturn ('/uploads ' );
191+
192+ $ this ->mapping
193+ ->expects (self ::once ())
194+ ->method ('getUploadDir ' )
195+ ->willReturn ('0 ' );
196+
197+ $ this ->mapping
198+ ->expects (self ::once ())
199+ ->method ('getFileName ' )
200+ ->willReturn ('file.txt ' );
201+
202+ $ this ->factory
203+ ->expects (self ::once ())
204+ ->method ('fromField ' )
205+ ->with ($ this ->object , 'file_field ' )
206+ ->willReturn ($ this ->mapping );
207+
208+ $ path = $ this ->getStorage ()->resolveUri ($ this ->object , 'file_field ' );
209+
210+ self ::assertEquals ('/uploads/0/file.txt ' , $ path );
211+ }
212+
183213 #[RequiresMethod(Filesystem::class, 'publicUrl ' )]
184214 public function testResolveUriThroughFlysystem (): void
185215 {
@@ -212,6 +242,43 @@ public function testResolveUriThroughFlysystem(): void
212242 self ::assertEquals ('example.com/file.txt ' , $ path );
213243 }
214244
245+ #[RequiresMethod(Filesystem::class, 'publicUrl ' )]
246+ public function testResolveUriThroughFlysystemWithZeroDirectory (): void
247+ {
248+ $ this ->useFlysystemToResolveUri = true ;
249+
250+ $ this ->filesystem
251+ ->expects (self ::once ())
252+ ->method ('publicUrl ' )
253+ ->with ('0/file.txt ' , [
254+ 'object ' => $ this ->object ,
255+ 'fieldName ' => 'file_field ' ,
256+ 'className ' => null ,
257+ 'mapping ' => $ this ->mapping ,
258+ ])
259+ ->willReturn ('example.com/0/file.txt ' );
260+
261+ $ this ->mapping
262+ ->expects (self ::once ())
263+ ->method ('getUploadDir ' )
264+ ->willReturn ('0 ' );
265+
266+ $ this ->mapping
267+ ->expects (self ::once ())
268+ ->method ('getFileName ' )
269+ ->willReturn ('file.txt ' );
270+
271+ $ this ->factory
272+ ->expects (self ::exactly (2 ))
273+ ->method ('fromField ' )
274+ ->with ($ this ->object , 'file_field ' )
275+ ->willReturn ($ this ->mapping );
276+
277+ $ path = $ this ->getStorage ()->resolveUri ($ this ->object , 'file_field ' );
278+
279+ self ::assertEquals ('example.com/0/file.txt ' , $ path );
280+ }
281+
215282 #[RequiresMethod(Filesystem::class, 'publicUrl ' )]
216283 public function testResolveUriHandlesUndefinedMethodError (): void
217284 {
0 commit comments