protected function CreateMembershipTest::setUp in Organic groups 8
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ CreateMembershipTest.php, line 101
Class
- CreateMembershipTest
- Tests create membership helper function.
Namespace
Drupal\Tests\og\UnitCode
protected function setUp() : void {
parent::setUp();
$this->entityTypeId = $this
->randomMachineName();
$this->bundle = $this
->randomMachineName();
$this->entityStorage = $this
->prophesize(EntityStorageInterface::class);
$this->entityTypeManager = $this
->prophesize(EntityTypeManagerInterface::class);
$this->entityTypeRepository = $this
->prophesize(EntityTypeRepositoryInterface::class);
$this->groupAudienceHelper = $this
->prophesize(OgGroupAudienceHelperInterface::class);
$this->staticCache = $this
->prophesize(MemoryCacheInterface::class);
$this->entityTypeManager
->getStorage('og_membership')
->willReturn($this->entityStorage
->reveal());
$this->entityTypeRepository
->getEntityTypeFromClass('Drupal\\og\\Entity\\OgMembership')
->willReturn('og_membership');
// Create a mocked Og Membership entity.
/** @var \Drupal\og\OgMembershipInterface|\Prophecy\Prophecy\ObjectProphecy $membership_entity */
$membership_entity = $this
->prophesize(OgMembershipInterface::class);
$this->entityStorage
->create(Argument::type('array'))
->willReturn($membership_entity
->reveal());
// Create a mocked test group.
$this->group = $this
->prophesize(ContentEntityInterface::class);
// Create a mocked test user.
$this->user = $this
->prophesize(UserInterface::class);
$membership_entity
->setOwner($this->user)
->willReturn($membership_entity
->reveal());
$membership_entity
->setGroup($this->group)
->willReturn($membership_entity
->reveal());
$container = new ContainerBuilder();
$container
->set('entity_type.manager', $this->entityTypeManager
->reveal());
$container
->set('entity_type.repository', $this->entityTypeRepository
->reveal());
\Drupal::setContainer($container);
}