You are here

protected function DateRecurRlInterpretationUnitTest::setUp in Recurring Dates Field 3.0.x

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/DateRecurRlInterpretationUnitTest.php \Drupal\Tests\date_recur\Unit\DateRecurRlInterpretationUnitTest::setUp()
  2. 3.x tests/src/Unit/DateRecurRlInterpretationUnitTest.php \Drupal\Tests\date_recur\Unit\DateRecurRlInterpretationUnitTest::setUp()
  3. 3.1.x tests/src/Unit/DateRecurRlInterpretationUnitTest.php \Drupal\Tests\date_recur\Unit\DateRecurRlInterpretationUnitTest::setUp()

Overrides UnitTestCase::setUp

File

tests/src/Unit/DateRecurRlInterpretationUnitTest.php, line 36

Class

DateRecurRlInterpretationUnitTest
Tests Rlanvin implementation of interpreter.

Namespace

Drupal\Tests\date_recur\Unit

Code

protected function setUp() : void {
  parent::setUp();
  $dateFormat = $this
    ->createMock(DateFormatInterface::class);
  $dateFormat
    ->expects($this
    ->any())
    ->method('id')
    ->willReturn($this
    ->randomMachineName());
  $dateFormatStorage = $this
    ->createMock(EntityStorageInterface::class);
  $dateFormatStorage
    ->expects($this
    ->any())
    ->method('load')
    ->with($this
    ->anything())
    ->willReturn($dateFormat);
  $entityTypeManager = $this
    ->createMock(EntityTypeManagerInterface::class);
  $entityTypeManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->with('date_format')
    ->willReturn($dateFormatStorage);
  $dateFormatter = $this
    ->createMock(DateFormatterInterface::class);
  $dateFormatter
    ->expects($this
    ->any())
    ->method('format')
    ->with($this
    ->anything())
    ->willReturnCallback(function ($timestamp, $type = 'medium', $format = '', string $timezone = NULL, $langcode = NULL) {
    $date = new \DateTime('@' . $timestamp);
    if (!$timezone) {
      $timezone = date_default_timezone_get();
    }
    $date
      ->setTimezone(new \DateTimeZone($timezone));
    return $date
      ->format('r');
  });
  $container = new ContainerBuilder();
  $container
    ->set('date.formatter', $dateFormatter);
  $container
    ->set('entity_type.manager', $entityTypeManager);
  $this->testContainer = $container;
}