进行单元测试时是否为ServiceNotFoundException?

时间:2016-08-02 06:53:05

标签: php symfony

我在这里遵循教程:

http://symfony.com/doc/current/testing.html

运行此行时出现ServiceNotFoundException:

static::createClient();

错误来自

的第35行
Symfony\Bundle\FrameworkBundle\Test\WebTestCase.php

$client = static::$kernal->getContainer()->get('test.client');

所以我猜测缺少一个名为test.client的服务。我该如何提供该服务?还是其他东西坏了?

1 个答案:

答案 0 :(得分:0)

如果扩展WebTestCase类,您应该能够使用此代码获取客户端:

$client = static::createClient([]);

如果您无法以任何方式获取内核,我过去会创建以下方式:

$appKernel = new AppKernel('test', true);
$appKernel->boot();
$container = $appKernel->getContainer();