【发布时间】:2015-06-16 15:34:01
【问题描述】:
我已按照accepted answer of this question 中的说明修改了我的应用程序的基本请求类。它工作得很好,除了在启动我的功能测试时,我收到以下错误:
控制器
"My\Bundle\AppBundle\Controller\MyController::searchAction()"要求您为“$request”参数提供一个值(因为没有默认值或因为在此参数之后有一个非可选参数)。 (500 内部服务器错误)
确实没有使用app_test.php 控制器。我希望它可以在我的WebTestCase 基类的createCient() 函数中完成,但是如何实现呢?
/**
* Creates a Client.
*
* @param array $options An array of options to pass to the createKernel class
* @param array $server An array of server parameters
*
* @return Client A Client instance
*/
protected static function createClient(array $options = array(), array $server = array())
{
static::bootKernel($options);
$client = static::$kernel->getContainer()->get('test.client');
$client->setServerParameters($server);
return $client;
}
- 使用 Symfony 2.6.9。
[2017 年 9 月 21 日编辑]:
迁移到 Symfony 3.3 时我必须执行以下操作:
config_test.yml:
parameters:
test.client.class: My\Bundle\AppBundle\Tests\Client
services:
test.client:
class: '%test.client.class%'
arguments: ['@kernel', '%test.client.parameters%', '@test.client.history', '@test.client.cookiejar']
【问题讨论】:
-
如果你自己重新定义服务,别忘了加
shared: false。请参阅default configuration 以获取new instance each time
标签: php symfony request phpunit