开发者社区> 问答> 正文

狂饮后的请求没有嘲笑

我正在尝试为使用Guzzle http客户端的端点编写测试用例。但这并没有被嘲笑。它仍然符合实际要求并等待响应。我的代码如下。

测试用例

    new Response(200, ['X-Foo' => 'Bar'], 'Hello, World'),
]);
$handler = HandlerStack::create($mockHandler);
$client = new Client(['handler' => $handler]);

$this->app->instance(\GuzzleHttp\Client::class, $client);

$response = $this->actingAs($user)
            ->get('/api/request?' . http_build_query($request));

我在服务类中使用Guzzle客户端的方式如下

{
    public function __construct(\GuzzleHttp\Client $client, $extraInfo)
    {
        $this->client = $client;
        $this->setExtraInfo($extraInfo);
    }

    private function getToken($scope)
    {
        $response = $this->client->post(
            '/post/request/url',
            [
                'form_params' => [
                    "param_1" => "value_1",
                    "param_2" => 'value_2'
                ],
                'headers' => [
                    "Authorization"=> "Basic 5235252333",
                    "Content-Type" => 'application/x-www-form-urlencoded'
                ],
                self::COMMON_REQUEST_PARAMS,
                'cert' => ['cert path' , 'pass phrase']
            ]
        );

        $jsonOutput = json_decode($response->getBody()->getContents());

        return $jsonOutput->access_token;
    }
}

展开
收起
社区秘书 2019-12-09 16:58:49 596 0
0 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
一封信 立即下载
让世界没有陌生的角落共享单车时代的快与慢 立即下载
让世界没有陌生的角落 共享单车时代的快与慢 立即下载