Skip to content

Commit

Permalink
feat: add dedicated test cases to ensure copy and move methods to alw…
Browse files Browse the repository at this point in the history
…ays overwrite target
  • Loading branch information
tinect committed Aug 9, 2024
1 parent 009a4a1 commit 219c79a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
8 changes: 5 additions & 3 deletions InMemoryFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,14 @@ public function move(string $source, string $destination, Config $config): void
$sourcePath = $this->preparePath($source);
$destinationPath = $this->preparePath($destination);

if ( ! $this->fileExists($source) || $this->fileExists($destination)) {
if ( ! $this->fileExists($source)) {
throw UnableToMoveFile::fromLocationTo($source, $destination);
}

$this->files[$destinationPath] = $this->files[$sourcePath];
unset($this->files[$sourcePath]);
if ($sourcePath !== $destinationPath) {
$this->files[$destinationPath] = $this->files[$sourcePath];
unset($this->files[$sourcePath]);
}

if ($visibility = $config->get(Config::OPTION_VISIBILITY)) {
$this->setVisibility($destination, $visibility);
Expand Down
12 changes: 0 additions & 12 deletions InMemoryFilesystemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,6 @@ public function moving_a_file_successfully(): void
$this->assertTrue($adapter->fileExists('new-path.txt'));
}

/**
* @test
*/
public function moving_a_file_with_collision(): void
{
$this->expectException(UnableToMoveFile::class);
$adapter = $this->adapter();
$adapter->write('path.txt', 'contents', new Config());
$adapter->write('new-path.txt', 'contents', new Config());
$adapter->move('path.txt', 'new-path.txt', new Config());
}

/**
* @test
*/
Expand Down

0 comments on commit 219c79a

Please sign in to comment.