function FileDeleteRecursiveTest::testSingleFile

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

Delete a normal file.

File

core/tests/Drupal/KernelTests/Core/File/FileDeleteRecursiveTest.php, line 17

Class

FileDeleteRecursiveTest
Tests the unmanaged file delete recursive function.

Namespace

Drupal\KernelTests\Core\File

Code

public function testSingleFile() : void {
    // Create a file for testing
    $filepath = 'public://' . $this->randomMachineName();
    file_put_contents($filepath, '');
    // Delete the file.
    $this->assertTrue(\Drupal::service('file_system')->deleteRecursive($filepath), 'Function reported success.');
    $this->assertFileDoesNotExist($filepath);
}

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