From 8e0df19e28b7e5549c4af066c9615a989fbc3015 Mon Sep 17 00:00:00 2001 From: eltouf <496631+eltouf@users.noreply.github.com> Date: Wed, 25 Mar 2026 14:54:13 +0100 Subject: [PATCH] fix: throw exception when attempting to retrieve stats for a non-existent directory --- .../StreamCommand/StreamStatCommand.php | 2 ++ tests/StreamCommand/StreamStatTest.php | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Flysystem/StreamCommand/StreamStatCommand.php b/src/Flysystem/StreamCommand/StreamStatCommand.php index 4ea23ae..c6041f6 100644 --- a/src/Flysystem/StreamCommand/StreamStatCommand.php +++ b/src/Flysystem/StreamCommand/StreamStatCommand.php @@ -142,6 +142,8 @@ public static function getRemoteStats(FileData $current): array [$mode, $size, $lastModified] = self::getRemoteDirectoryStats($current, $converter, $visibility); } elseif ($current->filesystem->fileExists($current->file)) { [$mode, $size, $lastModified] = self::getRemoteFileStats($current, $converter, $visibility); + } else { + throw $e; } } else { throw $e; diff --git a/tests/StreamCommand/StreamStatTest.php b/tests/StreamCommand/StreamStatTest.php index c0048aa..892a922 100644 --- a/tests/StreamCommand/StreamStatTest.php +++ b/tests/StreamCommand/StreamStatTest.php @@ -1,4 +1,5 @@ getCurrent(); + + /** @var MockObject $filesystem */ + $filesystem = $current->filesystem; + $filesystem->method('visibility') + ->with('test') + ->willReturn(Visibility::PUBLIC); + $filesystem->method('lastModified') + ->with('test') + ->willThrowException(UnableToRetrieveMetadata::lastModified(self::TEST_PATH)); + + $this->assertFalse(@StreamStatCommand::run($current)); + + $this->expectErrorWithMessage('Stat failed'); + StreamStatCommand::run($current); + } + public function testRemoteException(): void { $current = $this->getCurrent();