function FileCopyTest::testNonExistent

Same name and namespace in other branches
  1. 9 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()
  3. 11.x 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->assertFileNotExists($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.