You are here

protected function UnitTestCase::getClassResolverStub in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 256
Contains \Drupal\Tests\UnitTestCase.

Class

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

Namespace

Drupal\Tests

Code

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