function FileSystemTest::testCopyFailureIfFileAlreadyExists

Same name and namespace in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/File/FileSystemTest.php \Drupal\KernelTests\Core\File\FileSystemTest::testCopyFailureIfFileAlreadyExists()
  2. 9 core/tests/Drupal/KernelTests/Core/File/FileSystemTest.php \Drupal\KernelTests\Core\File\FileSystemTest::testCopyFailureIfFileAlreadyExists()
  3. 8.9.x core/tests/Drupal/KernelTests/Core/File/FileSystemTest.php \Drupal\KernelTests\Core\File\FileSystemTest::testCopyFailureIfFileAlreadyExists()

Tests copy failure if file already exists.

@legacy-covers ::copy

File

core/tests/Drupal/KernelTests/Core/File/FileSystemTest.php, line 78

Class

FileSystemTest
Tests Drupal\Core\File\FileSystem.

Namespace

Drupal\KernelTests\Core\File

Code

public function testCopyFailureIfFileAlreadyExists() : void {
  $this->expectException(FileExistsException::class);
  $this->expectExceptionMessage("File 'public://test.txt' could not be copied because a file by that name already exists in the destination directory ('')");
  $uri = 'public://test.txt';
  touch($uri);
  $this->fileSystem
    ->copy($uri, $uri, FileExists::Error);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.