You are here

protected function UnitTestCase::getClassResolverStub in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::getClassResolverStub()
  2. 9 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 245

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;
}