function FileTestBase::createDirectory

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/File/FileTestBase.php \Drupal\KernelTests\Core\File\FileTestBase::createDirectory()
  2. 10 core/tests/Drupal/KernelTests/Core/File/FileTestBase.php \Drupal\KernelTests\Core\File\FileTestBase::createDirectory()
  3. 8.9.x core/tests/Drupal/KernelTests/Core/File/FileTestBase.php \Drupal\KernelTests\Core\File\FileTestBase::createDirectory()

Create a directory and assert it exists.

Parameters

string $path: Optional string with a directory path. If none is provided, a random name in the site's files directory will be used.

Return value

string The path to the directory.

File

core/tests/Drupal/KernelTests/Core/File/FileTestBase.php, line 162

Class

FileTestBase
Provides file-specific assertions and helper functions.

Namespace

Drupal\KernelTests\Core\File

Code

public function createDirectory($path = NULL) {
  // A directory to operate on.
  if (!isset($path)) {
    $path = 'public://' . $this->randomMachineName();
  }
  $this->assertTrue(\Drupal::service('file_system')->mkdir($path));
  $this->assertDirectoryExists($path);
  return $path;
}

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