我正在为api $client->request('POST', 'http://symfony.localhost/purchase', ['headers' => $headers]);编写一个测试。我使用测试sqlite设置测试环境,但是请求中调用的API继续在dev db上写入。我认为http请求不允许识别环境。(P.S. test env工作正常,与其他单元测试一起尝试)。我如何告诉/purchase使用test env?
这是我的考验:
public function testAdd()
{
$client = new \GuzzleHttp\Client();
$token = $this->encrypt('testaauser@mail.com', 'carouge', 'basic');
$headers = [
'Authorization' => 'Bearer ' . $token,
'Accept' => 'application/json',
];
$res = $client->request('POST', 'http://symfony.localhost/purchase', ['headers' => $headers]);
$this->assertEquals(201, $res->getStatusCode());
}发布于 2019-07-15 08:26:19
正如您已经说过的,您的http://symfony.localhost指向您的DEV环境,所以当您执行API调用时,您实际上是在该环境上执行调用。
要做您想做的事情,您需要“构建”一个测试环境:
这样,您的API调用就会在您的测试环境中执行。
关于环境的更多信息:
https://stackoverflow.com/questions/56220481
复制相似问题