public function testReturnsResultOfPassingWpDataToFactoryCreate() { $wpData = ['response' => ['code' => 201]]; $this->wpHttp->get('uri', [])->willReturn($wpData); $this->factory->create($wpData)->shouldBeCalled(); $this->request->get('uri'); }
public function testReturns500ResponseWithErrorsWhenInputIsWordpressErrorObject() { $wpError = $this->prophesize('WP_Error'); $wpError->get_error_messages()->willReturn(['ack!', 'bleh...', 'LOL wut?']); $response = $this->factory->create($wpError->reveal()); $this->assertSame(500, $response->getStatusCode()); $this->assertSame("ack!\nbleh...\nLOL wut?", $response->getBody()); }
/** * @return Response */ private function exec() { $url = $this->url; $options = $this->options; switch ($this->method) { case self::METHOD_GET: break; case self::METHOD_POST: $options[] = [CURLOPT_POST, TRUE]; break; default: $options[] = [CURLOPT_CUSTOMREQUEST, $this->method]; } if ($this->parameters) { if ($this->method === self::METHOD_GET) { $url .= '?' . http_build_query($this->parameters); } else { $isJson = isset($options[self::CURLOPT_JSON]) && $options[self::CURLOPT_JSON]; $data = $isJson ? json_encode($this->parameters) : http_build_query($this->parameters); $options[] = [CURLOPT_POSTFIELDS, $data]; } } if ($this->headers) { $options[] = [CURLOPT_HTTPHEADER, $this->headers]; } $request = $this->requestFactory->create($url, $options); return $this->responseFactory->create($request); }