public function onInit(InitEvent $event)
 {
     $command = $event->getCommand();
     $operation = $this->api->getOperation($command->getName());
     $fn = $this->validator;
     $fn($command->getName(), $operation->getInput(), $command->toArray());
 }
 /**
  * @dataProvider testCaseProvider
  */
 public function testPassesComplianceTest($about, Service $service, $name, array $args, $serialized)
 {
     $ep = 'http://dus-bb-api802.dus.via.de';
     $client = new VwsClient(['service' => 'foo', 'api_provider' => function () use($service) {
         return $service->toArray();
     }, 'credentials' => false, 'client' => new Client(), 'region' => 'sandbox', 'endpoint' => $ep, 'error_parser' => Service::createErrorParser($service->getProtocol()), 'serializer' => Service::createSerializer($service, $ep), 'version' => 'latest']);
     $command = $client->getCommand($name, $args);
     $trans = new CommandTransaction($client, $command);
     /** @var callable $serializer */
     $serializer = $this->readAttribute($client, 'serializer');
     $request = $serializer($trans);
     $this->assertEquals($serialized['uri'], $request->getResource());
     $body = (string) $request->getBody();
     switch ($service->getMetadata('type')) {
         case 'json':
         case 'rest-json':
             // Normalize the JSON data.
             $body = str_replace(':', ': ', $request->getBody());
             $body = str_replace(',', ', ', $body);
             break;
     }
     $this->assertEquals($serialized['body'], $body);
     if (isset($serialized['headers'])) {
         foreach ($serialized['headers'] as $key => $value) {
             $this->assertSame($value, $request->getHeader($key));
         }
     }
 }
 public function __invoke(CommandTransaction $trans)
 {
     $command = $trans->command;
     $name = $command->getName();
     $operation = $this->api->getOperation($name);
     return $trans->client->createRequest($operation['http']['method'], $this->endpoint, ['headers' => ['Content-Type' => $this->contentType], 'body' => $this->jsonFormatter->build($operation->getInput(), $command->toArray()), 'config' => ['command' => $command]]);
 }
 public function __invoke(CommandTransaction $trans)
 {
     $command = $trans->command;
     $operation = $this->api->getOperation($command->getName());
     $args = $command->toArray();
     $request = $trans->client->createRequest($operation['http']['method'], $this->buildEndpoint($operation, $args), ['config' => ['command' => $command]]);
     // Ensure that query string lists are serialized as duplicates.
     $request->getQuery()->setAggregator($this->aggregator);
     return $this->serialize($request, $operation, $args);
 }
 /**
  * @dataProvider testCaseProvider
  */
 public function testPassesComplianceTest($about, Service $service, $name, array $expectedResult, $res)
 {
     $parser = Service::createParser($service);
     $command = new Command($name);
     // Create a response based on the serialized property of the test.
     $response = new Response($res['status_code'], $res['headers'], Stream::factory($res['body']));
     $result = $parser($command, $response)->toArray();
     $this->fixTimestamps($result, $service->getOperation($name)->getOutput());
     $this->assertEquals($expectedResult, $result);
 }
 private function applyParser()
 {
     $parser = Service::createParser($this->api);
     $this->getEmitter()->on('process', static function (ProcessEvent $e) use($parser) {
         // Guard against exceptions and injected results.
         if ($e->getException() || $e->getResult()) {
             return;
         }
         // Ensure a response exists in order to parse.
         $response = $e->getResponse();
         if (!$response) {
             throw new \RuntimeException('No response was received.');
         }
         $e->setResult($parser($e->getCommand(), $response));
     });
 }
 public static function _apply_api_provider($value, array &$args)
 {
     $api = new Service(ApiProvider::resolve($value, 'api', $args['service'], $args['version']), $value);
     $args['api'] = $api;
     $args['error_parser'] = Service::createErrorParser($api->getProtocol());
     $args['serializer'] = Service::createSerializer($api, $args['endpoint']);
 }
 /**
  * @dataProvider errorParserProvider
  */
 public function testCreatesRelevantErrorParsers($p, $cl)
 {
     $this->assertInstanceOf($cl, Service::createErrorParser($p));
 }