Skip to content

Commit

Permalink
Merge pull request #1823 from gam6itko/web-dav-create-folder-fix
Browse files Browse the repository at this point in the history
[WebDAV] createDirectory - not throw if got 405
  • Loading branch information
frankdejonge authored Oct 30, 2024
2 parents edc1bb7 + 1eb13cb commit 1af5c0b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/WebDAV/WebDAVAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ public function createDirectory(string $path, Config $config): void
throw UnableToCreateDirectory::dueToFailure($path, $exception);
}

if ($response['statusCode'] === 405) {
continue;
}

if ($response['statusCode'] !== 201) {
throw UnableToCreateDirectory::atLocation($path, 'Failed to create directory at: ' . $location);
}
Expand Down
27 changes: 26 additions & 1 deletion src/WebDAV/WebDAVAdapterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use League\Flysystem\UnableToMoveFile;
use League\Flysystem\UnableToSetVisibility;
use League\Flysystem\Visibility;
use Sabre\DAV\Client;

abstract class WebDAVAdapterTestCase extends FilesystemAdapterTestCase
{
Expand Down Expand Up @@ -48,7 +49,7 @@ public function creating_a_directory_with_leading_and_trailing_slashes(): void
{
$this->runScenario(function () {
$adapter = $this->adapter();
$adapter->createDirectory('/some/directory/', new Config);
$adapter->createDirectory('/some/directory/', new Config());

self::assertTrue($adapter->directoryExists('/some/directory/'));
});
Expand Down Expand Up @@ -132,4 +133,28 @@ public function moving_a_file_that_does_not_exist(): void
$this->adapter()->move('source.txt', 'destination.txt', new Config());
});
}

/**
* @test
*/
public function part_of_prefix_already_exists(): void
{
$this->runScenario(function () {
$config = new Config();

$adapter1 = new WebDAVAdapter(
new Client(['baseUri' => 'http://localhost:4040/']),
'directory1/prefix1',
);
$adapter1->createDirectory('folder1', $config);
self::assertTrue($adapter1->directoryExists('/folder1'));

$adapter2 = new WebDAVAdapter(
new Client(['baseUri' => 'http://localhost:4040/']),
'directory1/prefix2',
);
$adapter2->createDirectory('folder2', $config);
self::assertTrue($adapter2->directoryExists('/folder2'));
});
}
}

0 comments on commit 1af5c0b

Please sign in to comment.