function DateTimePlusTest::testChainable

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

Tests that object methods are chainable.

@covers ::__call

File

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

Class

DateTimePlusTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Component%21Datetime%21DateTimePlus.php/class/DateTimePlus/8.9.x" title="Wraps DateTime()." class="local">\Drupal\Component\Datetime\DateTimePlus</a> @group Datetime

Namespace

Drupal\Tests\Component\Datetime

Code

public function testChainable() {
    $date = new DateTimePlus('now', 'Australia/Sydney');
    $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);
    $date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '1970-05-24 07:21:18', new \DateTimeZone('Australia/Sydney'))->setTimezone(new \DateTimeZone('America/New_York'));
    $rendered = $date->render();
    $this->assertInstanceOf(DateTimePlus::class, $date);
    $this->assertEquals(12345678, $date->getTimestamp());
    $this->assertEquals('1970-05-23 17:21:18 America/New_York', $rendered);
}

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