function ImageStyleTest::getImageStyleMock

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

3 calls to ImageStyleTest::getImageStyleMock()
ImageStyleTest::testBuildUri in core/modules/image/tests/src/Unit/ImageStyleTest.php
@covers ::buildUri
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 49

Class

ImageStyleTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21image%21src%21Entity%21ImageStyle.php/class/ImageStyle/9" title="Defines an image style configuration entity." class="local">\Drupal\image\Entity\ImageStyle</a>

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.