You are here

public function FeaturesManagerTest::setUp in Features 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Unit/FeaturesManagerTest.php \Drupal\Tests\features\Unit\FeaturesManagerTest::setUp()

Overrides UnitTestCase::setUp

File

tests/src/Unit/FeaturesManagerTest.php, line 100

Class

FeaturesManagerTest
@coversDefaultClass Drupal\features\FeaturesManager @group features

Namespace

Drupal\Tests\features\Unit

Code

public function setUp() {
  parent::setUp();
  $container = new ContainerBuilder();
  $container
    ->set('string_translation', $this
    ->getStringTranslationStub());
  $container
    ->set('app.root', $this->root);

  // Since in Drupal 8.3 the "\Drupal::installProfile()" was introduced
  // then we have to spoof a value for the "install_profile" parameter
  // because it will be used by "ExtensionInstallStorage" class, which
  // extends the "FeaturesInstallStorage".
  // @see \Drupal\features\FeaturesConfigInstaller::__construct()
  $container
    ->setParameter('install_profile', '');
  \Drupal::setContainer($container);
  $entity_type = $this
    ->createMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
  $entity_type
    ->expects($this
    ->any())
    ->method('getConfigPrefix')
    ->willReturn('custom');
  $entity_type
    ->expects($this
    ->any())
    ->method('getProvider')
    ->willReturn('my_module');
  $this->entityTypeManager = $this
    ->createMock('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface');
  $this->entityTypeManager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->willReturn($entity_type);
  $this->configFactory = $this
    ->createMock(ConfigFactoryInterface::class);
  $this->configStorage = $this
    ->createMock(StorageInterface::class);
  $this->configManager = $this
    ->createMock(ConfigManagerInterface::class);
  $this->moduleHandler = $this
    ->createMock(ModuleHandlerInterface::class);

  // getModuleList should return an array of extension objects.
  // but we just need  isset($module_list[$provider]) for
  // ::getConfigDependency() and ::assignInterPackageDependencies().
  $this->moduleHandler
    ->expects($this
    ->any())
    ->method('getModuleList')
    ->willReturn([
    'my_module' => TRUE,
    'example' => TRUE,
    'example3' => TRUE,
    'my_feature' => TRUE,
    'my_other_feature' => TRUE,
    'package' => TRUE,
    'package2' => TRUE,
    'package3' => TRUE,
    'giraffe_package' => TRUE,
    'giraffe_package2' => TRUE,
    'giraffe_package3' => TRUE,
  ]);
  $this->configReverter = $this
    ->createMock(ConfigRevertInterface::class);
  $this->configReverter
    ->expects($this
    ->any())
    ->method('import')
    ->willReturn(TRUE);
  $this->configReverter
    ->expects($this
    ->any())
    ->method('revert')
    ->willReturn(TRUE);
  $this->moduleExtensionList = $this
    ->createMock(ModuleExtensionList::class);
  $this->moduleExtensionList
    ->expects($this
    ->any())
    ->method('getPath')
    ->willReturn('some/path');
  $this->moduleExtensionList
    ->expects($this
    ->any())
    ->method('getExtensionInfo')
    ->willReturn([]);
  $this->featuresManager = new FeaturesManager($this->root, $this->entityTypeManager, $this->configFactory, $this->configStorage, $this->configManager, $this->moduleHandler, $this->configReverter, $this->moduleExtensionList);
}