function RulesIntegrationTestBase::setUp
Overrides UnitTestCase::setUp
22 calls to RulesIntegrationTestBase::setUp()
- AnnotationProcessingTest::setUp in tests/
src/ Unit/ Integration/ Engine/ AnnotationProcessingTest.php - BanIpTest::setUp in tests/
src/ Unit/ Integration/ RulesAction/ BanIpTest.php - DataCalculateValueTest::setUp in tests/
src/ Unit/ Integration/ RulesAction/ DataCalculateValueTest.php - DataComparisonTest::setUp in tests/
src/ Unit/ Integration/ Condition/ DataComparisonTest.php - DataConvertTest::setUp in tests/
src/ Unit/ Integration/ RulesAction/ DataConvertTest.php
22 methods override RulesIntegrationTestBase::setUp()
- AnnotationProcessingTest::setUp in tests/
src/ Unit/ Integration/ Engine/ AnnotationProcessingTest.php - BanIpTest::setUp in tests/
src/ Unit/ Integration/ RulesAction/ BanIpTest.php - DataCalculateValueTest::setUp in tests/
src/ Unit/ Integration/ RulesAction/ DataCalculateValueTest.php - DataComparisonTest::setUp in tests/
src/ Unit/ Integration/ Condition/ DataComparisonTest.php - DataConvertTest::setUp in tests/
src/ Unit/ Integration/ RulesAction/ DataConvertTest.php
File
-
tests/
src/ Unit/ Integration/ RulesIntegrationTestBase.php, line 165
Class
- RulesIntegrationTestBase
- Base class for Rules integration tests.
Namespace
Drupal\Tests\rules\Unit\IntegrationCode
protected function setUp() : void {
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) {
if (isset($enabled_modules[$arguments[0]])) {
return [
$arguments[0],
$enabled_modules[$arguments[0]],
];
}
// Handle case where a plugin provider module is not enabled.
return [
$arguments[0],
FALSE,
];
});
// We 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());
$uuid_service = new Php();
$this->rulesExpressionManager = new ExpressionManager($this->namespaces, $this->moduleHandler
->reveal(), $uuid_service);
$this->classResolver = $this->prophesize(ClassResolverInterface::class);
$this->typedDataManager = new TypedDataManager($this->namespaces, $this->cacheBackend, $this->moduleHandler
->reveal(), $this->classResolver
->reveal());
if (version_compare(\Drupal::VERSION, '10.2') >= 0) {
// @phpcs:ignore Drupal.Classes.FullyQualifiedNamespace.UseStatementMissing
$this->fieldTypeCategoryManager = new \Drupal\Core\Field\FieldTypeCategoryManager($this->root, $this->moduleHandler
->reveal(), $this->cacheBackend);
}
$this->rulesDataProcessorManager = new DataProcessorManager($this->namespaces, $this->moduleHandler
->reveal());
$this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
$this->entityTypeManager
->getDefinitions()
->willReturn([]);
// Setup a rules_component storage mock which returns nothing by default.
$storage = $this->prophesize(ConfigEntityStorageInterface::class);
$storage->loadMultiple(NULL)
->willReturn([]);
$this->entityTypeManager
->getStorage('rules_component')
->willReturn($storage->reveal());
$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->messenger = new TestMessenger();
$this->dataFilterManager = new DataFilterManager($this->namespaces, $this->cacheBackend, $this->moduleHandler
->reveal());
$this->placeholderResolver = new PlaceholderResolver($this->dataFetcher, $this->dataFilterManager);
// Mock the Rules debug logger service and make it return our mocked logger.
$this->logger = $this->prophesize(LoggerChannelInterface::class);
$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('logger.channel.rules_debug', $this->logger
->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('messenger', $this->messenger);
if (version_compare(\Drupal::VERSION, '10.2') >= 0) {
$container->set('plugin.manager.field.field_type_category', $this->fieldTypeCategoryManager);
}
$container->set('typed_data_manager', $this->typedDataManager);
$container->set('string_translation', $this->getStringTranslationStub());
$container->set('uuid', $uuid_service);
$container->set('typed_data.data_fetcher', $this->dataFetcher);
$container->set('typed_data.placeholder_resolver', $this->placeholderResolver);
// The new ReverseContainer service needs to be present to prevent massive
// unit test failures.
// @see https://www.drupal.org/project/rules/issues/3346846
$container->set('Drupal\\Component\\DependencyInjection\\ReverseContainer', new ReverseContainer($container));
\Drupal::setContainer($container);
$this->container = $container;
}