File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -188,7 +188,9 @@ private function createDirectoryRecursively(string $path): bool
188188 $ parentDir = dirname ($ path );
189189
190190 while (!$ this ->isDirectory ($ parentDir )) {
191- $ this ->createDirectoryRecursively ($ parentDir );
191+ if (!$ this ->createDirectoryRecursively ($ parentDir )) {
192+ return false ;
193+ }
192194 }
193195
194196 if (!$ this ->isDirectory ($ path )) {
Original file line number Diff line number Diff line change 1818
1919/**
2020 * @see AwsS3
21+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2122 */
2223class AwsS3Test extends TestCase
2324{
@@ -497,6 +498,23 @@ public function testCreateDirectory(): void
497498 self ::assertTrue ($ this ->driver ->createDirectory (self ::URL . 'test/test2/ ' ));
498499 }
499500
501+ /**
502+ * This test ensures that the method does not loop infinitely in case of an exception
503+ *
504+ * @return void
505+ * @throws FileSystemException
506+ * @throws \PHPUnit\Framework\MockObject\Exception
507+ */
508+ public function testShouldFailSafelyIfUnableToCreateDirectory (): void
509+ {
510+ $ this ->adapterMock ->expects (self ::once ())
511+ ->method ('createDirectory ' )
512+ ->willThrowException ($ this ->createMock (\League \Flysystem \FilesystemException::class))
513+ ->with ('test ' );
514+
515+ self ::assertFalse ($ this ->driver ->createDirectory (self ::URL . 'test/test2/ ' ));
516+ }
517+
500518 public function testRename (): void
501519 {
502520 $ this ->adapterMock ->expects (self ::once ())
You can’t perform that action at this time.
0 commit comments