我修改了我的應用程序的基本請求類,如accepted answer of this question中所述。它工作得非常好,我的啓動功能測試時除外,我得到以下錯誤:Symfony:更改請求基類和更新測試環境
Controller
"My\Bundle\AppBundle\Controller\MyController::searchAction()"
requires that you provide a value for the "$request" argument (because there is no default value or because there is a non-optional argument after this one). (500 Internal Server Error)
事實上,有沒有使用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'。查看[默認配置](https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml#L14)以獲得[每次新實例]( https://symfony.com/doc/current/service_container/shared.html) – Mick