From 9ef8f594133467bbdfff53aed42bd7312d3b0c8b Mon Sep 17 00:00:00 2001 From: tinect Date: Tue, 26 Dec 2023 22:28:56 +0100 Subject: [PATCH] feat: add test cases to ensure error when deleting entire storage and deleting directory by delete method instead of deleteDirectory --- .../FilesystemAdapterTestCase.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/AdapterTestUtilities/FilesystemAdapterTestCase.php b/src/AdapterTestUtilities/FilesystemAdapterTestCase.php index 5361d30f4..c4bad0879 100644 --- a/src/AdapterTestUtilities/FilesystemAdapterTestCase.php +++ b/src/AdapterTestUtilities/FilesystemAdapterTestCase.php @@ -4,6 +4,7 @@ namespace League\Flysystem\AdapterTestUtilities; +use League\Flysystem\UnableToDeleteFile; use const PHP_EOL; use DateInterval; use DateTimeImmutable; @@ -871,4 +872,50 @@ public function cannot_get_checksum_for_directory(): void $adapter->checksum('dir', new Config()); } + + /** + * @test + */ + public function cannot_delete_directory_over_delete(): void + { + $this->runScenario(function () { + $adapter = $this->adapter(); + + $adapter->write( + 'test/text.txt', + 'contents', + new Config() + ); + + $this->assertTrue($adapter->fileExists('test/text.txt')); + + $this->expectException(UnableToDeleteFile::class); + $adapter->delete('test/'); + + $this->assertTrue($adapter->fileExists('test/text.txt')); + }); + } + + /** + * @test + */ + public function cannot_delete_with_empty_path(): void + { + $this->runScenario(function () { + $adapter = $this->adapter(); + + $adapter->write( + 'test/text.txt', + 'contents', + new Config() + ); + + $this->assertTrue($adapter->fileExists('test/text.txt')); + + $this->expectException(UnableToDeleteFile::class); + $adapter->delete(''); + + $this->assertTrue($adapter->fileExists('test/text.txt')); + }); + } }