不断收到“您请求了一个不存在的服务"test.client“"在 Symfony2 Beta3 中

2022-01-25 00:00:00 php symfony phpunit

我正在尝试设置单元测试,但每当我运行phpunit -c app"时,我都会收到此错误:

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

SymfonyComponentDependencyInjectionExceptionServiceNotFoundException:您请求了一个不存在的服务test.client".

SymfonyComponentDependencyInjectionExceptionServiceNotFoundException: You have requested a non-existent service "test.client".

我的测试用例中的代码只是:

The code in my test case is just:

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

如果我不调用 createClient,一切都会正常运行.我检查了 AppKernel.php 以确保 FrameworkBundle(我相信这是定义此服务的位置)肯定仍然存在并且确实存在.

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.

感谢您的帮助.

推荐答案

你是否在config_test.yml中启用了framework.test选项?

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

framework:
  test: ~

相关文章