liip / LiipFunctionalTestBundle

Some helper classes for writing functional tests in Symfony
http://liip.ch
MIT License
641 stars 182 forks source link

Call to deprecated method isMasterRequest() when isMainRequest() returns false #590

Closed tperunsky closed 2 years ago

tperunsky commented 2 years ago

Relevant piece of code in \Liip\FunctionalTestBundle\Validator\DataCollectingValidator

    public function onKernelRequest(GetResponseEvent $event): void
    {
        if (method_exists($event, 'isMainRequest') && $event->isMainRequest()) {
            $this->clearLastErrors();
        } elseif ($event->isMasterRequest()) {
            $this->clearLastErrors();
        }
    }

The method onKernelRequest() correctly uses $event->isMainRequest() if the method exists, however the way the condition is constructed, the elseif condition is checked when isMainRequest() returns false. As a result, the deprecated isMasterRequest() method is called unnecessarily.

Preconditions

  1. Using composer package liip/functional-test-bundle 4.4.2

Steps to reproduce

The bug is obvious when looking at the code. To reproduce, call \Liip\FunctionalTestBundle\Validator\DataCollectingValidator::onKernelRequest() with \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST as the last parameter

Expected result

  1. A deprecation error is not triggered when isMainRequest() exists and returns false.

Actual result

  1. When isMainRequest() exists and returns false, a deprecation error is triggered: php.INFO: User Deprecated: Since symfony/http-kernel 5.3: "Symfony\Component\HttpKernel\Event\KernelEvent::isMasterRequest()" is deprecated, use "isMainRequest()" instead.
alexislefebvre commented 2 years ago

Thanks for the detailed report, do you have an idea to fix it?

alexislefebvre commented 2 years ago

Please have a look at #591