MethodNotAllowedHttpExceptionTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests\Exception;
  11. use Symfony\Component\HttpKernel\Exception\HttpException;
  12. use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
  13. class MethodNotAllowedHttpExceptionTest extends HttpExceptionTest
  14. {
  15. public function testHeadersDefault()
  16. {
  17. $exception = new MethodNotAllowedHttpException(['GET', 'PUT']);
  18. $this->assertSame(['Allow' => 'GET, PUT'], $exception->getHeaders());
  19. }
  20. public function testWithHeaderConstruct()
  21. {
  22. $headers = [
  23. 'Cache-Control' => 'public, s-maxage=1200',
  24. ];
  25. $exception = new MethodNotAllowedHttpException(['get'], '', null, 0, $headers);
  26. $headers['Allow'] = 'GET';
  27. $this->assertSame($headers, $exception->getHeaders());
  28. }
  29. /**
  30. * @dataProvider headerDataProvider
  31. */
  32. public function testHeadersSetter($headers)
  33. {
  34. $exception = new MethodNotAllowedHttpException(['GET']);
  35. $exception->setHeaders($headers);
  36. $this->assertSame($headers, $exception->getHeaders());
  37. }
  38. protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException
  39. {
  40. return new MethodNotAllowedHttpException(['get'], $message, $previous, $code, $headers);
  41. }
  42. }