function EntityUrlTest::getEntity
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::getEntity()
- 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::getEntity()
- 10 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::getEntity()
Returns a mock entity for testing.
Parameters
class-string<\Drupal\Tests\Core\Entity\StubEntityBase> $class: The class name to mock. Should be \Drupal\Tests\Core\Entity\StubEntityBase or a subclass.
array<string,int|string> $values: An array of entity values to construct the mock entity with.
list<string> $methods: (optional) A list of additional methods to mock on the entity object. The getEntityType() and entityTypeBundleInfo() methods are always mocked.
Return value
\Drupal\Tests\Core\Entity\StubEntityBase&\PHPUnit\Framework\MockObject\MockObject
10 calls to EntityUrlTest::getEntity()
- EntityUrlTest::testToUrlDefaultException in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php - Tests the toUrl() method without specifying the $rel parameter.
- EntityUrlTest::testToUrlDefaultFallback in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php - Tests the toUrl() method without specifying the $rel parameter.
- EntityUrlTest::testToUrlLinkTemplateAddForm in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php - Tests the toUrl() method with the 'revision' link template.
- EntityUrlTest::testToUrlLinkTemplateNoId in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php - Tests the toUrl() method with link templates without an entity ID.
- EntityUrlTest::testToUrlLinkTemplateRevision in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php - Tests the toUrl() method with the 'revision' link template.
File
-
core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php, line 476
Class
- EntityUrlTest
- Tests URL handling of the \Drupal\Core\Entity\EntityBase class.
Namespace
Drupal\Tests\Core\EntityCode
protected function getEntity(string $class, array $values, array $methods = []) : StubEntityBase&MockObject {
$methods = array_merge($methods, [
'getEntityType',
'entityTypeBundleInfo',
]);
// Prophecy does not allow prophesizing abstract classes while actually
// calling their code. We use Prophecy below because that allows us to
// add method prophecies later while still revealing the prophecy now.
$entity = $this->getMockBuilder($class)
->setConstructorArgs([
$values,
static::ENTITY_TYPE_ID,
])
->onlyMethods($methods)
->getMock();
$this->entityType = $this->prophesize(EntityTypeInterface::class);
$this->entityType
->getLinkTemplates()
->willReturn([]);
$this->entityType
->getKey('langcode')
->willReturn(FALSE);
$entity->method('getEntityType')
->willReturn($this->entityType
->reveal());
$this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
$entity->method('entityTypeBundleInfo')
->willReturn($this->entityTypeBundleInfo
->reveal());
return $entity;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.