You are here

public function FileCopyTest::testNonExistent in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php \Drupal\KernelTests\Core\File\FileCopyTest::testNonExistent()
  2. 10 core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php \Drupal\KernelTests\Core\File\FileCopyTest::testNonExistent()

Copy a non-existent file.

File

core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php, line 51

Class

FileCopyTest
Tests the unmanaged file copy function.

Namespace

Drupal\KernelTests\Core\File

Code

public function testNonExistent() {

  // Copy non-existent file
  $desired_filepath = $this
    ->randomMachineName();
  $this
    ->assertFileDoesNotExist($desired_filepath);
  $this
    ->expectException(FileNotExistsException::class);
  $new_filepath = \Drupal::service('file_system')
    ->copy($desired_filepath, $this
    ->randomMachineName());
  $this
    ->assertFalse($new_filepath, 'Copying a missing file fails.');
}