You are here

public function DateTimePlusTest::testDateArrays in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::testDateArrays()
  2. 9 core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php \Drupal\Tests\Component\Datetime\DateTimePlusTest::testDateArrays()

Tests creating dates from string and array input.

@dataProvider providerTestDateArrays

Parameters

mixed $input: Input argument for DateTimePlus.

string $timezone: Timezone argument for DateTimePlus.

string $expected: Expected output from DateTimePlus::format().

File

core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php, line 48

Class

DateTimePlusTest
@coversDefaultClass \Drupal\Component\Datetime\DateTimePlus @group Datetime

Namespace

Drupal\Tests\Component\Datetime

Code

public function testDateArrays($input, $timezone, $expected) {
  $date = DateTimePlus::createFromArray($input, $timezone);
  $value = $date
    ->format('c');
  if (is_array($input)) {
    $input = var_export($input, TRUE);
  }
  $this
    ->assertEquals($expected, $value, sprintf("Test new DateTimePlus(%s, %s): should be %s, found %s.", $input, $timezone, $expected, $value));
}