Keep getting 'You have requested a non-existent service "test.client"' in Symfony2 Beta3

14,503

Solution 1

Have you enabled the framework.test option in config_test.yml?

framework:
  test: ~

Solution 2

In phpunit.xml you should have env variable like:

<env name="APP_ENV" value="test"/>

Solution 3

I had this problem with symfony version 3.3.13.

The config_test.yml file was fine, but I did the same mistake.

I solved adding the <server name ="APP_ENV" value="test" /> option under php in the phpunit.xml file

Share:
14,503
pogo
Author by

pogo

Updated on June 08, 2022

Comments

  • pogo
    pogo almost 2 years

    I'm trying to setup a unit test but whenever I run "phpunit -c app" I get this error:

    Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "test.client".

    The code in my test case is just:

    public function testNonAuthenticatedPathsIndex()
    {
        $client = $this->createClient();
    }
    

    If I don't make the call to createClient everything runs correctly. I've checked AppKernel.php to make sure the FrameworkBundle (I believe that's where this service is defined) is definitely still in there and it is.

    I'm a bit confused as to what might be causing this as I've managed to do this kind of thing before.

    Thanks for any help.

  • pogo
    pogo almost 13 years
    That's fixed it. Annoyed I didn't spot that myself so thanks for the help.
  • wesside
    wesside over 10 years
    +1 thanks, where is this in the docs? I must have missed it.
  • A.L
    A.L over 9 years
    This answer is still valid in 2014 with Symfony 2.3.22. Thanks!
  • A.L
    A.L over 9 years
    @wesside : it's displayed on this page but not in the linked page.
  • Med
    Med almost 9 years
    Still valid with symfony 2.7
  • stuzzo
    stuzzo about 8 years
    Still valid with symfony 2.8.2!
  • Sohrab
    Sohrab almost 8 years
    Still valid with Symfony 3.0.6
  • Pierre de LESPINAY
    Pierre de LESPINAY over 6 years
    framework.test is set by default in 3.4 but error is still there
  • Pierre de LESPINAY
    Pierre de LESPINAY over 6 years
    This does not fix it in my 3.4.1