39

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.

Karol Gasienica
  • 2,825
  • 24
  • 36
pogo
  • 2,287
  • 2
  • 25
  • 36

5 Answers5

84

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

framework:
  test: ~
A.L
  • 10,259
  • 10
  • 67
  • 98
Ajb
  • 1,275
  • 10
  • 5
10

In phpunit.xml you should have env variable like:

<env name="APP_ENV" value="test"/>
Karol Gasienica
  • 2,825
  • 24
  • 36
5

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

matiux
  • 493
  • 1
  • 6
  • 16
2

composer require symfony/browser-kit

The definition test.client depends upon AbstractBrowser::class presence

drzraf
  • 451
  • 4
  • 11
0

I had same issue with remote builds of my project. This issue was connected with empty symfony.lock file in the root of my project. This file is for preventing symfony recipes execution twice. But my symfony.lock was corrupted and empty so framework-bundle executed it's recipe and replaced my APP_ENV variable in phpunit.xml.dist from test to dev. The reason why it happened was repositories node in composer.json (https://github.com/symfony/flex/issues/347)

I'm fixing this situation by adding dependencies in symfony.lock by my hands

Nikita Leshchev
  • 1,784
  • 2
  • 14
  • 26