/**
  * Sets up the entity type manager to be tested.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface[]|\Prophecy\Prophecy\ProphecyInterface[] $definitions
  *   (optional) An array of entity type definitions.
  */
 protected function setUpEntityTypeDefinitions($definitions = [])
 {
     $class = $this->getMockClass(EntityInterface::class);
     foreach ($definitions as $key => $entity_type) {
         // \Drupal\Core\Entity\EntityTypeInterface::getLinkTemplates() is called
         // by \Drupal\Core\Entity\EntityManager::processDefinition() so it must
         // always be mocked.
         $entity_type->getLinkTemplates()->willReturn([]);
         // Give the entity type a legitimate class to return.
         $entity_type->getClass()->willReturn($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);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
     $this->entityTypeManager->getDefinitions()->willReturn([$this->entityTypeId => '']);
     $this->processPlugin = new LinkUri([], 'link_uri', [], $this->entityTypeManager->reveal());
     // Url::fromInternalUri() accesses the path validator from the global
     // container.
     // @see \Drupal\Core\Url::fromInternalUri()
     $this->pathValidator = $this->prophesize(PathValidator::class);
     $container = new ContainerBuilder();
     $container->set('path.validator', $this->pathValidator->reveal());
     \Drupal::setContainer($container);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $container = new ContainerBuilder();
     // Register plugin managers used by Rules, but mock some unwanted
     // dependencies requiring more stuff to loaded.
     $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
     // Set all the modules as being existent.
     $this->enabledModules = new \ArrayObject();
     $this->enabledModules['rules'] = TRUE;
     $this->enabledModules['rules_test'] = TRUE;
     $enabled_modules = $this->enabledModules;
     $this->moduleHandler->moduleExists(Argument::type('string'))->will(function ($arguments) use($enabled_modules) {
         return [$arguments[0], $enabled_modules[$arguments[0]]];
     });
     // Wed don't care about alter() calls on the module handler.
     $this->moduleHandler->alter(Argument::any(), Argument::any(), Argument::any(), Argument::any())->willReturn(NULL);
     $this->cacheBackend = new NullBackend('rules');
     $rules_directory = __DIR__ . '/../../..';
     $this->namespaces = new \ArrayObject(['Drupal\\rules' => $rules_directory . '/src', 'Drupal\\rules_test' => $rules_directory . '/tests/modules/rules_test/src', 'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData', 'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation']);
     $this->actionManager = new RulesActionManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal());
     $this->conditionManager = new ConditionManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal());
     $this->rulesExpressionManager = new ExpressionManager($this->namespaces, $this->moduleHandler->reveal());
     $this->classResolver = $this->prophesize(ClassResolverInterface::class);
     $this->typedDataManager = new TypedDataManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal(), $this->classResolver->reveal());
     $this->rulesDataProcessorManager = new DataProcessorManager($this->namespaces, $this->moduleHandler->reveal());
     $this->aliasManager = $this->prophesize(AliasManagerInterface::class);
     // Keep the deprecated entity manager around because it is still used in a
     // few places.
     $this->entityManager = $this->prophesize(EntityManagerInterface::class);
     $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
     $this->entityTypeManager->getDefinitions()->willReturn([]);
     $this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class);
     $this->entityFieldManager->getBaseFieldDefinitions()->willReturn([]);
     $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
     $this->entityTypeBundleInfo->getBundleInfo()->willReturn([]);
     $this->dataFetcher = new DataFetcher();
     $this->dataFilterManager = new DataFilterManager($this->namespaces, $this->moduleHandler->reveal());
     $this->placeholderResolver = new PlaceholderResolver($this->dataFetcher, $this->dataFilterManager);
     $container->set('entity.manager', $this->entityManager->reveal());
     $container->set('entity_type.manager', $this->entityTypeManager->reveal());
     $container->set('entity_field.manager', $this->entityFieldManager->reveal());
     $container->set('entity_type.bundle.info', $this->entityTypeBundleInfo->reveal());
     $container->set('context.repository', new LazyContextRepository($container, []));
     $container->set('path.alias_manager', $this->aliasManager->reveal());
     $container->set('plugin.manager.rules_action', $this->actionManager);
     $container->set('plugin.manager.condition', $this->conditionManager);
     $container->set('plugin.manager.rules_expression', $this->rulesExpressionManager);
     $container->set('plugin.manager.rules_data_processor', $this->rulesDataProcessorManager);
     $container->set('typed_data_manager', $this->typedDataManager);
     $container->set('string_translation', $this->getStringTranslationStub());
     $container->set('uuid', new Php());
     $container->set('typed_data.data_fetcher', $this->dataFetcher);
     $container->set('typed_data.placeholder_resolver', $this->placeholderResolver);
     \Drupal::setContainer($container);
     $this->container = $container;
 }