当我阅读symfony文档https://symfony.com/doc/current/testing.html时,他们使用以下命令初始化客户端:
$client = static::createClient();
他们可以使用相对路径进行请求
$client->request('GET', '/post/hello-world');
我的项目中的问题是我生成了以下网址:http://localhost/api/users,但是我想要的是http://myproject.localhost/api/users
如何根据要启动测试的环境来更改基本url(因为在测试环境中,我将有http://myproject.test/api/users
感谢您的帮助
答案 0 :(得分:2)
您应该能够将服务器信息作为createClient方法的第二个参数传递,例如:
$client = static::createClient(array(), array('HTTP_HOST' => 'localhost/myalias/app_dev.php')) ;
希望获得帮助
答案 1 :(得分:1)
您也可以尝试手动设置:
$client = static::createClient();
$client->setServerParameter('HTTP_HOST', 'myproject.localhost');