/**
  * @expectedException \GuzzleHttp\Command\Exception\CommandException
  * @expectedExceptionMessage 404
  */
 public function testDoesNotAddResultWhenExceptionIsPresent()
 {
     $description = new Description(['operations' => ['foo' => ['uri' => 'http://httpbin.org/{foo}', 'httpMethod' => 'GET', 'responseModel' => 'j', 'parameters' => ['bar' => ['type' => 'string', 'required' => true, 'location' => 'uri']]]]]);
     $client = new GuzzleClient(new Client(), $description);
     $client->getHttpClient()->getEmitter()->attach(new Mock([new Response(404)]));
     $client->foo(['bar' => 'baz']);
 }
Ejemplo n.º 2
0
 public function testVisitsNestedProperties()
 {
     $hclient = new Client();
     $hclient->getEmitter()->on('before', function (BeforeEvent $event) {
         $json = ['nested' => ['foo' => 'abc', 'bar' => 123, 'bam' => ['abc' => 456]], 'baz' => 'boo'];
         $response = new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode($json)));
         $event->intercept($response);
     });
     $description = new Description(['operations' => ['foo' => ['uri' => 'http://httpbin.org', 'httpMethod' => 'GET', 'responseModel' => 'j']], 'models' => ['j' => ['type' => 'object', 'properties' => ['nested' => ['location' => 'json', 'type' => 'object', 'properties' => ['foo' => ['type' => 'string'], 'bar' => ['type' => 'number'], 'bam' => ['type' => 'object', 'properties' => ['abc' => ['type' => 'number']]]]]], 'additionalProperties' => ['location' => 'json', 'type' => 'string', 'filters' => ['strtoupper']]]]]);
     $client = new GuzzleClient($hclient, $description);
     $result = $client->foo();
     $expected = ['nested' => ['foo' => 'abc', 'bar' => 123, 'bam' => ['abc' => 456]], 'baz' => 'BOO'];
     $this->assertEquals($expected, $result->toArray());
 }
 public function testVisitsNullResponseProperties()
 {
     $hclient = new Client();
     $hclient->getEmitter()->on('before', function (BeforeEvent $event) {
         $json = ['data' => ['link' => null]];
         $response = new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode($json)));
         $event->intercept($response);
     });
     $description = new Description(['operations' => ['foo' => ['uri' => 'http://httpbin.org', 'httpMethod' => 'GET', 'responseModel' => 'j']], 'models' => ['j' => ['type' => 'object', 'location' => 'json', 'properties' => ['scalar' => ['type' => 'string'], 'data' => ['type' => 'object', 'location' => 'json', 'properties' => ['link' => ['name' => 'val', 'type' => 'string', 'location' => 'json']], 'additionalProperties' => false]]]]]);
     $client = new GuzzleClient($hclient, $description);
     $result = $client->foo();
     $expected = ['data' => ['link' => null]];
     $this->assertEquals($expected, $result);
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider nestedProvider
  */
 public function testVisitsNestedProperties($desc)
 {
     $hclient = new Client();
     $hclient->getEmitter()->on('before', function (BeforeEvent $event) {
         $json = ['nested' => ['foo' => 'abc', 'bar' => 123, 'bam' => ['abc' => 456]], 'baz' => 'boo'];
         $response = new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode($json)));
         $event->intercept($response);
     });
     $description = new Description($desc);
     $client = new GuzzleClient($hclient, $description);
     $result = $client->foo();
     $expected = ['nested' => ['foo' => 'abc', 'bar' => 123, 'bam' => ['abc' => 456]], 'baz' => 'BOO'];
     $this->assertEquals($expected, $result);
 }