function DrupalDateTimeTest::testChainableNonChainable

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

Tests that non-chainable methods work.

@covers ::__call

File

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

Class

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

Namespace

Drupal\Tests\Core\Datetime

Code

public function testChainableNonChainable() : void {
    $tz = new \DateTimeZone(date_default_timezone_get());
    $datetime1 = new DrupalDateTime('2009-10-11 12:00:00', $tz, [
        'langcode' => 'en',
    ]);
    $datetime2 = new DrupalDateTime('2009-10-13 12:00:00', $tz, [
        'langcode' => 'en',
    ]);
    $interval = $datetime1->diff($datetime2);
    $this->assertInstanceOf(\DateInterval::class, $interval);
    $this->assertEquals('+2 days', $interval->format('%R%a days'));
}

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