Skip to content
Snippets Groups Projects
Unverified Commit 47fd6730 authored by Robin Appelman's avatar Robin Appelman
Browse files

use `nodeExists` instead of catching exceptions


makes the intent of the code more clear imo

Signed-off-by: default avatarRobin Appelman <robin@icewind.nl>
parent 950856d5
No related branches found
No related tags found
No related merge requests found
......@@ -124,10 +124,9 @@ class Manager implements IManager {
public function create(string $path, string $editorId, string $creatorId, $templateId = null): string {
$userFolder = $this->rootFolder->getUserFolder($this->userId);
try {
$file = $userFolder->get($path);
if ($userFolder->nodeExists($path)) {
throw new \RuntimeException('File already exists');
} catch (\OCP\Files\NotFoundException $e) {
} else {
$file = $userFolder->newFile($path);
$editor = $this->getEditor($editorId);
$creators = $editor->getCreators();
......
......@@ -153,9 +153,9 @@ class ManagerTest extends TestCase {
->method('generate')
->willReturn($expectedToken);
$this->userFolder
->method('get')
->method('nodeExists')
->with('/File.txt')
->willThrowException(new NotFoundException());
->willReturn(false);
$this->userFolder->expects($this->once())
->method('newFile')
->willReturn($file);
......@@ -173,9 +173,9 @@ class ManagerTest extends TestCase {
->method('generate')
->willReturn($expectedToken);
$this->userFolder
->method('get')
->method('nodeExists')
->with('/File.txt')
->willThrowException(new NotFoundException());
->willReturn(false);
$this->userFolder->expects($this->once())
->method('newFile')
->willReturn($file);
......@@ -188,6 +188,10 @@ class ManagerTest extends TestCase {
public function testCreateFileAlreadyExists() {
$this->expectException(\RuntimeException::class);
$this->userFolder
->method('nodeExists')
->with('/File.txt')
->willReturn(true);
$this->manager->create('/File.txt', 'testeditor', 'createEmpty');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment