You are here

protected function FileTest::getStreamWrapperMock in Freelinking 8.3

Same name and namespace in other branches
  1. 4.0.x tests/src/Unit/Plugin/freelinking/FileTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\FileTest::getStreamWrapperMock()

Get the stream wrapper mock depending on if the file should exist or not.

Parameters

int $fileAvailability: Whether the file should not exist (0), exist (1) or not be accessible (-1).

Return value

\Drupal\Core\StreamWrapper\StreamWrapperManagerInterface The stream wrapper manager object mocke to return

2 calls to FileTest::getStreamWrapperMock()
FileTest::setUp in tests/src/Unit/Plugin/freelinking/FileTest.php
FileTest::testBuildLink in tests/src/Unit/Plugin/freelinking/FileTest.php
Assert that buildLink is functional.

File

tests/src/Unit/Plugin/freelinking/FileTest.php, line 185

Class

FileTest
Tests the freelinking file plugin.

Namespace

Drupal\Tests\freelinking\Unit\Plugin\freelinking

Code

protected function getStreamWrapperMock($fileAvailability = 0) {

  // Mock Stream Wrapper Manager and stream wrapper interface.
  $streamWrapperProphet = $this
    ->prophesize('\\Drupal\\Core\\StreamWrapper\\StreamWrapperInterface');
  $streamWrapperProphet
    ->setUri(Argument::any())
    ->will(function () {
    return $this;
  });
  $streamWrapperProphet
    ->realpath()
    ->will(function () use ($fileAvailability) {
    return $fileAvailability !== 0;
  });
  $streamWrapperProphet
    ->getExternalUrl()
    ->willReturn('http://example.com/logo.png');
  $streamWrapperManagerProphet = $this
    ->prophesize('\\Drupal\\Core\\StreamWrapper\\StreamWrapperManagerInterface');
  $streamWrapperManagerProphet
    ->getViaScheme(Argument::any())
    ->willReturn($streamWrapperProphet
    ->reveal());
  return $streamWrapperManagerProphet
    ->reveal();
}