function FileCopyTest::testNonExistent

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php \Drupal\KernelTests\Core\File\FileCopyTest::testNonExistent()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php \Drupal\KernelTests\Core\File\FileCopyTest::testNonExistent()
  3. 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 53

Class

FileCopyTest
Tests the unmanaged file copy function.

Namespace

Drupal\KernelTests\Core\File

Code

public function testNonExistent() : void {
    // 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.');
}

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