function CacheableExceptionTest::testExceptions

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Http/CacheableExceptionTest.php \Drupal\Tests\Core\Http\CacheableExceptionTest::testExceptions()
  2. 11.x core/tests/Drupal/Tests/Core/Http/CacheableExceptionTest.php \Drupal\Tests\Core\Http\CacheableExceptionTest::testExceptions()

@dataProvider providerTestExceptions

File

core/tests/Drupal/Tests/Core/Http/CacheableExceptionTest.php, line 46

Class

CacheableExceptionTest
@group Http

Namespace

Drupal\Tests\Core\Http

Code

public function testExceptions($status_code, $class, $argument = NULL, $expected_headers = []) : void {
    $cacheable_metadata = (new CacheableMetadata())->setCacheContexts([
        'route',
    ]);
    $message = "{$class} test message";
    if ($argument) {
        $exception = new $class($cacheable_metadata, $argument, $message, NULL, 123);
    }
    else {
        $exception = new $class($cacheable_metadata, $message, NULL, 123);
    }
    $this->assertSame([
        'route',
    ], $exception->getCacheContexts());
    $this->assertSame($message, $exception->getMessage());
    $this->assertSame($status_code, $exception->getStatusCode());
    $this->assertSame($expected_headers, $exception->getHeaders());
    $this->assertSame(123, $exception->getCode());
}

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