Php 如何获取流明响应内容作为字符串?

Php 如何获取流明响应内容作为字符串?,php,api,phpunit,response,lumen,Php,Api,Phpunit,Response,Lumen,我尝试的是从带有Lumen response的单元测试中获取字符串形式的响应内容: class MovieQueryTest扩展了测试用例 { 使用数据库迁移; 公共函数testCanSearch() { 电影::创建([ 'name'=>'Fast&frequence 8', '别名'=>'快速狂暴8', “年份”=>2016年 ]); $response=$this->post(“/graphql”[ 'query'=>'{movies(search:“Fast&free”){data{na

我尝试的是从带有Lumen response的单元测试中获取字符串形式的响应内容:

class MovieQueryTest扩展了测试用例
{
使用数据库迁移;
公共函数testCanSearch()
{
电影::创建([
'name'=>'Fast&frequence 8',
'别名'=>'快速狂暴8',
“年份”=>2016年
]);
$response=$this->post(“/graphql”[
'query'=>'{movies(search:“Fast&free”){data{name}}
]);
$response->getContent();//错误:调用未定义的方法MovieQueryTest::getContent()
$response->getOriginalContent();//错误:调用未定义的方法MovieQueryTest::getOriginalContent()
$response->content;//错误异常:未定义属性:MovieQueryTest::$content
}
}
但我不知道如何获得回复内容

我不想使用Lumen
TestCase->seeJson()
方法


我只需要获取响应内容。

$response
还包含一个
response
字段,您需要在该字段上调用
getContent()
,因此您首先需要提取该字段,然后调用
getContent()
,因此在您的代码中这将成为:

public function testCanSearch()
    {
        Movie::create([
            'name' => 'Fast & Furious 8',
            'alias' => 'Fast and Furious 8',
            'year' => 2016
        ]);

        $response = $this->post('/graphql', [
            'query' => '{movies(search: "Fast & Furious"){data{name}}}'
        ]);

        $extractedResponse = $response->response; // Extract the response object
        $responseContent = $extractedResponse->getContent(); // Extract the content from the response object

        $responseContent = $response->response->getContent(); // Alternative one-liner

}