You are here

protected function RecursiveContextualValidatorTest::setUp in Drupal 8

Same name in this branch
  1. 8 core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::setUp()
  2. 8 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/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php, line 59
Contains \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest.

Class

RecursiveContextualValidatorTest
@coversDefaultClass \Drupal\Core\TypedData\Validation\RecursiveContextualValidator @group typedData

Namespace

Drupal\Tests\Core\TypedData

Code

protected function setUp() {
  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);
}