function ConfigEntityBaseUnitTest::getMockEntityWithPluginCollection
Get a mock entity with a plugin collection.
Parameters
\Drupal\Component\Plugin\PluginBase $plugin: A plugin the entity will have a collection containing.
Return value
\Drupal\Core\Config\Entity\ConfigEntityBase|\PHPUnit\Framework\MockObject\MockObject A mock entity with a plugin collection containing the given plugin.
1 call to ConfigEntityBaseUnitTest::getMockEntityWithPluginCollection()
- ConfigEntityBaseUnitTest::testOnDependencyRemovalWithPluginCollections in core/
tests/ Drupal/ Tests/ Core/ Config/ Entity/ ConfigEntityBaseUnitTest.php - Test dependency removal on entities with plugin collections.
File
-
core/
tests/ Drupal/ Tests/ Core/ Config/ Entity/ ConfigEntityBaseUnitTest.php, line 468
Class
Namespace
Drupal\Tests\Core\Config\EntityCode
protected function getMockEntityWithPluginCollection(PluginBase $plugin) : ConfigEntityBase|MockObject {
$values = [];
$entity = $this->getMockBuilder('\\Drupal\\Tests\\Core\\Config\\Entity\\Fixtures\\ConfigEntityBaseWithPluginCollections')
->setConstructorArgs([
$values,
$this->entityTypeId,
])
->onlyMethods([
'getPluginCollections',
])
->getMock();
// Create a plugin collection to contain the instance.
$pluginCollection = $this->getMockBuilder('\\Drupal\\Core\\Plugin\\DefaultLazyPluginCollection')
->disableOriginalConstructor()
->onlyMethods([
'get',
])
->getMock();
$pluginCollection->expects($this->atLeastOnce())
->method('get')
->with($plugin->getPluginId())
->willReturn($plugin);
$pluginCollection->addInstanceId($plugin->getPluginId());
// Return the mocked plugin collection.
$entity->expects($this->atLeastOnce())
->method('getPluginCollections')
->willReturn([
$pluginCollection,
]);
return $entity;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.