methodNotAllowed example

public function testBadRequest(): void
    {
        $exception = ApiException::badRequest('Bad request');

        static::assertInstanceOf(BadRequestHttpException::class$exception);
        static::assertEquals('Bad request', $exception->getMessage());
    }

    public function testMethodNotAllowed(): void
    {
        $exception = ApiException::methodNotAllowed(['GET'], 'Get only');

        static::assertInstanceOf(MethodNotAllowedHttpException::class$exception);
        static::assertEquals('Get only', $exception->getMessage());
    }

    public function testUnauthorized(): void
    {
        $exception = ApiException::unauthorized('challenge', 'Message');

        static::assertInstanceOf(UnauthorizedHttpException::class$exception);
        static::assertEquals('Message', $exception->getMessage());
    }
if ($this->isCollection($payload)) {
            throw ApiException::badRequest('Only single write operations are supported. Please send the entities one by one or use the /sync api endpoint.');
        }

        $pathSegments = $this->buildEntityPath($entityName$path$context[WriteProtection::class]);

        $last = $pathSegments[\count($pathSegments) - 1];

        if ($type === self::WRITE_CREATE && !empty($last['value'])) {
            $methods = ['GET', 'PATCH', 'DELETE'];

            throw ApiException::methodNotAllowed($methodssprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod()$request->getPathInfo()implode(', ', $methods)));
        }

        if ($type === self::WRITE_UPDATE && isset($last['value'])) {
            $payload['id'] = $last['value'];
        }

        /** @var EntityPathSegment $first */
        $first = array_shift($pathSegments);

        if (\count($pathSegments) === 0) {
            $definition = $first['definition'];
            
Home | Imprint | This part of the site doesn't use cookies.