You are here

protected function DateTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::setUp()
  2. 9 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 61

Class

DateTest
@coversDefaultClass \Drupal\Core\Datetime\DateFormatter @group Datetime

Namespace

Drupal\Tests\Core\Datetime

Code

protected function setUp() : void {
  parent::setUp();
  $entity_storage = $this
    ->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');
  $this->entityTypeManager = $this
    ->createMock('Drupal\\Core\\Entity\\EntityTypeManagerInterface');
  $this->entityTypeManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->with('date_format')
    ->willReturn($entity_storage);
  $this->languageManager = $this
    ->createMock('Drupal\\Core\\Language\\LanguageManagerInterface');
  $this->stringTranslation = $this
    ->createMock('Drupal\\Core\\StringTranslation\\TranslationInterface');
  $this->requestStack = $this
    ->createMock('Symfony\\Component\\HttpFoundation\\RequestStack');
  $config_factory = $this
    ->getConfigFactoryStub([
    'system.date' => [
      'country' => [
        'default' => 'GB',
      ],
    ],
  ]);
  $container = new ContainerBuilder();
  $container
    ->set('config.factory', $config_factory);
  $container
    ->set('string_translation', $this
    ->getStringTranslationStub());
  \Drupal::setContainer($container);
  $this->dateFormatter = new DateFormatter($this->entityTypeManager, $this->languageManager, $this->stringTranslation, $this
    ->getConfigFactoryStub(), $this->requestStack);
  $this->dateFormatterStub = $this
    ->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatter')
    ->setConstructorArgs([
    $this->entityTypeManager,
    $this->languageManager,
    $this->stringTranslation,
    $this
      ->getConfigFactoryStub(),
    $this->requestStack,
  ])
    ->onlyMethods([
    'formatDiff',
  ])
    ->getMock();
}