function DateTest::setUp

Same name and namespace in other branches
  1. 8.9.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. 11.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 64

Class

DateTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Datetime%21DateFormatter.php/class/DateFormatter/9" title="Provides a service to handle various date related functionality." class="local">\Drupal\Core\Datetime\DateFormatter</a> @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();
}

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