27 $p->addVisitor(
'foo', $visitor);
28 $this->assertSame($visitor, $this->readAttribute($p,
'factory')->getResponseVisitor(
'foo'));
37 $op->setResponseParser($p)->setClient(
new Client());
38 $op->prepare()->setResponse(
new Response(200, array(
'Content-Type' =>
'application/xml'),
'<F><B>C</B></F>'),
true);
39 $this->assertInstanceOf(
'SimpleXMLElement',
$op->execute());
49 $op->setResponseParser($parser)->setClient(
new Client());
50 $op->prepare()->setResponse(
new Response(201),
true);
51 $result =
$op->execute();
52 $this->assertEquals(201, $result[
'code']);
53 $this->assertEquals(
'Created', $result[
'phrase']);
61 $op->setResponseParser($parser)->setClient(
new Client());
62 $op->prepare()->setResponse(
new Response(200, array(
63 'Content-Type' =>
'application/json'
64 ),
'{"baz":"bar","enigma":"123"}'),
true);
65 $result =
$op->execute();
66 $this->assertEquals(array(
71 ), $result->toArray());
78 $operation->setResponseClass(
'Baz')->setResponseType(
'model');
80 $op->setResponseParser($parser)->setClient(
new Client());
81 $op->prepare()->setResponse(
new Response(201),
true);
82 $this->assertInstanceOf(
'Guzzle\Http\Message\Response',
$op->execute());
90 $op->setResponseParser($parser)->setClient(
new Client());
91 $op->prepare()->setResponse(
new Response(200, array(
92 'Content-Type' =>
'application/json'
93 ),
'{"baz":"bar","enigma":"123"}'),
true);
94 $result =
$op->execute();
95 $this->assertInstanceOf(
'Guzzle\Service\Resource\Model', $result);
96 $this->assertEquals(array(
99 ), $result->toArray());
106 $operation = $desc->getOperation(
'test');
108 $op->setResponseParser($parser)->setClient(
new Client());
109 $op->prepare()->setResponse(
new Response(200, array(
110 'Content-Type' =>
'application/json'
111 ),
'{"baz":"bar","enigma":"123"}'),
true);
112 $result =
$op->execute();
113 $this->assertSame($result->getStructure(), $desc->getModel(
'Foo'));
120 'operations' => array(
'test' => array(
'responseClass' =>
'Foo')),
124 'properties' => array(
'baz' => array(
'location' =>
'body'))
128 $operation = $description->getOperation(
'test');
130 $op->setResponseParser($parser)->setClient(
new Client());
131 $brokenXml =
'<broken><><><<xml>>>>>';
132 $op->prepare()->setResponse(
new Response(200, array(
133 'Content-Type' =>
'application/xml'
134 ), $brokenXml),
true);
135 $result =
$op->execute();
136 $this->assertEquals(array(
'baz'), $result->getKeys());
137 $this->assertEquals($brokenXml, (
string) $result[
'baz']);
144 'operations' => array(
'test' => array(
'responseClass' =>
'Foo')),
148 'properties' => array(
149 'code' => array(
'location' =>
'statusCode')
151 'additionalProperties' => array(
152 'location' =>
'json',
154 'properties' => array(
157 'filters' =>
'strtoupper'
165 $operation = $description->getOperation(
'test');
167 $op->setResponseParser($parser)->setClient(
new Client());
168 $json =
'[{"a":"test"},{"a":"baz"}]';
169 $op->prepare()->setResponse(
new Response(200, array(
'Content-Type' =>
'application/json'), $json),
true);
170 $result =
$op->execute()->toArray();
171 $this->assertEquals(array(
173 array(
'a' =>
'TEST'),
186 'operations' => array(
'test' => array(
'responseClass' =>
'Foo')),
190 'additionalProperties' =>
false,
191 'properties' => array(
193 'location' =>
'json',
197 'location' =>
'json',
199 'additionalProperties' =>
false,
200 'properties' => array(
206 'code' => array(
'location' =>
'statusCode')
213 $operation = $description->getOperation(
'test');
215 $op->setResponseParser($parser)->setClient(
new Client());
216 $json =
'{"name":"test", "volume":2.0, "nested":{"width":10,"bogus":1}}';
217 $op->prepare()->setResponse(
new Response(200, array(
'Content-Type' =>
'application/json'), $json),
true);
218 $result =
$op->execute()->toArray();
219 $this->assertEquals(array(
232 'operations' => array(
'test' => array(
'responseClass' =>
'Guzzle\Tests\Mock\CustomResponseModel'))
234 $operation = $description->getOperation(
'test');
236 $op->setResponseParser($parser)->setClient(
new Client());
237 $op->prepare()->setResponse(
new Response(200, array(
'Content-Type' =>
'application/json'),
'hi!'),
true);
238 $result =
$op->execute();
239 $this->assertInstanceOf(
'Guzzle\Tests\Mock\CustomResponseModel', $result);
240 $this->assertSame(
$op, $result->command);
251 'operations' => array(
'test' => array(
'responseClass' =>
'Foo\Baz\Bar'))
253 $operation = $description->getOperation(
'test');
255 $op->setResponseParser($parser)->setClient(
new Client());
256 $op->prepare()->setResponse(
new Response(200, array(
'Content-Type' =>
'application/json'),
'hi!'),
true);
268 'operations' => array(
'test' => array(
'responseClass' => __CLASS__))
270 $operation = $description->getOperation(
'test');
272 $op->setResponseParser($parser)->setClient(
new Client());
273 $op->prepare()->setResponse(
new Response(200, array(
'Content-Type' =>
'application/json'),
'hi!'),
true);
280 'operations' => array(
'test' => array(
'responseClass' =>
'Foo')),
284 'properties' => array(
285 'baz' => array(
'type' =>
'string',
'location' =>
'json'),
286 'code' => array(
'location' =>
'statusCode'),
287 'phrase' => array(
'location' =>
'reasonPhrase'),
298 'operations' => array(
'test' => array(
'responseClass' =>
'FooBazBar'))
300 $foo = new \stdClass();
301 $client->getEventDispatcher()->addListener(
'command.parse_response',
function ($e) use ($foo) {
304 $command = $client->getCommand(
'test');
305 $command->prepare()->setResponse(
new Response(200),
true);
306 $result = $command->execute();
307 $this->assertSame($result, $foo);
318 'operations' => array(
'test' => array(
'responseClass' =>
'Foo')),
320 'Baz' => array(
'type' =>
'string'),
323 'additionalProperties' => array(
'$ref' =>
'Baz',
'location' =>
'json')
327 $operation = $description->getOperation(
'test');
329 $op->setResponseParser($parser)->setClient(
new Client());
330 $json =
'{"a":"a","b":"b","c":"c"}';
331 $op->prepare()->setResponse(
new Response(200, array(
'Content-Type' =>
'application/json'), $json),
true);
332 $result =
$op->execute()->toArray();
333 $this->assertEquals(array(
'a' =>
'a',
'b' =>
'b',
'c' =>
'c'), $result);