function UnitTestCase::getClassResolverStub

Same name in other branches
  1. 9 core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::getClassResolverStub()
  2. 8.9.x core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::getClassResolverStub()
  3. 10 core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::getClassResolverStub()

Returns a stub class resolver.

Return value

\Drupal\Core\DependencyInjection\ClassResolverInterface|\PHPUnit\Framework\MockObject\MockObject The class resolver stub.

3 calls to UnitTestCase::getClassResolverStub()
EntityResolverManagerTest::setUp in core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php
@covers ::__construct
EntityTypeManagerTest::setUp in core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php
FormTestBase::setUp in core/tests/Drupal/Tests/Core/Form/FormTestBase.php

File

core/tests/Drupal/Tests/UnitTestCase.php, line 216

Class

UnitTestCase
Provides a base class and helpers for Drupal unit tests.

Namespace

Drupal\Tests

Code

protected function getClassResolverStub() {
    $class_resolver = $this->createMock('Drupal\\Core\\DependencyInjection\\ClassResolverInterface');
    $class_resolver->expects($this->any())
        ->method('getInstanceFromDefinition')
        ->willReturnCallback(function ($class) {
        if (is_subclass_of($class, 'Drupal\\Core\\DependencyInjection\\ContainerInjectionInterface')) {
            return $class::create(new ContainerBuilder());
        }
        else {
            return new $class();
        }
    });
    return $class_resolver;
}

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