function DateTest::setUp

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::setUp()
  2. 8.9.x core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::setUp()
  3. 10 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 68

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->languageManager
        ->expects($this->any())
        ->method('getCurrentLanguage')
        ->willReturn(new Language([
        'id' => $this->randomMachineName(2),
    ]));
    $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());
    $container->set('language_manager', $this->languageManager);
    \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();
}

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