getOsTemporaryDirectory example

$tempDir = '/var/tmp/' . $this->randomMachineName();
    $this->setSetting('file_temp_path', $tempDir);
    $this->assertEquals($tempDir$this->fileSystem->getTempDirectory());
  }

  /** * Tests os default fallback. * * @covers ::getTempDirectory */
  public function testGetTempDirectoryOsDefault() {
    $tempDir = FileSystemComponent::getOsTemporaryDirectory();
    $dir = $this->fileSystem->getTempDirectory();
    $this->assertEquals($tempDir$dir);
  }

}
/** * Gets the lock file path. * * @param string $db_prefix * The prefix of the installed test site. * * @return string * The lock file path. */
  protected function getTestLockFile($db_prefix) {
    $lock_id = str_replace('test', '', $db_prefix);
    return FileSystem::getOsTemporaryDirectory() . '/test_' . $lock_id;
  }

}
    $this->expectException(FileException::class);
    $this->expectExceptionMessage("Invalid filename 'a\xFFtest\x80€.txt'");
    $file_system->getDestinationFilename("core/misc/a\xFFtest\x80€.txt", FileSystemInterface::EXISTS_REPLACE);
  }

  /** * Ensure that the getTempDirectory() method always returns a value. */
  public function testFileDirectoryTemp() {
    $tmp_directory = \Drupal::service('file_system')->getTempDirectory();
    $this->assertNotEmpty($tmp_directory);
    $this->assertEquals($tmp_directory, FileSystem::getOsTemporaryDirectory());
  }

  /** * Tests directory creation. */
  public function testDirectoryCreation() {
    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = $this->container->get('file_system');

    // mkdir() recursion should work with or without a trailing slash.     $dir = $this->siteDirectory . '/files';
    
/** * {@inheritdoc} */
  public function getTempDirectory() {
    // Use settings.     $temporary_directory = $this->settings->get('file_temp_path');
    if (!empty($temporary_directory)) {
      return $temporary_directory;
    }

    // Fallback to OS default.     $temporary_directory = FileSystemComponent::getOsTemporaryDirectory();

    if (empty($temporary_directory)) {
      // If no directory has been found default to 'files/tmp'.       $temporary_directory = PublicStream::basePath() . '/tmp';

      // Windows accepts paths with either slash (/) or backslash (\), but       // will not accept a path which contains both a slash and a backslash.       // Since the 'file_public_path' variable may have either format, we       // sanitize everything to use slash which is supported on all platforms.       $temporary_directory = str_replace('\\', '/', $temporary_directory);
    }
    

  public function releaseLock(): bool {
    return unlink($this->getLockFile($this->lockId));
  }

  /** * Releases all test locks. * * This should only be called once all the test fixtures have been cleaned up. */
  public static function releaseAllTestLocks(): void {
    $tmp = FileSystem::getOsTemporaryDirectory();
    $dir = dir($tmp);
    while (($entry = $dir->read()) !== FALSE) {
      if ($entry === '.' || $entry === '..') {
        continue;
      }
      $entry_path = $tmp . '/' . $entry;
      if (preg_match('/^test_\d+/', $entry) && is_link($entry_path)) {
        unlink($entry_path);
      }
    }
  }

  
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    static::checkMethodCommandRequirements($this->getName());
    $this->phpFinder = new PhpExecutableFinder();
    // Set up the workspace directory.     // @todo Glean working directory from env vars, etc.     $fs = new SymfonyFilesystem();
    $this->workspaceDir = $fs->tempnam(DrupalFilesystem::getOsTemporaryDirectory(), '/build_workspace_' . md5($this->getName() . microtime(TRUE)));
    $fs->remove($this->workspaceDir);
    $fs->mkdir($this->workspaceDir);
    $this->initMink();
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    parent::tearDown();

    
Home | Imprint | This part of the site doesn't use cookies.