function EntityTypeRepositoryTest::setUpEntityTypeDefinitions
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php \Drupal\Tests\Core\Entity\EntityTypeRepositoryTest::setUpEntityTypeDefinitions()
- 10 core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php \Drupal\Tests\Core\Entity\EntityTypeRepositoryTest::setUpEntityTypeDefinitions()
- 11.x core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php \Drupal\Tests\Core\Entity\EntityTypeRepositoryTest::setUpEntityTypeDefinitions()
Sets up the entity type manager to be tested.
Parameters
\Drupal\Core\Entity\EntityTypeInterface[]|\Prophecy\Prophecy\ProphecyInterface[] $definitions: (optional) An array of entity type definitions.
4 calls to EntityTypeRepositoryTest::setUpEntityTypeDefinitions()
- EntityTypeRepositoryTest::testGetEntityTypeFromClass in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityTypeRepositoryTest.php - @covers ::getEntityTypeFromClass
- EntityTypeRepositoryTest::testGetEntityTypeFromClassAmbiguous in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityTypeRepositoryTest.php - @covers ::getEntityTypeFromClass
- EntityTypeRepositoryTest::testGetEntityTypeFromClassNoMatch in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityTypeRepositoryTest.php - @covers ::getEntityTypeFromClass
- EntityTypeRepositoryTest::testGetEntityTypeLabels in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityTypeRepositoryTest.php - Tests the getEntityTypeLabels() method.
File
-
core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityTypeRepositoryTest.php, line 52
Class
- EntityTypeRepositoryTest
- @coversDefaultClass \Drupal\Core\Entity\EntityTypeRepository @group Entity
Namespace
Drupal\Tests\Core\EntityCode
protected function setUpEntityTypeDefinitions($definitions = []) {
foreach ($definitions as $key => $entity_type) {
// \Drupal\Core\Entity\EntityTypeInterface::getLinkTemplates() is called
// by \Drupal\Core\Entity\EntityTypeManager::processDefinition() so it must
// always be mocked.
$entity_type->getLinkTemplates()
->willReturn([]);
// Give the entity type a legitimate class to return.
$entity_type->getClass()
->willReturn(EntityInterface::class);
$definitions[$key] = $entity_type->reveal();
}
$this->entityTypeManager
->getDefinition(Argument::cetera())
->will(function ($args) use ($definitions) {
$entity_type_id = $args[0];
$exception_on_invalid = $args[1];
if (isset($definitions[$entity_type_id])) {
return $definitions[$entity_type_id];
}
elseif (!$exception_on_invalid) {
return NULL;
}
else {
throw new PluginNotFoundException($entity_type_id);
}
});
$this->entityTypeManager
->getDefinitions()
->willReturn($definitions);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.