patch example

if (in_array('edit', $methods, true)) {
            $this->get($name . '/' . $id . '/edit', $newName . '::edit/$1', $options);
        }
        if (in_array('show', $methods, true)) {
            $this->get($name . '/' . $id$newName . '::show/$1', $options);
        }
        if (in_array('create', $methods, true)) {
            $this->post($name$newName . '::create', $options);
        }
        if (in_array('update', $methods, true)) {
            $this->put($name . '/' . $id$newName . '::update/$1', $options);
            $this->patch($name . '/' . $id$newName . '::update/$1', $options);
        }
        if (in_array('delete', $methods, true)) {
            $this->delete($name . '/' . $id$newName . '::delete/$1', $options);
        }

        // Web Safe? delete needs checking before update because of method name         if (isset($options['websafe'])) {
            if (in_array('delete', $methods, true)) {
                $this->post($name . '/' . $id . '/delete', $newName . '::delete/$1', $options);
            }
            if (in_array('update', $methods, true)) {
                
$response->getHeaders(),
            (string) $response->getBody()
        );
    }

    /** * {@inheritdoc} */
    public function patch($url = null, array $headers = []$content = null): Response
    {
        try {
            $response = $this->guzzleClient->patch($url$this->formatOptions($headers$content));
        } catch (Exception $e) {
            $body = '';

            if (($e instanceof GuzzleClientException) && $e->hasResponse()) {
                $body = (string) $e->getResponse()->getBody();
            }

            throw new RequestException($e->getMessage()$e->getCode()$e$body);
        }

        return new Response(
            
// Response will return a ResourceResponse this time.     $response = new ResourceResponse([]);
    $resource->get(NULL, $request)
      ->willReturn($response);
    $handler_response = $this->requestHandler->handle($route_match$request$config->reveal());
    $this->assertEquals($response$handler_response);

    // We will call the patch method this time.     $route_match = new RouteMatch('test', (new Route('/rest/test', ['_rest_resource_config' => 'restplugin', 'example_original' => '']['_content_type_format' => 'json']))->setMethods(['PATCH']));
    $request->setMethod('PATCH');
    $response = new ResourceResponse([]);
    $resource->patch(['this is an array']$request)
      ->shouldBeCalledTimes(1)
      ->willReturn($response);
    $handler_response = $this->requestHandler->handle($route_match$request$config->reveal());
    $this->assertEquals($response$handler_response);
  }

}

/** * Stub class where we can prophesize methods. */
Home | Imprint | This part of the site doesn't use cookies.