function ImageStyleTest::getImageStyleMock

Same name in other branches
  1. 9 core/modules/image/tests/src/Unit/ImageStyleTest.php \Drupal\Tests\image\Unit\ImageStyleTest::getImageStyleMock()
  2. 8.9.x core/modules/image/tests/src/Unit/ImageStyleTest.php \Drupal\Tests\image\Unit\ImageStyleTest::getImageStyleMock()
  3. 11.x 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.

4 calls to ImageStyleTest::getImageStyleMock()
ImageStyleTest::testBuildUri in core/modules/image/tests/src/Unit/ImageStyleTest.php
@covers ::buildUri
ImageStyleTest::testFlush in core/modules/image/tests/src/Unit/ImageStyleTest.php
@covers ::flush
ImageStyleTest::testGetDerivativeExtension in core/modules/image/tests/src/Unit/ImageStyleTest.php
@covers ::getDerivativeExtension
ImageStyleTest::testGetPathToken in core/modules/image/tests/src/Unit/ImageStyleTest.php
@covers ::getPathToken

File

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

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)
        ->willReturn($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')
        ->willReturn($effectManager);
    $image_style->expects($this->any())
        ->method('fileDefaultScheme')
        ->willReturnCallback([
        $this,
        'fileDefaultScheme',
    ]);
    return $image_style;
}

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