Пример #1
0
 public static function serializeOptions(Operation $operation, array $userValues = [])
 {
     $options = ['headers' => []];
     $jsonSerializer = new JsonSerializer();
     foreach ($userValues as $paramName => $paramValue) {
         if (null === ($schema = $operation->getParam($paramName))) {
             continue;
         }
         switch ($schema->getLocation()) {
             case 'query':
                 $options['query'][$schema->getName()] = $paramValue;
                 break;
             case 'header':
                 $options['headers'] += self::parseHeader($schema, $paramName, $paramValue);
                 break;
             case 'json':
                 $json = isset($options['json']) ? $options['json'] : [];
                 $options['json'] = $jsonSerializer->stockJson($schema, $paramValue, $json);
                 break;
             case 'raw':
                 $options['body'] = $paramValue;
                 break;
         }
     }
     if (!empty($options['json']) && ($key = $operation->getJsonKey())) {
         $options['json'] = [$key => $options['json']];
     }
     return $options;
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function test_exception_is_thrown_when_non_stdClass_or_serializable_object_provided()
 {
     $subParam = $this->prophesize(Parameter::class);
     $subParam->isArray()->shouldBeCalled()->willReturn(false);
     $subParam->isObject()->shouldBeCalled()->willReturn(true);
     $param = $this->prophesize(Parameter::class);
     $param->isArray()->shouldBeCalled()->willReturn(false);
     $param->isObject()->shouldBeCalled()->willReturn(true);
     $param->getProperty('subResource')->shouldBeCalled()->willReturn($subParam);
     $userValues = ['subResource' => new NonSerializableResource()];
     $this->serializer->stockJson($param->reveal(), $userValues, []);
 }