function DateTest::setUp

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::setUp()
  2. 10 core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::setUp()
  3. 9 core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::setUp()
  4. 8.9.x core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Datetime/DateTest.php, line 77

Class

DateTest
Tests Drupal\Core\Datetime\DateFormatter.

Namespace

Drupal\Tests\Core\Datetime

Code

protected function setUp() : void {
  parent::setUp();
  $entity_storage = $this->createStub(EntityStorageInterface::class);
  $this->entityTypeManager = $this->createStub(EntityTypeManagerInterface::class);
  $this->entityTypeManager
    ->method('getStorage')
    ->willReturn($entity_storage);
  $this->languageManager = $this->createStub(LanguageManagerInterface::class);
  $this->languageManager
    ->method('getCurrentLanguage')
    ->willReturn(new Language([
    'id' => $this->randomMachineName(2),
  ]));
  $this->stringTranslation = $this->createStub(TranslationInterface::class);
  $this->requestStack = $this->createStub(RequestStack::class);
  $config_factory = $this->getConfigFactoryStub([
    'system.date' => [
      'country' => [
        'default' => 'GB',
      ],
    ],
  ]);
  $container = new ContainerBuilder();
  $container->set('config.factory', $config_factory);
  $container->set('string_translation', $this->getStringTranslationStub());
  $container->set('language_manager', $this->languageManager);
  \Drupal::setContainer($container);
  $this->dateFormatter = new DateFormatter($this->entityTypeManager, $this->languageManager, $this->stringTranslation, $this->getConfigFactoryStub(), $this->requestStack);
}

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