class CacheableExceptionTest in Drupal 10
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Http/CacheableExceptionTest.php \Drupal\Tests\Core\Http\CacheableExceptionTest
@group Http
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitWarnings
- class \Drupal\Tests\Core\Http\CacheableExceptionTest
Expanded class hierarchy of CacheableExceptionTest
File
- core/
tests/ Drupal/ Tests/ Core/ Http/ CacheableExceptionTest.php, line 27
Namespace
Drupal\Tests\Core\HttpView source
class CacheableExceptionTest extends UnitTestCase {
/**
* @covers \Drupal\Core\Http\Exception\CacheableHttpException
*/
public function testCacheableHttpException() {
$exception = new CacheableHttpException((new CacheableMetadata())
->setCacheContexts([
'route',
]), 500, 'test message', NULL, [
'X-Drupal-Exception' => 'Test',
], 123);
$this
->assertSame([
'route',
], $exception
->getCacheContexts());
$this
->assertSame(500, $exception
->getStatusCode());
$this
->assertSame('test message', $exception
->getMessage());
$this
->assertSame([
'X-Drupal-Exception' => 'Test',
], $exception
->getHeaders());
$this
->assertSame(123, $exception
->getCode());
}
/**
* @dataProvider providerTestExceptions
*/
public function testExceptions($status_code, $class, $argument = NULL, $expected_headers = []) {
$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());
}
public function providerTestExceptions() {
return [
[
400,
CacheableBadRequestHttpException::class,
],
[
401,
CacheableUnauthorizedHttpException::class,
'test challenge',
[
'WWW-Authenticate' => 'test challenge',
],
],
[
403,
CacheableAccessDeniedHttpException::class,
],
[
404,
CacheableNotFoundHttpException::class,
],
[
405,
CacheableMethodNotAllowedHttpException::Class,
[
'POST',
'PUT',
],
[
'Allow' => 'POST, PUT',
],
],
[
406,
CacheableNotAcceptableHttpException::class,
],
[
409,
CacheableConflictHttpException::class,
],
[
410,
CacheableGoneHttpException::class,
],
[
411,
CacheableLengthRequiredHttpException::class,
],
[
412,
CacheablePreconditionFailedHttpException::class,
],
[
415,
CacheableUnsupportedMediaTypeHttpException::class,
],
[
422,
CacheableUnprocessableEntityHttpException::class,
],
[
428,
CacheablePreconditionRequiredHttpException::class,
],
[
429,
CacheableTooManyRequestsHttpException::class,
60,
[
'Retry-After' => 60,
],
],
[
503,
CacheableServiceUnavailableHttpException::class,
60,
[
'Retry-After' => 60,
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableExceptionTest:: |
public | function | ||
CacheableExceptionTest:: |
public | function | @covers \Drupal\Core\Http\Exception\CacheableHttpException | |
CacheableExceptionTest:: |
public | function | @dataProvider providerTestExceptions | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 206 | |
UnitTestCase:: |
public static | function |