You are here

public function FileSystemTest::testDestinationDirectoryFailureOnCopy in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/File/FileSystemTest.php \Drupal\KernelTests\Core\File\FileSystemTest::testDestinationDirectoryFailureOnCopy()
  2. 9 core/tests/Drupal/KernelTests/Core/File/FileSystemTest.php \Drupal\KernelTests\Core\File\FileSystemTest::testDestinationDirectoryFailureOnCopy()

@covers ::copy

File

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

Class

FileSystemTest
@coversDefaultClass \Drupal\Core\File\FileSystem @group File

Namespace

Drupal\KernelTests\Core\File

Code

public function testDestinationDirectoryFailureOnCopy() {
  $this
    ->expectException(DirectoryNotReadyException::class);
  $this
    ->expectExceptionMessage("The specified file 'public://test.txt' could not be copied because the destination directory 'public://subdirectory' is not properly configured. This may be caused by a problem with file or directory permissions.");
  touch('public://test.txt');

  // public://subdirectory has not been created, so \Drupal::service('file_system')->prepareDirectory()
  // will fail, causing copy() to throw DirectoryNotReadyException.
  $this->fileSystem
    ->copy('public://test.txt', 'public://subdirectory/test.txt');
}