invalidJsonNotList example

try {
            $result = json_decode($value, true, flags: \JSON_THROW_ON_ERROR);
        } catch (\JsonException $e) {
            throw UtilException::invalidJson($e);
        }

        if (\is_array($result) && \array_is_list($result)) {
            return $result;
        }

        throw UtilException::invalidJsonNotList();
    }
}

        $e = UtilException::invalidJson($p = new \JsonException('invalid'));

        static::assertEquals(Response::HTTP_BAD_REQUEST, $e->getStatusCode());
        static::assertEquals('UTIL_INVALID_JSON', $e->getErrorCode());
        static::assertEquals('JSON is invalid', $e->getMessage());
        static::assertEquals($p$e->getPrevious());
    }

    public function testInvalidJsonNotList(): void
    {
        $e = UtilException::invalidJsonNotList();

        static::assertEquals(Response::HTTP_BAD_REQUEST, $e->getStatusCode());
        static::assertEquals('UTIL_INVALID_JSON_NOT_LIST', $e->getErrorCode());
        static::assertEquals('JSON cannot be decoded to a list', $e->getMessage());
    }
}
Home | Imprint | This part of the site doesn't use cookies.