symfony功能测试:更改基本URL

问题描述 投票:1回答:1

当我阅读symfony文档https://symfony.com/doc/current/testing.html时,他们使用此命令初始化客户端:

$client = static::createClient();

他们可以使用相对路径进行请求

$client->request('GET', '/post/hello-world');

我项目中的问题是,我生成了这个URL:http://localhost/api/users,但我想要的是http://myproject.localhost/api/users

我如何根据要启动测试的环境来更改基本URL(因为在测试环境中,我将获得http://myproject.test/api/users

感谢您的帮助

symfony phpunit
1个回答
1
投票

例如,您应该能够将服务器信息作为createClient方法的第二个参数传递:

$client = static::createClient(array(), array('HTTP_HOST' => 'localhost/myalias/app_dev.php')) ; 

希望此帮助

© www.soinside.com 2019 - 2024. All rights reserved.