You are here

private function FileHelperTest::prepareUpdateSize in SVG Upload Sanitizer 8

Prepare the context for the updateSize() method tests.

Parameters

bool $pathIsResolved: TRUE if the file path was resolved, FALSE otherwise.

bool $filePathExists: TRUE if the file path exists, FALSE otherwise.

bool $fileSaveIsSuccessful: TRUE if the file save was successful, FALSE otherwise.

Return value

\PHPUnit\Framework\MockObject\MockObject A mocked optimizer.

4 calls to FileHelperTest::prepareUpdateSize()
FileHelperTest::testUpdateSize in tests/src/Unit/Helper/FileHelperTest.php
FileHelperTest::testUpdateSizeWhenTheFileCouldNotBeSaved in tests/src/Unit/Helper/FileHelperTest.php
FileHelperTest::testUpdateSizeWhenTheFilePathCouldNotBeResolved in tests/src/Unit/Helper/FileHelperTest.php
FileHelperTest::testUpdateSizeWhenTheFileSizeCouldNotBeGotten in tests/src/Unit/Helper/FileHelperTest.php

File

tests/src/Unit/Helper/FileHelperTest.php, line 110

Class

FileHelperTest
Unit test class for the FileHelper class.

Namespace

Drupal\Tests\svg_upload_sanitizer\Unit\Helper

Code

private function prepareUpdateSize($pathIsResolved, $filePathExists = FALSE, $fileSaveIsSuccessful = FALSE) {
  $filePath = $filePathExists ? sprintf('%s/fixtures/image.svg', __DIR__) : 'something/that/will/never/exists.casper';
  $this->fileSystem
    ->expects($this
    ->atLeastOnce())
    ->method('realpath')
    ->with('public://fileuri')
    ->willReturn($pathIsResolved ? $filePath : FALSE);
  $file = $this
    ->createMock(FileInterface::class);
  $file
    ->expects($this
    ->atLeastOnce())
    ->method('getFileUri')
    ->willReturn('public://fileuri');
  if ($filePathExists) {
    $file
      ->expects($this
      ->atLeastOnce())
      ->method('setSize')
      ->with(filesize($filePath));
    $mocker = $file
      ->expects($this
      ->atLeastOnce())
      ->method('save');
    if (!$fileSaveIsSuccessful) {
      $mocker
        ->willThrowException(new EntityStorageException());
    }
  }
  return [
    $file,
    $filePath,
  ];
}