function SpaceUsedTest::createFileWithSize

Same name in other branches
  1. 9 core/modules/file/tests/src/Kernel/SpaceUsedTest.php \Drupal\Tests\file\Kernel\SpaceUsedTest::createFileWithSize()
  2. 10 core/modules/file/tests/src/Kernel/SpaceUsedTest.php \Drupal\Tests\file\Kernel\SpaceUsedTest::createFileWithSize()
  3. 11.x core/modules/file/tests/src/Kernel/SpaceUsedTest.php \Drupal\Tests\file\Kernel\SpaceUsedTest::createFileWithSize()

Creates a file with a given size.

Parameters

string $uri: URI of the file to create.

int $size: Size of the file.

int $uid: File owner ID.

int $status: Whether the file should be permanent or temporary.

Return value

\Drupal\Core\Entity\EntityInterface The file entity.

1 call to SpaceUsedTest::createFileWithSize()
SpaceUsedTest::setUp in core/modules/file/tests/src/Kernel/SpaceUsedTest.php

File

core/modules/file/tests/src/Kernel/SpaceUsedTest.php, line 43

Class

SpaceUsedTest
Tests the spaceUsed() function.

Namespace

Drupal\Tests\file\Kernel

Code

protected function createFileWithSize($uri, $size, $uid, $status = FILE_STATUS_PERMANENT) {
    file_put_contents($uri, $this->randomMachineName($size));
    $file = File::create([
        'uri' => $uri,
        'uid' => $uid,
        'status' => $status,
    ]);
    $file->save();
    return $file;
}

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