/** * Creates a callable function used to create command objects from a * service description. * * @param Description $description Service description * * @return callable Returns a command factory */ public static function defaultCommandFactory(Description $description) { return function ($name, array $args = [], GuzzleClientInterface $client) use($description) { $operation = null; if ($description->hasOperation($name)) { $operation = $description->getOperation($name); } else { $name = ucfirst($name); if ($description->hasOperation($name)) { $operation = $description->getOperation($name); } } if (!$operation) { return null; } return new Command($operation, $args, clone $client->getEmitter()); }; }
/** * test getParametersForSignature * * @param string $operation * @param array $params * @param array $expectedSignatureParams * * @dataProvider dataGetParametersForSignature */ public function testGetParametersForSignature($operation, $params, $expectedSignatureParams) { $description = new Description(json_decode(file_get_contents(__DIR__ . '/../Data/service.json'), true)); //$client = new GuzzleClient(new Client(), $description); $operation = $description->getOperation($operation); $method = new \ReflectionMethod('Wk\\AmazonMwsApi\\Services\\MwsConnection', 'getParametersForSignature'); $method->setAccessible(true); $args = array($operation, $params); $this->assertEquals($expectedSignatureParams, $method->invokeArgs($this->mwsConnection, $args)); }
private function resolveExtends($name, array $config) { if (!$this->description->hasOperation($name)) { throw new \InvalidArgumentException('No operation named ' . $name); } // Merge parameters together one level deep $base = $this->description->getOperation($name)->toArray(); $result = $config + $base; if (isset($base['parameters']) && isset($config['parameters'])) { $result['parameters'] = $config['parameters'] + $base['parameters']; } return $result; }
public function testCanExtendFromOtherOperations() { $d = new Description(['operations' => ['A' => ['parameters' => ['A' => ['type' => 'object', 'properties' => ['foo' => ['type' => 'string']]], 'B' => ['type' => 'string']], 'summary' => 'foo'], 'B' => ['extends' => 'A', 'summary' => 'Bar'], 'C' => ['extends' => 'B', 'summary' => 'Bar', 'parameters' => ['B' => ['type' => 'number']]]]]); $a = $d->getOperation('A'); $this->assertEquals('foo', $a->getSummary()); $this->assertTrue($a->hasParam('A')); $this->assertEquals('string', $a->getParam('B')->getType()); $b = $d->getOperation('B'); $this->assertTrue($a->hasParam('A')); $this->assertEquals('Bar', $b->getSummary()); $this->assertEquals('string', $a->getParam('B')->getType()); $c = $d->getOperation('C'); $this->assertTrue($a->hasParam('A')); $this->assertEquals('Bar', $c->getSummary()); $this->assertEquals('number', $c->getParam('B')->getType()); }
public function testHasOperations() { $desc = ['operations' => ['foo' => ['parameters' => ['foo' => ['name' => 'foo']]]]]; $s = new Description($desc); $this->assertInstanceOf('GuzzleHttp\\Command\\Guzzle\\Operation', $s->getOperation('foo')); $this->assertSame($s->getOperation('foo'), $s->getOperation('foo')); }