function FileUploadHandlerTest::testLockAcquireException

Same name in other branches
  1. 11.x core/modules/file/tests/src/Kernel/FileUploadHandlerTest.php \Drupal\Tests\file\Kernel\FileUploadHandlerTest::testLockAcquireException()

Test the lock acquire exception.

File

core/modules/file/tests/src/Kernel/FileUploadHandlerTest.php, line 81

Class

FileUploadHandlerTest
Tests the file upload handler.

Namespace

Drupal\Tests\file\Kernel

Code

public function testLockAcquireException() : void {
    $lock = $this->createMock(LockBackendInterface::class);
    $lock->expects($this->once())
        ->method('acquire')
        ->willReturn(FALSE);
    $fileUploadHandler = new FileUploadHandler($this->container
        ->get('file_system'), $this->container
        ->get('entity_type.manager'), $this->container
        ->get('stream_wrapper_manager'), $this->container
        ->get('event_dispatcher'), $this->container
        ->get('file.mime_type.guesser'), $this->container
        ->get('current_user'), $this->container
        ->get('request_stack'), $this->container
        ->get('file.repository'), $this->container
        ->get('file.validator'), $lock, $this->container
        ->get('validation.basic_recursive_validator_factory'));
    $file_name = $this->randomMachineName();
    $file_info = $this->createMock(UploadedFileInterface::class);
    $file_info->expects($this->once())
        ->method('getClientOriginalName')
        ->willReturn($file_name);
    $file_info->expects($this->once())
        ->method('validate')
        ->willReturn(new ConstraintViolationList());
    $this->expectException(LockAcquiringException::class);
    $this->expectExceptionMessage(sprintf('File "temporary://%s" is already locked for writing.', $file_name));
    $fileUploadHandler->handleFileUpload(uploadedFile: $file_info, throw: FALSE);
}

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