使用Behat,我可以编写这样的场景:
Scenario: I can get a template
When I send a GET request to "/products/template"
Then the response status code should be 200
链接到vendor/behatch/contexts/src/Context/RestContext.php
实现的Behatch步骤:
/**
* Sends a HTTP request
*
* @Given I send a :method request to :url
*/
public function iSendARequestTo($method, $url, PyStringNode $body = null, $files = [])
{
return $this->request->send(
$method,
$this->locatePath($url),
[],
$files,
$body !== null ? $body->getRaw() : null
);
}
为了验证文件响应,我想编写一个类似这样的场景:
Scenario: I can get a template
When I send a GET download request to "/products/template" and save it to "/tmp"
Then the response status code should be 200
And the file "/tmp/template.csv" should exist
我想编写一个发送GET请求并将文件下载到提供的路径的步骤,类似于sink Guzzle functionality,类似于:
/**
* Sends a HTTP request
*
* @Given I send a :method download request to :url and save it to :path
*/
public function iSendADownloadRequestTo($method, $url, $path)
{
return $this->request->send(
$method,
$this->locatePath($url),
["sink" => __DIR__.$path]
);
}
先前的代码成功发送了请求,但未保存文件。我该如何实现?
答案 0 :(得分:0)
我将使用Guzzle
或curl
下载文件。 Mink
用于与页面交互,并且据我所知并快速浏览其文档并不支持您所追求的功能。