function EntityUnitTest::setUpEntity
Sets up the entity under test.
Parameters
int $getBundleListCacheTagsCallsCount: The number of expected calls to the EntityTypeInterface::getBundleListCacheTags() method.
int $getDefinitionCallsCount: The number of expected calls to the EntityTypeManagerInterface::getDefinition() method.
int $getLanguageCallsCount: The number of expected calls to the LanguageManagerInterface::getLanguage() method.
28 calls to EntityUnitTest::setUpEntity()
- EntityUnitTest::setupTestLoad in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUnitTest.php - Setup for the tests of the ::load() method.
- EntityUnitTest::testAccess in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUnitTest.php - Tests access.
- EntityUnitTest::testBundle in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUnitTest.php - Tests bundle.
- EntityUnitTest::testCacheContexts in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUnitTest.php - Tests cache contexts.
- EntityUnitTest::testCacheMaxAge in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUnitTest.php - Tests cache max age.
File
-
core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUnitTest.php, line 113
Class
Namespace
Drupal\Tests\Core\EntityCode
protected function setUpEntity(int $getBundleListCacheTagsCallsCount, int $getDefinitionCallsCount, int $getLanguageCallsCount) : void {
$this->entityType = $this->createMock(EntityTypeInterface::class);
$this->entityType
->method('getListCacheTags')
->willReturn([
$this->entityTypeId . '_list',
]);
$this->entityType
->expects($this->exactly($getBundleListCacheTagsCallsCount))
->method('getBundleListCacheTags')
->with($this->entityTypeId)
->willReturn([
$this->entityTypeId . '_list:' . $this->entityTypeId,
]);
$this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
$this->entityTypeManager
->expects($this->exactly($getDefinitionCallsCount))
->method('getDefinition')
->with($this->entityTypeId)
->willReturn($this->entityType);
$this->uuid = $this->createStub(UuidInterface::class);
$this->languageManager = $this->createMock(LanguageManagerInterface::class);
$this->languageManager
->expects($this->exactly($getLanguageCallsCount))
->method('getLanguage')
->with('en')
->willReturn(new Language([
'id' => 'en',
]));
$this->cacheTagsInvalidator = $this->prophesize(CacheTagsInvalidator::class);
$container = new ContainerBuilder();
$container->set('entity_type.manager', $this->entityTypeManager);
$container->set('uuid', $this->uuid);
$container->set('language_manager', $this->languageManager);
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator
->reveal());
\Drupal::setContainer($container);
$this->entity = new StubEntityBase($this->values, $this->entityTypeId);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.