You are here

protected function ContextDefinitionIsSatisfiedTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php \Drupal\Tests\Core\Plugin\Context\ContextDefinitionIsSatisfiedTest::setUp()
  2. 10 core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php \Drupal\Tests\Core\Plugin\Context\ContextDefinitionIsSatisfiedTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php, line 28

Class

ContextDefinitionIsSatisfiedTest
@coversDefaultClass \Drupal\Core\Plugin\Context\ContextDefinition @group Plugin

Namespace

Drupal\Tests\Core\Plugin\Context

Code

protected function setUp() : void {
  parent::setUp();
  $namespaces = new \ArrayObject([
    'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
    'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
    'Drupal\\Tests\\Core\\Plugin\\Fixtures' => $this->root . '/core/tests/Drupal/Tests/Core/Plugin/Fixtures',
  ]);
  $cache_backend = new NullBackend('cache');
  $module_handler = $this
    ->prophesize(ModuleHandlerInterface::class);
  $class_resolver = $this
    ->prophesize(ClassResolverInterface::class);
  $class_resolver
    ->getInstanceFromDefinition(Argument::type('string'))
    ->will(function ($arguments) {
    $class_name = $arguments[0];
    return new $class_name();
  });
  $type_data_manager = new TypedDataManager($namespaces, $cache_backend, $module_handler
    ->reveal(), $class_resolver
    ->reveal());
  $type_data_manager
    ->setValidationConstraintManager(new ConstraintManager($namespaces, $cache_backend, $module_handler
    ->reveal()));
  $string_translation = new TranslationManager(new LanguageDefault([]));
  $container = new ContainerBuilder();
  $container
    ->set('typed_data_manager', $type_data_manager);
  $container
    ->set('string_translation', $string_translation);
  \Drupal::setContainer($container);
}