HttpExceptionTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. protected function createException()
  43. {
  44. return new HttpException(200);
  45. }
  46. }