Open Journal Systems  3.3.0
OperationCommandTest.php
1 <?php
2 
4 
14 
19 {
20  public function testHasRequestSerializer()
21  {
22  $operation = new OperationCommand();
23  $a = $operation->getRequestSerializer();
25  $operation->setRequestSerializer($b);
26  $this->assertNotSame($a, $operation->getRequestSerializer());
27  }
28 
30  {
31  $op = new OperationCommand(array(), new Operation());
32  $op->setClient(new Client());
33  $s = $this->getMockBuilder('Guzzle\Service\Command\RequestSerializerInterface')
34  ->setMethods(array('prepare'))
35  ->getMockForAbstractClass();
36  $s->expects($this->once())
37  ->method('prepare')
38  ->will($this->returnValue(new EntityEnclosingRequest('POST', 'http://foo.com')));
39  $op->setRequestSerializer($s);
40  $op->prepare();
41  }
42 
44  {
45  $op = new OperationCommand(array(), new Operation());
46  $p = $this->getMockBuilder('Guzzle\Service\Command\ResponseParserInterface')
47  ->setMethods(array('parse'))
48  ->getMockForAbstractClass();
49  $p->expects($this->once())
50  ->method('parse')
51  ->will($this->returnValue(array('foo' => 'bar')));
52  $op->setResponseParser($p);
53  $op->setClient(new Client());
54  $request = $op->prepare();
55  $request->setResponse(new Response(200), true);
56  $this->assertEquals(array('foo' => 'bar'), $op->execute());
57  }
58 
60  {
61  $description = ServiceDescription::factory(array(
62  'operations' => array(
63  'foo' => array('responseClass' => 'bar', 'responseType' => 'model')
64  ),
65  'models' => array(
66  'bar' => array(
67  'type' => 'object',
68  'properties' => array(
69  'Baz' => array('type' => 'string', 'location' => 'xml')
70  )
71  )
72  )
73  ));
74 
75  $op = new OperationCommand(array(), $description->getOperation('foo'));
76  $op->setClient(new Client());
77  $request = $op->prepare();
78  $request->setResponse(new Response(200, array(
79  'Content-Type' => 'application/xml'
80  ), '<Foo><Baz>Bar</Baz></Foo>'), true);
81  $result = $op->execute();
82  $this->assertEquals(new Model(array('Baz' => 'Bar')), $result);
83  }
84 
85  public function testAllowsRawResponses()
86  {
87  $description = new ServiceDescription(array(
88  'operations' => array('foo' => array('responseClass' => 'bar', 'responseType' => 'model')),
89  'models' => array('bar' => array())
90  ));
91  $op = new OperationCommand(array(
93  ), $description->getOperation('foo'));
94  $op->setClient(new Client());
95  $request = $op->prepare();
96  $response = new Response(200, array(
97  'Content-Type' => 'application/xml'
98  ), '<Foo><Baz>Bar</Baz></Foo>');
99  $request->setResponse($response, true);
100  $this->assertSame($response, $op->execute());
101  }
102 }
Guzzle\Service\Command\LocationVisitor\VisitorFlyweight
Definition: VisitorFlyweight.php:12
$op
$op
Definition: lib/pkp/pages/help/index.php:18
Guzzle\Service\Description\Operation
Definition: Operation.php:10
Guzzle\Tests\GuzzleTestCase
Definition: GuzzleTestCase.php:22
Guzzle\Service\Client
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Service/Client.php:25
Guzzle\Service\Command\DefaultRequestSerializer
Definition: DefaultRequestSerializer.php:14
Guzzle\Service\Description\ServiceDescription\factory
static factory($config, array $options=array())
Definition: ServiceDescription.php:65
Guzzle\Service\Command\OperationCommand
Definition: OperationCommand.php:10
Guzzle\Http\Message\Response
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php:17
Guzzle\Tests\Service\Command\OperationCommandTest
Definition: OperationCommandTest.php:18
Guzzle\Service\Resource\Model
Definition: Model.php:11
Guzzle\Service\Command\LocationVisitor\VisitorFlyweight\getInstance
static getInstance()
Definition: VisitorFlyweight.php:52
Guzzle\Service\Description\ServiceDescription
Definition: ServiceDescription.php:11
Guzzle\Service\Command\AbstractCommand\TYPE_RAW
const TYPE_RAW
Definition: AbstractCommand.php:39
Guzzle\Tests\Service\Command\OperationCommandTest\testParsesResponsesUsingModelParserWhenMatchingModelIsFound
testParsesResponsesUsingModelParserWhenMatchingModelIsFound()
Definition: OperationCommandTest.php:59
Guzzle\Service\Command\AbstractCommand\RESPONSE_PROCESSING
const RESPONSE_PROCESSING
Definition: AbstractCommand.php:37
Guzzle\Http\Message\EntityEnclosingRequest
Definition: EntityEnclosingRequest.php:14
Guzzle\Tests\Service\Command\OperationCommandTest\testHasRequestSerializer
testHasRequestSerializer()
Definition: OperationCommandTest.php:20
Guzzle\Tests\Service\Command\OperationCommandTest\testPreparesRequestUsingSerializer
testPreparesRequestUsingSerializer()
Definition: OperationCommandTest.php:29
Guzzle\Tests\Service\Command\OperationCommandTest\testAllowsRawResponses
testAllowsRawResponses()
Definition: OperationCommandTest.php:85
Guzzle\Tests\Service\Command
Definition: AbstractCommandTest.php:3
Guzzle\Tests\Service\Command\OperationCommandTest\testParsesResponsesWithResponseParser
testParsesResponsesWithResponseParser()
Definition: OperationCommandTest.php:43