Example #1
0
    /**
     * testClientWithDefaultConfig.
     */
    public function testMetricGet()
    {
        $metricJson = <<<JSON
{
  "uuid": "ec9e5ba7-9136-4b67-b049-a969e8e6dcde",
  "name": "Web Reponse time",
  "metric_type": "ms",
  "metric_calc": "avg",
  "description": "best description",
  "display": 1,
  "created_at": "2016-02-02T10:03:15+0000",
  "updated_at": "2016-02-02T10:03:15+0000",
  "_links": {
    "self": {
      "href": "/api/metrics/ec9e5ba7-9136-4b67-b049-a969e8e6dcde"
    }
  }
}
JSON;
        $mock = new MockHandler([new Response(200), function (RequestInterface $request) use($metricJson) {
            $this->assertEquals($request->getUri()->getPath(), '/metrics/ec9e5ba7-9136-4b67-b049-a969e8e6dcde');
            return new Response(200, [], $metricJson);
        }]);
        $handler = HandlerStack::create($mock);
        $client = new Client(['username' => 'admin', 'password' => 'admin', 'base_uri' => 'http://hogosha.dev/api', 'handler' => $handler]);
        $resourceFactory = new ResourceFactory($client);
        $metricResource = $resourceFactory->get('metric');
        $metric = $metricResource->getMetric('ec9e5ba7-9136-4b67-b049-a969e8e6dcde');
        $this->assertSame(json_decode($metricJson, true), $metric);
        $this->assertEquals('http://hogosha.dev/api', $client->getGuzzleClient()->getConfig()['base_uri']);
        $this->assertEquals('application/json', $client->getGuzzleClient()->getConfig()['headers']['Content-Type']);
    }
Example #2
0
 /**
  * @expectedException GuzzleHttp\Exception\BadResponseException
  *
  * testClientException.
  */
 public function testClientExceptionWithStatusCode()
 {
     $mock = new MockHandler([new Response(200), new Response(404, ['Content-Type' => 'application/json'])]);
     $handler = HandlerStack::create($mock);
     $client = new Client(['handler' => $handler, 'username' => 'admin', 'password' => 'admin']);
     $client->get('/');
 }
Example #3
0
    /**
     * testIncidentGet.
     */
    public function testIncidentGet()
    {
        $incidentJson = <<<JSON
{
  "uuid": "e3d1ab31-800e-4710-8b25-14bdc6742951",
  "name": "Mysql Bug",
  "status": "1",
  "description": "My First Incident",
  "created_at": "2016-02-02T10:03:15+0000",
  "updated_at": "2016-02-02T10:03:15+0000",
  "_links": {
    "self": {
      "href": "/api/incident/ec9e5ba7-9136-4b67-b049-a969e8e6dcde"
    }
  },
  "_embedded": {
    "service": {
        "uuid": "4fcd899a-91da-4128-8baf-92044fafe3db",
        "name": "Mysql",
        "description": "Mysql Service",
        "url": "http://www.example.com",
        "created_at": "2016-02-02T10:03:15+0000",
        "updated_at": "2016-02-02T10:03:15+0000"
    }
  }
}
JSON;
        $mock = new MockHandler([new Response(200), function (RequestInterface $request) use($incidentJson) {
            $this->assertEquals($request->getUri()->getPath(), '/incidents/e3d1ab31-800e-4710-8b25-14bdc6742951');
            return new Response(200, [], $incidentJson);
        }]);
        $handler = HandlerStack::create($mock);
        $client = new Client(['username' => 'admin', 'password' => 'admin', 'base_uri' => 'http://hogosha.dev/api', 'handler' => $handler]);
        $resourceFactory = new ResourceFactory($client);
        $incidentResource = $resourceFactory->get('incident');
        $incident = $incidentResource->getIncident('e3d1ab31-800e-4710-8b25-14bdc6742951');
        $this->assertSame(json_decode($incidentJson, true), $incident);
        $this->assertEquals('http://hogosha.dev/api', $client->getGuzzleClient()->getConfig()['base_uri']);
        $this->assertEquals('application/json', $client->getGuzzleClient()->getConfig()['headers']['Content-Type']);
    }