Beispiel #1
0
 /**
  * @covers ::__construct
  */
 public function setUp()
 {
     parent::setUp();
     $this->contextHandler = $this->prophesize(ContextHandlerInterface::class);
     $this->entityType = $this->prophesize(EntityTypeInterface::class);
     $module_handler = $this->prophesize(ModuleHandlerInterface::class);
     $module_handler->invokeAll(Argument::cetera())->willReturn([]);
     $this->pageAccess = new PageAccess($this->entityType->reveal(), $this->contextHandler->reveal());
     $this->pageAccess->setModuleHandler($module_handler->reveal());
 }
 /**
  * @covers ::__construct
  */
 public function setUp()
 {
     parent::setUp();
     $this->contextHandler = $this->prophesize(ContextHandlerInterface::class);
     $this->entityType = $this->prophesize(EntityTypeInterface::class);
     $module_handler = $this->prophesize(ModuleHandlerInterface::class);
     $module_handler->invokeAll(Argument::cetera())->willReturn([]);
     $this->pageAccess = new PageAccess($this->entityType->reveal(), $this->contextHandler->reveal());
     $this->pageAccess->setModuleHandler($module_handler->reveal());
     $this->cacheContextsManager = $this->prophesize(CacheContextsManager::class);
     $container = new ContainerBuilder();
     $container->set('cache_contexts_manager', $this->cacheContextsManager->reveal());
     \Drupal::setContainer($container);
 }
 /**
  * Returns a mock entity for testing.
  *
  * @param string $class
  *   The class name to mock. Should be \Drupal\Core\Entity\Entity or a
  *   subclass.
  * @param array $values
  *   An array of entity values to construct the mock entity with.
  * @param array $methods
  *   (optional) An array of additional methods to mock on the entity object.
  *   The getEntityType() and entityManager() methods are always mocked.
  *
  * @return \Drupal\Core\Entity\Entity|\PHPUnit_Framework_MockObject_MockObject
  */
 protected function getEntity($class, array $values, array $methods = [])
 {
     $methods = array_merge($methods, ['getEntityType', 'entityManager']);
     // 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, $this->entityTypeId])->setMethods($methods)->getMockForAbstractClass();
     $this->entityType = $this->prophesize(EntityTypeInterface::class);
     $this->entityType->getLinkTemplates()->willReturn([]);
     $this->entityType->getKey('langcode')->willReturn(FALSE);
     $entity->method('getEntityType')->willReturn($this->entityType->reveal());
     $this->entityManager = $this->prophesize(EntityManagerInterface::class);
     $entity->method('entityManager')->willReturn($this->entityManager->reveal());
     return $entity;
 }