public function it_performs_a_HTTP_request_to_the_given_url_with_params_and_files(HttpMethodsClient $client, ResponseInterface $response) { $file = tempnam(sys_get_temp_dir(), 'veye'); $client->sendRequest(Argument::type(RequestInterface::class))->willReturn($response); $response->getBody()->willReturn('[]'); $this->request('DELETE', 'bar', ['foo' => 'bar', 'bazz' => $file])->shouldBeArray(); @unlink($file); }
/** * Make a custom api request. * * @param string $method HTTP Method * @param string $uri URI template * @param array $headers * @param string|StreamInterface|null $body * * @throws OneSignalException * * @return array */ public function request($method, $uri, array $headers = [], $body = null) { try { $response = $this->client->send($method, self::API_URL . $uri, array_merge(['Content-Type' => 'application/json'], $headers), $body); return json_decode($response->getBody(), true); } catch (\Throwable $t) { throw new OneSignalException($t->getMessage()); } catch (\Exception $e) { throw new OneSignalException($e->getMessage()); } }
/** * @return Event */ private function setUpStandardEvent() { $this->httpMethodsClient->expects(static::once())->method('post')->with('https://events.pagerduty.com/generic/2010-04-15/create_event.json', ['Content-type' => 'application/json'], '{ "service_key": "a2efbd3070e1113c18abef9ea544cd8c", "event_type": "trigger", "description": "FAILURE for production\\/HTTP on machine srv01.acme.com" }'); $event = new Event(); $event->serviceKey = 'a2efbd3070e1113c18abef9ea544cd8c'; $event->description = 'FAILURE for production/HTTP on machine srv01.acme.com'; return $event; }
/** * Ping an endpoint. * * @param string $method * @param \Psr\Http\Message\UriInterface|string $uri * @param mixed $body * @param array $headers * * @return \Psr\Http\Message\ResponseInterface */ public function send($method, $uri, $data = [], array $headers = []) { list($headers, $body) = $this->prepareRequestPayloads($headers, $body); return $this->http->send(strtoupper($method), $uri, $headers, $body); }