FileDeleteTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/File/FileDeleteTest.php
View source
<?php
namespace Drupal\KernelTests\Core\File;
use Drupal\Core\File\Exception\NotRegularFileException;
class FileDeleteTest extends FileTestBase {
public function testNormal() {
$uri = $this
->createUri();
$this
->assertTrue(\Drupal::service('file_system')
->delete($uri), 'Deleted worked.');
$this
->assertFileDoesNotExist($uri);
}
public function testMissing() {
$this
->assertTrue(\Drupal::service('file_system')
->delete('public://' . $this
->randomMachineName()), 'Returns true when deleting a non-existent file.');
}
public function testDirectory() {
$directory = $this
->createDirectory();
try {
\Drupal::service('file_system')
->delete($directory);
$this
->fail('Expected NotRegularFileException');
} catch (NotRegularFileException $e) {
}
$this
->assertDirectoryExists($directory);
}
}