FriendsOfBehat / SymfonyExtension

:musical_score: Extension integrating Behat with Symfony.
MIT License
472 stars 62 forks source link

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

Open DonCallisto opened 5 years ago

DonCallisto commented 5 years ago

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.

pamil commented 5 years ago

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

DonCallisto commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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

DonCallisto commented 5 years ago

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?

siment commented 4 years ago

@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"

DonCallisto commented 4 years ago

@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

siment commented 4 years ago

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

pamil commented 4 years ago

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

DonCallisto commented 4 years ago

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

DonCallisto commented 4 years ago

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

cv65kr commented 4 years ago

I confirmed, still problem with 4.4.

pamil commented 4 years ago

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

DonCallisto commented 4 years ago

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.

pamil commented 4 years ago

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

DonCallisto commented 4 years ago

@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?

pamil commented 4 years ago

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

DonCallisto commented 4 years ago

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