Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

HttpExceptionTest.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Symfony\Component\HttpKernel\Tests\Exception;
  3. use PHPUnit\Framework\TestCase;
  4. use Symfony\Component\HttpKernel\Exception\HttpException;
  5. class HttpExceptionTest extends TestCase
  6. {
  7. public function headerDataProvider()
  8. {
  9. return [
  10. [['X-Test' => 'Test']],
  11. [['X-Test' => 1]],
  12. [
  13. [
  14. ['X-Test' => 'Test'],
  15. ['X-Test-2' => 'Test-2'],
  16. ],
  17. ],
  18. ];
  19. }
  20. public function testHeadersDefault()
  21. {
  22. $exception = $this->createException();
  23. $this->assertSame([], $exception->getHeaders());
  24. }
  25. /**
  26. * @dataProvider headerDataProvider
  27. */
  28. public function testHeadersConstructor($headers)
  29. {
  30. $exception = new HttpException(200, null, null, $headers);
  31. $this->assertSame($headers, $exception->getHeaders());
  32. }
  33. /**
  34. * @dataProvider headerDataProvider
  35. */
  36. public function testHeadersSetter($headers)
  37. {
  38. $exception = $this->createException();
  39. $exception->setHeaders($headers);
  40. $this->assertSame($headers, $exception->getHeaders());
  41. }
  42. public function testThrowableIsAllowedForPrevious()
  43. {
  44. $previous = new class('Error of PHP 7+') extends \Error {
  45. };
  46. $exception = $this->createException(null, $previous);
  47. $this->assertSame($previous, $exception->getPrevious());
  48. }
  49. protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
  50. {
  51. return new HttpException(200, $message, $previous, $headers, $code);
  52. }
  53. }