public function addStats(TransferStats $stats)
 {
     $request = $stats->getRequest();
     $data = isset($this->history[$request]) ? $this->history[$request] : [];
     $data['info'] = $stats->getHandlerStats();
     $this->history->attach($request, $data);
 }
Example #2
0
 /**
  * @param TransferStats $comparingStats
  * @param TransferStats $competitorStats
  */
 public function __construct(TransferStats $comparingStats, TransferStats $competitorStats)
 {
     $this->comparingSiteUri = $comparingStats->getEffectiveUri();
     $this->comparingSiteLoadingTime = $comparingStats->getTransferTime();
     $this->competitorSiteUri = $competitorStats->getEffectiveUri();
     $this->competitorSiteLoadingTime = $competitorStats->getTransferTime();
     $this->calculatePerformanceIndicator();
 }
 public function recordTransferStats(TransferStats $stats)
 {
     $request = $stats->getRequest();
     $response = $stats->hasResponse() ? $stats->getResponse() : null;
     $this->extra["url"] = $request->getUri()->__toString();
     $this->extra["method"] = $request->getMethod();
     $this->extra["requestHeaders"] = $this->processHeaders($request->getHeaders());
     $this->extra["requestBody"] = $request->getBody()->getContents();
     $this->extra["statusCode"] = $response !== null ? $response->getStatusCode() : null;
     $this->extra["responseHeaders"] = $response !== null ? $this->processHeaders($request->getHeaders()) : "";
     $this->extra["responseBody"] = $response !== null ? $response->getBody()->getContents() : "";
     $this->extra["duration"] = $stats->getTransferTime();
 }
 public function testHasData()
 {
     $request = new Psr7\Request('GET', 'http://foo.com');
     $response = new Psr7\Response();
     $stats = new TransferStats($request, $response, 10.5, null, ['foo' => 'bar']);
     $this->assertSame($request, $stats->getRequest());
     $this->assertSame($response, $stats->getResponse());
     $this->assertTrue($stats->hasResponse());
     $this->assertEquals(['foo' => 'bar'], $stats->getHandlerStats());
     $this->assertEquals('bar', $stats->getHandlerStat('foo'));
     $this->assertSame($request->getUri(), $stats->getEffectiveUri());
     $this->assertEquals(10.5, $stats->getTransferTime());
     $this->assertNull($stats->getHandlerErrorData());
 }