25 $this->assertEquals(
'123', $command->get(
'test'));
26 $this->assertFalse($command->isPrepared());
27 $this->assertFalse($command->isExecuted());
32 $api =
new Operation(array(
'name' =>
'foobar'));
34 $this->assertEquals(
'foobar', $command->getName());
37 $this->assertEquals(
'mock_command', $command->getName());
40 $this->assertEquals(
'sub.sub', $command->getName());
49 $command->getRequest();
58 $command->setClient($client);
59 $this->assertSame($response, $command->getResponse());
60 $this->assertSame($response, $command->getResponse());
69 $command->setClient($client);
70 $this->assertSame($response, $command->getResult());
71 $this->assertSame($response, $command->getResult());
79 $command->setClient($client);
80 $this->assertEquals($client, $command->getClient());
88 $command->setClient($client)->prepare();
89 $this->assertEquals($client, $command->getClient());
90 $this->assertTrue($command->isPrepared());
97 'Content-Type' =>
'application/xml'
98 ),
'<xml><data>123</data></xml>');
101 $this->assertSame($command, $command->setClient($client));
104 $this->assertInstanceOf(
'SimpleXMLElement', $command->execute());
106 $this->assertTrue($command->isPrepared());
107 $this->assertTrue($command->isExecuted());
108 $this->assertSame($response, $command->getResponse());
109 $this->assertInstanceOf(
'Guzzle\\Http\\Message\\Request', $command->getRequest());
111 $this->assertInstanceOf(
'SimpleXMLElement', $command->getResult());
112 $this->assertEquals(
'123', (
string) $command->getResult()->data);
120 'Content-Type' =>
'application/json'
121 ),
'{ "key": "Hi!" }'
125 $command->setClient($client);
127 $this->assertEquals(array(
129 ), $command->getResult());
137 $json =
'{ "key": "Hi!" }invalid';
141 if (json_decode($json) && JSON_ERROR_NONE === json_last_error()) {
142 $this->markTestSkipped(
'php-pecl-json library regression issues');
148 'Content-Type' =>
'application/json'
153 $command->setClient($client);
162 'Content-Type' =>
'application/octet-stream'
166 $client->execute($command);
169 $this->assertFalse($command->getResult() instanceof \SimpleXMLElement);
193 $command->getRequestHeaders()->set(
'test',
'123');
194 $this->assertInstanceOf(
'Guzzle\Common\Collection', $command->getRequestHeaders());
195 $this->assertEquals(
'123', $command->getRequestHeaders()->get(
'test'));
197 $command->setClient($this->
getClient())->prepare();
198 $this->assertEquals(
'123', (
string) $command->getRequest()->getHeader(
'test'));
204 $this->assertInstanceOf(
'Guzzle\Common\Collection', $command->getRequestHeaders());
205 $this->assertEquals(
'Bar', $command->getRequestHeaders()->get(
'Foo'));
208 private function getOperation()
212 'httpMethod' =>
'POST',
213 'class' =>
'Guzzle\\Tests\\Service\\Mock\\Command\\MockCommand',
214 'parameters' => array(
224 $api = $this->getOperation();
226 $this->assertSame($api, $command->getOperation());
227 $command->setClient($this->
getClient())->prepare();
228 $this->assertEquals(
'123', $command->get(
'test'));
229 $this->assertSame($api, $command->getOperation($api));
235 $command =
new MockCommand(array(), $this->getOperation());
236 $command->setClient($client);
239 $this->assertTrue($command->isPrepared());
241 $command2 = clone $command;
242 $this->assertFalse($command2->isPrepared());
250 $testFunction =
function($command) use (&$called, $that) {
252 $that->assertInstanceOf(
'Guzzle\Service\Command\CommandInterface', $command);
257 'command.on_complete' => $testFunction
258 ), $this->getOperation());
259 $command->setClient($client);
261 $command->prepare()->setResponse(
new Response(200),
true);
263 $this->assertEquals(1, $called);
273 $command->setOnComplete(
'foo');
279 $client->getEventDispatcher()->addSubscriber(
new MockPlugin(array(
283 $client->execute($command);
284 $command->setResult(
'foo!');
285 $this->assertEquals(
'foo!', $command->getResult());
290 $command = $this->getMockBuilder(
'Guzzle\\Service\\Command\\AbstractCommand')
291 ->setConstructorArgs(array(array(
294 'parameters' => array(
300 ->getMockForAbstractClass();
302 $this->assertEquals(
'bar', $command[
'foo']);
303 $this->assertEquals(
'baaar', $command[
'baz']);
310 'curl.options' => array(
'CURLOPT_PROXYPORT' => 8080)
313 $command->setClient($client);
314 $request = $command->prepare();
315 $this->assertEquals(8080, $request->getCurlOptions()->get(CURLOPT_PROXYPORT));
324 $command->setClient($client);
326 $this->assertSame($response, $command());
331 $command = $this->getMockBuilder(
'Guzzle\Service\Command\AbstractCommand')->getMockForAbstractClass();
332 $this->assertInstanceOf(
'Guzzle\Service\Description\Operation', $command->getOperation());
337 $command = $this->getMockBuilder(
'Guzzle\Service\Command\AbstractCommand')->getMockForAbstractClass();
339 $command->setValidator($v);
340 $this->assertSame($v, $this->readAttribute($command,
'validator'));
347 $v = $this->getMockBuilder(
'Guzzle\Service\Description\SchemaValidator')
348 ->setMethods(array(
'validate'))
350 $v->expects($this->never())->method(
'validate');
351 $command->setValidator($v);
358 $command =
new MockCommand(array(
'test' => 123,
'foo' =>
'bar'));
361 $this->assertEquals(123, $command->get(
'test'));
362 $this->assertEquals(
'bar', $command->get(
'foo'));
370 $this->assertEquals(123, $command->get(
'test'));
371 $this->assertEquals(
'abc', $command->get(
'_internal'));
382 $v = $this->getMockBuilder(
'Guzzle\Service\Description\SchemaValidator')
383 ->setMethods(array(
'validate',
'getErrors'))
385 $v->expects($this->any())->method(
'validate')->will($this->returnValue(
false));
386 $v->expects($this->any())->method(
'getErrors')->will($this->returnValue(array(
'[Foo] Baz',
'[Bar] Boo')));
387 $command->setValidator($v);
398 'operations' => array(
400 'parameters' => array(
401 'baz' => array(
'type' =>
'integer')
403 'additionalParameters' => array(
411 $client->setDescription($description);
412 $command = $client->getCommand(
'foo', array(
414 'command.headers' => array(
'foo' =>
'bar')
421 $validationErrors = array(
'[Foo] Baz',
'[Bar] Boo');
425 $this->assertFalse($command->getValidationErrors());
427 $v = $this->getMockBuilder(
'Guzzle\Service\Description\SchemaValidator')
428 ->setMethods(array(
'validate',
'getErrors'))
430 $v->expects($this->any())->method(
'getErrors')->will($this->returnValue($validationErrors));
431 $command->setValidator($v);
433 $this->assertEquals($validationErrors, $command->getValidationErrors());
442 $request = $command->prepare();
443 $this->assertSame($body, $this->readAttribute($request,
'responseBody'));