function RecursiveContextualValidatorTest::setUp

Same name in this branch
  1. 11.x core/tests/Drupal/KernelTests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\KernelTests\Core\TypedData\RecursiveContextualValidatorTest::setUp()
Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\KernelTests\Core\TypedData\RecursiveContextualValidatorTest::setUp()
  2. 9 core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::setUp()
  3. 8.9.x core/tests/Drupal/KernelTests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\KernelTests\Core\TypedData\RecursiveContextualValidatorTest::setUp()
  4. 8.9.x core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::setUp()
  5. 10 core/tests/Drupal/KernelTests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\KernelTests\Core\TypedData\RecursiveContextualValidatorTest::setUp()
  6. 10 core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php, line 57

Class

RecursiveContextualValidatorTest
@coversDefaultClass \Drupal\Core\TypedData\Validation\RecursiveContextualValidator[[api-linebreak]] @group TypedData

Namespace

Drupal\Tests\Core\TypedData

Code

protected function setUp() : void {
  parent::setUp();
  $cache_backend = new NullBackend('cache');
  $namespaces = new \ArrayObject([
    'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
    'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
  ]);
  $module_handler = $this->getMockBuilder('Drupal\\Core\\Extension\\ModuleHandlerInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $class_resolver = $this->getMockBuilder('Drupal\\Core\\DependencyInjection\\ClassResolverInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $this->typedDataManager = new TypedDataManager($namespaces, $cache_backend, $module_handler, $class_resolver);
  $this->typedDataManager
    ->setValidationConstraintManager(new ConstraintManager($namespaces, $cache_backend, $module_handler));
  // Typed data definitions access the manager in the container.
  $container = new ContainerBuilder();
  $container->set('typed_data_manager', $this->typedDataManager);
  \Drupal::setContainer($container);
  $translator = $this->createMock('Drupal\\Core\\Validation\\TranslatorInterface');
  $translator->expects($this->any())
    ->method('trans')
    ->willReturnCallback(function ($id) {
    return $id;
  });
  $this->contextFactory = new ExecutionContextFactory($translator);
  $this->validatorFactory = new ConstraintValidatorFactory();
  $this->recursiveValidator = new RecursiveValidator($this->contextFactory, $this->validatorFactory, $this->typedDataManager);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.