You are here

public function DrupalDateTimeTest::testChainableNonChainable in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php \Drupal\Tests\Core\Datetime\DrupalDateTimeTest::testChainableNonChainable()
  2. 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 195

Class

DrupalDateTimeTest
@coversDefaultClass \Drupal\Core\Datetime\DrupalDateTime @group Datetime

Namespace

Drupal\Tests\Core\Datetime

Code

public function testChainableNonChainable() {
  $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'));
}