You are here

protected function SpaceUsedTest::createFileWithSize in Drupal 8

Same name and namespace in other branches
  1. 9 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;
}