function CopyTest::testEntityStorageException

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

Tests for entity storage exception.

@covers ::copy

File

core/modules/file/tests/src/Kernel/CopyTest.php, line 198

Class

CopyTest
Tests the file copy function.

Namespace

Drupal\Tests\file\Kernel

Code

public function testEntityStorageException() {
    
    /** @var \Drupal\Core\Entity\EntityTypeManager $entityTypeManager */
    $entityTypeManager = $this->prophesize(EntityTypeManager::class);
    $entityTypeManager->getStorage('file')
        ->willThrow(EntityStorageException::class);
    $fileRepository = new FileRepository($this->container
        ->get('file_system'), $this->container
        ->get('stream_wrapper_manager'), $entityTypeManager->reveal(), $this->container
        ->get('module_handler'), $this->container
        ->get('file.usage'), $this->container
        ->get('current_user'));
    $this->expectException(EntityStorageException::class);
    $source = $this->createFile();
    $target = $this->createFile();
    $fileRepository->copy($source, $target->getFileUri(), FileSystemInterface::EXISTS_REPLACE);
}

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