function DrupalDateTimeTest::testChainableNonCallable

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

Tests that chained calls to non-existent functions throw an exception.

@covers ::__call

File

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

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 testChainableNonCallable() {
    $this->expectException(\BadMethodCallException::class);
    $this->expectExceptionMessage('Call to undefined method Drupal\\Core\\Datetime\\DrupalDateTime::nonexistent()');
    $tz = new \DateTimeZone(date_default_timezone_get());
    $date = new DrupalDateTime('now', $tz, [
        'langcode' => 'en',
    ]);
    $date->setTimezone(new \DateTimeZone('America/New_York'))
        ->nonexistent();
}

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