Skip to content

Commit

Permalink
feat: add test cases to ensure error when deleting entire storage and…
Browse files Browse the repository at this point in the history
… deleting directory by delete method instead of deleteDirectory
  • Loading branch information
tinect committed Dec 26, 2023
1 parent d4ad81e commit 9ef8f59
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/AdapterTestUtilities/FilesystemAdapterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace League\Flysystem\AdapterTestUtilities;

use League\Flysystem\UnableToDeleteFile;
use const PHP_EOL;
use DateInterval;
use DateTimeImmutable;
Expand Down Expand Up @@ -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'));
});
}
}

0 comments on commit 9ef8f59

Please sign in to comment.