/** * @dataProvider caseProvider * * @param $about * @param Service $service * @param $name * @param array $args * @param $serialized */ public function testPassesComplianceTest($about, Service $service, $name, array $args, $serialized) { $endpoint = 'https://api-staging.sellercenter.net'; $client = new SdkClient(['api' => $service, 'credentials' => new NullCredentials(), 'client' => new Client(), 'signature' => $this->getMock('SellerCenter\\SDK\\Commom\\Signature\\SignatureInterface'), 'store' => 'mobly', 'environment' => 'staging', 'endpoint' => $endpoint, 'error_parser' => Service::createErrorParser($service->getProtocol()), 'serializer' => Service::createSerializer($service, $endpoint), 'version' => 'latest']); $factory = new ClientFactory(); /* @var \SellerCenter\SDK\Common\ClientFactory $reflectionClass */ /* @var \ReflectionClass $reflectionClass */ $reflectionClass = new \ReflectionClass($factory); $reflectionMethod = $reflectionClass->getMethod('applyParser'); $reflectionMethod->setAccessible(true); $reflectionMethod->invoke($factory, $client, 'http://foo.com'); $command = $client->getCommand($name, $args); $transaction = new CommandTransaction($client, $command); /** @var callable $serializer */ $serializer = $this->readAttribute($client, 'serializer'); $request = $serializer($transaction); $this->assertEquals($serialized['uri'], $request->getResource()); $body = (string) $request->getBody(); if (!empty($body) && $service->getMetadata('type') == 'rest-xml') { $this->assertXmlStringEqualsXmlString($serialized['body'], $body); } if (isset($serialized['headers'])) { foreach ($serialized['headers'] as $key => $value) { $this->assertSame($value, $request->getHeader($key)); } } }
public function testReturnsApiData() { $s = new Service(function () { return ['metadata' => ['serviceFullName' => 'foo', 'endpointPrefix' => 'bar', 'apiVersion' => 'baz', 'signingName' => 'qux', 'protocol' => 'yak']]; }, '', ''); $this->assertEquals('foo', $s->getServiceFullName()); $this->assertEquals('bar', $s->getEndpointPrefix()); $this->assertEquals('baz', $s->getApiVersion()); $this->assertEquals('qux', $s->getSigningName()); $this->assertEquals('yak', $s->getProtocol()); }
private function handleApiProvider($value, array &$args) { if (!is_callable($value)) { throw new InvalidArgumentException('api_provider must be callable'); } $api = new Service($value, $args['service'], $args['version']); $args['api'] = $api; $args['error_parser'] = Service::createErrorParser($api->getProtocol()); $args['serializer'] = Service::createSerializer($api, $args['endpoint']); }
/** * Applies the listeners needed to parse client models. * * @param Service $api API to create a parser for * @return callable * @throws \UnexpectedValueException */ public static function createParser(Service $api) { static $mapping = ['rest-xml' => 'SellerCenter\\SDK\\Common\\Api\\Parser\\RestXmlParser']; $protocol = $api->getProtocol(); if (isset($mapping[$protocol])) { return new $mapping[$protocol]($api); } else { throw new \UnexpectedValueException('Unknown protocol: ' . $api->getProtocol()); } }