我试图对我的Stripe webhook处理程序的实现进行单元测试.条带webhook数据作为POST请求正文中的原始JSON在线上传播,因此我捕获并解码数据:
public function store() { $input = @file_get_contents("php://input"); $request = json_decode($input); return Json::encode($request); }
我正在尝试对此代码进行单元测试,但我无法弄清楚如何在单元测试中发送原始JSON数据,以便我可以使用该file_get_contents("php:input//")
函数检索它.这是我尝试过的(使用PHPUnit
):
protected $testRoute = 'api/stripe/webhook'; protected $validWebhookJson = <<call('POST', $this->testRoute, $this->validWebhookJson); // fails because `$parameters` must be an array $response = $this->call('POST', $this->testRoute, [], [], ['CONTENT_TYPE' => 'application/json'], $this->validWebhookJson); dd($response->getData(true)); // array(0) {} BOOOO!!! Where for to my data go? }
我也尝试了,curl
但这会产生一个外部请求,从单元测试的角度来看,这对我没有意义.如何使用我的store
方法拾取的正文中的原始JSON数据来模拟POST请求?