function ReflectionFactoryTest::testCreateInstance
Same name in other branches
- 9 core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php \Drupal\Tests\Component\Plugin\Factory\ReflectionFactoryTest::testCreateInstance()
- 8.9.x core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php \Drupal\Tests\Component\Plugin\Factory\ReflectionFactoryTest::testCreateInstance()
- 10 core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php \Drupal\Tests\Component\Plugin\Factory\ReflectionFactoryTest::testCreateInstance()
@covers ::createInstance @dataProvider providerGetInstanceArguments
File
-
core/
tests/ Drupal/ Tests/ Component/ Plugin/ Factory/ ReflectionFactoryTest.php, line 83
Class
- ReflectionFactoryTest
- @group Plugin @coversDefaultClass \Drupal\Component\Plugin\Factory\ReflectionFactory
Namespace
Drupal\Tests\Component\Plugin\FactoryCode
public function testCreateInstance($expected, $reflector_name, $plugin_id, $plugin_definition, $configuration) : void {
// Create a mock DiscoveryInterface which can return our plugin definition.
$mock_discovery = $this->getMockBuilder('Drupal\\Component\\Plugin\\Discovery\\DiscoveryInterface')
->onlyMethods([
'getDefinition',
'getDefinitions',
'hasDefinition',
])
->getMock();
$mock_discovery->expects($this->never())
->method('getDefinitions');
$mock_discovery->expects($this->never())
->method('hasDefinition');
$mock_discovery->expects($this->once())
->method('getDefinition')
->willReturn($plugin_definition);
// Create a stub ReflectionFactory object. We use StubReflectionFactory
// because createInstance() has a dependency on a static method.
// StubReflectionFactory overrides this static method.
$reflection_factory = new StubReflectionFactory($mock_discovery);
// Finally test that createInstance() returns an object of the class we
// want.
$this->assertInstanceOf($reflector_name, $reflection_factory->createInstance($plugin_id));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.