Example #1
0
 public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
 {
     // parse json
     $parser = $this->templateFactory->newTextParser();
     $response = $parser->parse($request, $context, $configuration->get('patch'));
     // patch
     $patch = new Patch(Json::decode($response, false));
     $body = $patch->patch(Transformer::toStdClass($request->getBody()));
     $body = Transformer::toRecord($body);
     return $this->processor->execute($configuration->get('action'), $request->withBody($body), $context);
 }
    public function testGetActionHandle()
    {
        $action = $this->getActionFactory()->factory(Impl\Action::class);
        $this->assertInstanceOf(ActionInterface::class, $action);
        $parameters = $this->getParameters([]);
        $response = $action->handle($this->getRequest(), $parameters, $this->getContext());
        $actual = json_encode(Transformer::toStdClass($response->getBody()), JSON_PRETTY_PRINT);
        $expect = <<<JSON
{
    "foo": "bar"
}
JSON;
        $this->assertInstanceOf(ResponseInterface::class, $response);
        $this->assertEquals(200, $response->getStatusCode());
        $this->assertEquals([], $response->getHeaders());
        $this->assertJsonStringEqualsJsonString($expect, $actual, $actual);
    }
    public function testHandle()
    {
        $callback = function (Response\FactoryInterface $response) {
            return $response->build(200, [], ['foo' => 'bar']);
        };
        $action = $this->getActionFactory()->factory(CallbackAction::class);
        $response = $action->handle($this->getRequest(), $this->getParameters(['callback' => $callback]), $this->getContext());
        $actual = json_encode(Transformer::toStdClass($response->getBody()), JSON_PRETTY_PRINT);
        $expect = <<<JSON
{
    "foo": "bar"
}
JSON;
        $this->assertInstanceOf(ResponseInterface::class, $response);
        $this->assertEquals(200, $response->getStatusCode());
        $this->assertEquals([], $response->getHeaders());
        $this->assertJsonStringEqualsJsonString($expect, $actual, $actual);
    }
Example #4
0
 protected function parseRequest(MethodAbstract $method)
 {
     if ($method->hasRequest()) {
         if ($method->getRequest()->getDefinition()->getName() == self::SCHEMA_PASSTHRU) {
             return Transformer::toRecord($this->getBody());
         } else {
             return $this->getBodyAs($method->getRequest());
         }
     } else {
         return new Record();
     }
 }
Example #5
0
 public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
 {
     $response = $this->processor->execute($configuration->get('source'), $request, $context);
     $body = Transformer::toRecord($response->getBody());
     return $this->processor->execute($configuration->get('destination'), $request->withBody($body), $context);
 }