function DrupalDateTimeTest::testChainable

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php \Drupal\Tests\Core\Datetime\DrupalDateTimeTest::testChainable()
  2. 10 core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php \Drupal\Tests\Core\Datetime\DrupalDateTimeTest::testChainable()
  3. 11.x core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php \Drupal\Tests\Core\Datetime\DrupalDateTimeTest::testChainable()

Tests that object methods are chainable.

@covers ::__call

File

core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php, line 177

Class

DrupalDateTimeTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Datetime%21DrupalDateTime.php/class/DrupalDateTime/9" title="Extends DateTimePlus()." class="local">\Drupal\Core\Datetime\DrupalDateTime</a> @group Datetime

Namespace

Drupal\Tests\Core\Datetime

Code

public function testChainable() {
    $tz = new \DateTimeZone(date_default_timezone_get());
    $date = new DrupalDateTime('now', $tz, [
        'langcode' => 'en',
    ]);
    $date->setTimestamp(12345678);
    $rendered = $date->render();
    $this->assertEquals('1970-05-24 07:21:18 Australia/Sydney', $rendered);
    $date->setTimestamp(23456789);
    $rendered = $date->setTimezone(new \DateTimeZone('America/New_York'))
        ->render();
    $this->assertEquals('1970-09-29 07:46:29 America/New_York', $rendered);
}

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