You are here

class StubReflectionFactory in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php \Drupal\Tests\Component\Plugin\Factory\StubReflectionFactory

Override ReflectionFactory because ::createInstance() calls a static method.

We have to override getPluginClass so that we can stub out its return value.

Hierarchy

Expanded class hierarchy of StubReflectionFactory

File

core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php, line 143
Contains \Drupal\Tests\Component\Plugin\Factory\ReflectionFactoryTest.

Namespace

Drupal\Tests\Component\Plugin\Factory
View source
class StubReflectionFactory extends ReflectionFactory {

  /**
   * {@inheritdoc}
   */
  public static function getPluginClass($plugin_id, $plugin_definition = NULL, $required_interface = NULL) {

    // Return the class name from the plugin definition.
    return $plugin_definition[$plugin_id]['class'];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DefaultFactory::$discovery protected property The object that retrieves the definitions of the plugins that this factory instantiates.
DefaultFactory::$interface protected property Defines an interface each plugin should implement.
DefaultFactory::__construct public function Constructs a Drupal\Component\Plugin\Factory\DefaultFactory object.
ReflectionFactory::createInstance public function Creates a pre-configured instance of a plugin. Overrides DefaultFactory::createInstance
ReflectionFactory::getInstanceArguments protected function Inspects the plugin class and build a list of arguments for the constructor.
StubReflectionFactory::getPluginClass public static function Finds the class relevant for a given plugin. Overrides DefaultFactory::getPluginClass