protected function getCommandWithArrayParamAndFilters() { $operation = new Operation(array('httpMethod' => 'POST', 'parameters' => array('foo' => new Parameter(array('type' => 'string', 'location' => 'query', 'sentAs' => 'Foo', 'required' => true, 'default' => 'bar', 'filters' => array('strtoupper'))), 'arr' => new Parameter(array('type' => 'array', 'location' => 'query', 'sentAs' => 'Arr', 'required' => true, 'default' => array(123, 456, 789), 'filters' => array(array('method' => 'implode', 'args' => array(',', '@value')))))))); $command = new OperationCommand(array(), $operation); $command->setClient(new MockClient()); return $command; }
/** * @covers Desk\Command\PreValidator::castPrimitivesToArrays * @dataProvider dataCastPrimitivesToArrays * * @param array $param Parameter description/structure * @param mixed $value Input value for the parameter * @param mixed $expected Expected output value */ public function testCastPrimitivesToArrays(array $param, $value, $expected) { $command = new OperationCommand(array('foo' => $value), new Operation(array('parameters' => array('foo' => $param)))); $command->setClient(new Client()); $event = new Event(array('command' => $command)); $preValidator = $this->mock('castPrimitivesToArrays'); $preValidator->castPrimitivesToArrays($event); $this->assertSame($expected, $command->get('foo')); }
public function testAddsContentTypeWhenExpectsIsSetOnCommand() { $op = new OperationCommand(array(), new Operation()); $op['command.expects'] = 'application/json'; $op->setClient(new Client()); $request = $op->prepare(); $request->setResponse(new Response(200, null, '{"Baz":"Bar"}'), true); $this->assertEquals(array('Baz' => 'Bar'), $op->execute()); }
public function testAllowsRawResponses() { $description = new ServiceDescription(array('operations' => array('foo' => array('responseClass' => 'bar', 'responseType' => 'model')), 'models' => array('bar' => array()))); $op = new OperationCommand(array(OperationCommand::RESPONSE_PROCESSING => OperationCommand::TYPE_RAW), $description->getOperation('foo')); $op->setClient(new Client()); $request = $op->prepare(); $response = new Response(200, array('Content-Type' => 'application/xml'), '<Foo><Baz>Bar</Baz></Foo>'); $request->setResponse($response, true); $this->assertSame($response, $op->execute()); }
protected function getCommand($location) { $command = new OperationCommand(array(), $this->getNestedCommand($location)); $command->setClient(new MockClient()); return $command; }