class StubReflectionFactory

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php \Drupal\Tests\Component\Plugin\Factory\StubReflectionFactory
  2. 8.9.x core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php \Drupal\Tests\Component\Plugin\Factory\StubReflectionFactory
  3. 11.x 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 137

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

Title Sort descending Modifiers Object type Summary Overriden Title
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 plugin instance based on the provided ID and configuration. 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

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