You are here

public static function MockService::getFactoryMethod in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\MockService::getFactoryMethod()
  2. 9 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\MockService::getFactoryMethod()

Provides a factory method to get a service.

Parameters

string $class: The class name of the class to instantiate

array $arguments: (optional) Arguments to pass to the new class.

Return value

object The instantiated service object.

File

core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php, line 1179
Contains \Drupal\Tests\Component\DependencyInjection\ContainerTest.

Class

MockService
Helper class to test Container::get() method.

Namespace

Drupal\Tests\Component\DependencyInjection

Code

public static function getFactoryMethod($class, $arguments = []) {
  $r = new \ReflectionClass($class);
  $service = $r
    ->getConstructor() === NULL ? $r
    ->newInstance() : $r
    ->newInstanceArgs($arguments);
  return $service;
}