mglaman / drupal-test-helpers

Helpers for writing better Kernel and Unit tests for Drupal
GNU General Public License v2.0
10 stars 2 forks source link

decorate the http_kernel service to not catch exceptions #2

Closed joachim-n closed 1 year ago

joachim-n commented 1 year ago

Drupal's http_kernel service is StackedHttpKernel, which has $catch = TRUE.

That means that if the request throws an exception somewhere, the response 500 and you don't know why.

I'm wondering if it would be worth adding a testing_http_kernel which decorates the original service and sets $catch = FALSE. What do you think?

mglaman commented 1 year ago

That sounds like a great idea.

mglaman commented 1 year ago

I was looking into this, and it might be hard.

\Drupal\Core\DependencyInjection\Compiler\StackedKernelPass has logic that is specific to \Drupal\Core\StackMiddleware\StackedHttpKernel

However, I think we can decorate http_kernel.basic which is Symfony\Component\HttpKernel\HttpKernel.

From the StackedHttpKernel

    $decorated_id = 'http_kernel.basic';
    $middlewares_param = [new Reference($decorated_id)];
    //...
    $arguments = [$middlewares_param[0], $middlewares_param];
    $stacked_kernel->setArguments($arguments);