public function post($url, $nonBlocking = false) { $request = new Request('GET', $url, ['User-Agent' => self::PHP_GA_MEASUREMENT_PROTOCOL_USER_AGENT]); $response = $this->getClient()->sendAsync($request, ['synchronous' => !$nonBlocking, 'timeout' => self::REQUEST_TIMEOUT_SECONDS, 'connect_timeout' => self::REQUEST_TIMEOUT_SECONDS]); if ($nonBlocking) { self::$promises[] = $response; } else { $response = $response->wait(); } return $this->getAnalyticsResponse($request, $response); }
public function testPost() { $response = $this->mockHttpClient->post('http://test-collector.com/collect?v=1'); $this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response); $responseAsync = $this->mockHttpClient->post('http://test-collector.com/collect?v=1', true); $this->assertInstanceOf('GuzzleHttp\\Promise\\PromiseInterface', $responseAsync); $response = $this->httpClient->post('http://test-collector.com/collect?v=1'); $this->assertInstanceOf('TheIconic\\Tracking\\GoogleAnalytics\\AnalyticsResponse', $response); // Promises should be unwrapped on the object destruction $this->httpClient = null; $this->mockHttpClient = null; }