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. 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 61

Class

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

Namespace

Drupal\Tests\Core\Datetime

Code

protected function setUp() {
    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,
    ])
        ->setMethods([
        'formatDiff',
    ])
        ->getMock();
}

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