SymfonyExtension icon indicating copy to clipboard operation
SymfonyExtension copied to clipboard

The service "test.client" has a dependency on a non-existent service "test.client.history".

Open DonCallisto opened this issue 5 years ago • 19 comments

Hi, after upgrading symfony version from 4.2 to 4.3 (actually 4.3.3) I have this error shown when I try to run any behat test. I think that has something to do with this extension as if I try with a different extension - wich I trying to get rid of; is symfony2extension - everything works fine. Moreover with symfony 4.2 and this extension, everything is fine.

The error is shown in the title.

DonCallisto avatar Aug 01 '19 10:08 DonCallisto

Are there any other packages being updated as well? Could you provide a stacktrace (run Behat with -vvv)?

We're using SymfonyExtension v2.0.8 with Symfony v4.3.3 in Sylius builds and it's passing on Travis: https://travis-ci.org/Sylius/Sylius/jobs/566377307

pamil avatar Aug 01 '19 12:08 pamil

I've done a bounce of updates but already in dev (where every test is fine). In branch I'm working on, this is the only change (removing symfony2extension in favor of yours).

Here's the stack trace.

In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:

[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
The service "test.client" has a dependency on a non-existent service "test.client.history".

Exception trace: () at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:86 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php:82 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:49 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php:91 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:49 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php:82 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:49 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php:46 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->process() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:40 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->process() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:95 Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:756 Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:550 Symfony\Component\HttpKernel\Kernel->initializeContainer() at /var/www/nuvola/app/AppKernel.php:227 AppKernel->initializeContainer() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:133 Symfony\Component\HttpKernel\Kernel->boot() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1630 Symfony\Component\DependencyInjection\ContainerBuilder->callMethod() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1168 Symfony\Component\DependencyInjection\ContainerBuilder->createService() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:612 Symfony\Component\DependencyInjection\ContainerBuilder->doGet() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1266 Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1214 Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1116 Symfony\Component\DependencyInjection\ContainerBuilder->createService() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1268 Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1214 Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1630 Symfony\Component\DependencyInjection\ContainerBuilder->callMethod() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1168 Symfony\Component\DependencyInjection\ContainerBuilder->createService() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:612 Symfony\Component\DependencyInjection\ContainerBuilder->doGet() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1266 Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1214 Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1116 Symfony\Component\DependencyInjection\ContainerBuilder->createService() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1268 Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1214 Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1214 Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1116 Symfony\Component\DependencyInjection\ContainerBuilder->createService() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:612 Symfony\Component\DependencyInjection\ContainerBuilder->doGet() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:558 Symfony\Component\DependencyInjection\ContainerBuilder->get() at /var/www/nuvola/vendor/behat/behat/src/Behat/Testwork/Cli/Application.php:161 Behat\Testwork\Cli\Application->createCommand() at /var/www/nuvola/vendor/behat/behat/src/Behat/Testwork/Cli/Application.php:122 Behat\Testwork\Cli\Application->doRun() at /var/www/nuvola/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:149 Symfony\Component\Console\Application->run() at /var/www/nuvola/vendor/behat/behat/bin/behat:34

I've checked Sylius in order to find if you were using the same version but, as long as composer.lock was not included, I could not assume the versions.

DonCallisto avatar Aug 01 '19 12:08 DonCallisto

Debug shows how with old extension (symfony2extension) and symfony 4.3.3, test.client.history is not inlined and so not removed whereas with symfonyextension is.

DonCallisto avatar Aug 01 '19 12:08 DonCallisto

@pamil if I do bin/app debug:container --env=test the container is unable to compile (so is not necessary to reach a behat test). Does this suggest you something? To me it sounds like it should not be fault of the bundle but as soon as I comment it out from AppKernel everything works like a charm.

Edit: my fault, there's an extension so is perfectly legit for this bundle to be loaded while compiling the container.

DonCallisto avatar Aug 01 '19 13:08 DonCallisto

@pamil my bad, the previous version of symfony was 4.1 not 4.2. I suspect that this issue is related to AnalyzeServiceReferencesPass

DonCallisto avatar Aug 02 '19 10:08 DonCallisto

A little update for this: I've managed to let it work but still not sure why. When the issue was there, I use to declare test.client in bind section as follows

services:
  _defaults:
    autowire: true
    autoconfigure: true
    bind:
      $testClient: '@test.client'

As soon as I changed it to an alias like (removing the declaration under bind key)

Symfony\Component\BrowserKit\AbstractBrowser: '@test.client'

everything works. So it must be something in Symfony >= 4.2 or in this extension or in the combination of both that mess up the things.

Any clues?

DonCallisto avatar Aug 21 '19 15:08 DonCallisto

@DonCallisto I think your issue is that you don't have symfony/browser-kit installed. Here is why:

Please have a look at the method

\Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension::load()

specifically the following lines:

        if (!empty($config['test'])) {
            $loader->load('test.xml');

            if (!class_exists(AbstractBrowser::class)) {
                $container->removeDefinition('test.client');
            }
        }

Notice that the definition 'test.client' is removed if it cannot find AbstractBrowser::class. This conditional removal was not present in version 4.2.

The class AbstractBrowser is native to "symfony/browser-kit"

siment avatar Dec 06 '19 10:12 siment

@siment I have that bundle installed (and enabled) otherwise I won't be able to do what I've done in https://github.com/FriendsOfBehat/SymfonyExtension/issues/88#issuecomment-523504558

DonCallisto avatar Dec 06 '19 10:12 DonCallisto

Right... I missed that part. Wish I could help you more. Good luck.

siment avatar Dec 06 '19 10:12 siment

Does this error still happen with the newest Symfony (4.4.*)?

pamil avatar Jan 13 '20 19:01 pamil

@pamil I will try with Symfony 4.4.* and previous configuration, hopefully, this week end. Let's keep in touch.

DonCallisto avatar Jan 22 '20 10:01 DonCallisto

@pamil sorry for being late on this. Just updated the project to Symfony4.4.* and the issue is still there.

DonCallisto avatar Feb 27 '20 15:02 DonCallisto

I confirmed, still problem with 4.4.

cv65kr avatar Mar 16 '20 07:03 cv65kr

Build failures on Sylius look connected with this issue: https://github.com/Sylius/Sylius/pull/11029

pamil avatar Apr 04 '20 13:04 pamil

I think that adding AbstractBrowser here will solve the issue. I've tried to debug the container in my application (using v2.1 of this lib and with the edit suggested) and seems to work. Moreover AbstractBrowser is what is suggested to replace Client in deprecation notice.

If makes sense to you, I'll open a PR. Let me know.

DonCallisto avatar Jun 18 '20 10:06 DonCallisto

@DonCallisto sounds good, feel free to send a PR. Is there any way we could also test it to avoid regressions in the future?

pamil avatar Jun 18 '20 13:06 pamil

@pamil Maybe check if test.client service is added to the container? Because if I'm not mistaken here, the fact that test.client is never declared (aliased to be fair), results in test.client to be removed from container and, along with it, also test.client.history. If we have that alias and one of those implementations is used (injected), test.client.history will never be removed. WDYT?

DonCallisto avatar Jun 18 '20 13:06 DonCallisto

Makes sense! Let's first create a failing test and then add the fix to make sure that's the case. Thanks a lot!

pamil avatar Jun 18 '20 14:06 pamil

@pamil take a look at https://github.com/FriendsOfBehat/SymfonyExtension/pull/129 LGTY?

DonCallisto avatar Jun 18 '20 15:06 DonCallisto