You are here

protected function ImageStyleTest::getImageStyleMock in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/image/tests/src/Unit/ImageStyleTest.php \Drupal\Tests\image\Unit\ImageStyleTest::getImageStyleMock()
  2. 9 core/modules/image/tests/src/Unit/ImageStyleTest.php \Drupal\Tests\image\Unit\ImageStyleTest::getImageStyleMock()

Gets a mocked image style for testing.

Parameters

string $image_effect_id: The image effect ID.

\Drupal\image\ImageEffectInterface|\PHPUnit\Framework\MockObject\MockObject $image_effect: The image effect used for testing.

array $stubs: An array of additional method names to mock.

Return value

\Drupal\image\ImageStyleInterface The mocked image style.

File

core/modules/image/tests/src/Unit/ImageStyleTest.php, line 49

Class

ImageStyleTest
@coversDefaultClass \Drupal\image\Entity\ImageStyle

Namespace

Drupal\Tests\image\Unit

Code

protected function getImageStyleMock($image_effect_id, $image_effect, $stubs = []) {
  $effectManager = $this
    ->getMockBuilder('\\Drupal\\image\\ImageEffectManager')
    ->disableOriginalConstructor()
    ->getMock();
  $effectManager
    ->expects($this
    ->any())
    ->method('createInstance')
    ->with($image_effect_id)
    ->will($this
    ->returnValue($image_effect));
  $default_stubs = [
    'getImageEffectPluginManager',
    'fileDefaultScheme',
  ];
  $image_style = $this
    ->getMockBuilder('\\Drupal\\image\\Entity\\ImageStyle')
    ->setConstructorArgs([
    [
      'effects' => [
        $image_effect_id => [
          'id' => $image_effect_id,
        ],
      ],
    ],
    $this->entityTypeId,
  ])
    ->onlyMethods(array_merge($default_stubs, $stubs))
    ->getMock();
  $image_style
    ->expects($this
    ->any())
    ->method('getImageEffectPluginManager')
    ->will($this
    ->returnValue($effectManager));
  $image_style
    ->expects($this
    ->any())
    ->method('fileDefaultScheme')
    ->willReturnCallback([
    $this,
    'fileDefaultScheme',
  ]);
  return $image_style;
}