Skip to content

Commit

Permalink
Fixing test suite after rebase massacre
Browse files Browse the repository at this point in the history
  • Loading branch information
tPl0ch committed Nov 15, 2021
1 parent db440b9 commit a2946cd
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 81 deletions.
7 changes: 5 additions & 2 deletions src/Exception/ExceptionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ private function __construct()
{
$factoryFn = static function (string $exceptionClass): callable {
return static function (int $errorCode, string $errorMessage) use ($exceptionClass): SchemaRegistryException {
return new $exceptionClass($errorMessage, $errorCode);
/** @var SchemaRegistryException $e */
$e = new $exceptionClass($errorMessage, $errorCode);

return $e;
};
};

Expand Down Expand Up @@ -84,7 +87,7 @@ public function hasMappableError(ResponseInterface $response): bool

/**
* @param ResponseInterface $response
* @return array<mixed, mixed>
* @return array<string, mixed>
*/
private function guardAgainstMissingErrorCode(ResponseInterface $response): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public static function validateStringAsJson(string $schema): string

/**
* @param string $jsonString
* @param int $depth
* @param int<1, max> $depth
*
* @return mixed
* @return mixed|array
*
* @throws JsonException
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Registry/Decorators/CachingDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use AvroSchema;
use Exception;
use FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException;
use FlixTech\SchemaRegistryApi\Schema\AvroReference;
use FlixTech\SchemaRegistryApi\Registry;
use FlixTech\SchemaRegistryApi\Registry\Cache\CacheAdapter;
use FlixTech\SchemaRegistryApi\Schema\AvroReference;
use GuzzleHttp\Promise\PromiseInterface;
use function call_user_func;

Expand Down
2 changes: 1 addition & 1 deletion src/Registry/GuzzlePromiseAsyncRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
use FlixTech\SchemaRegistryApi\AsynchronousRegistry;
use FlixTech\SchemaRegistryApi\Constants;
use FlixTech\SchemaRegistryApi\Exception\ExceptionMap;
use FlixTech\SchemaRegistryApi\Schema\AvroReference;
use FlixTech\SchemaRegistryApi\Exception\RuntimeException;
use FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException;
use FlixTech\SchemaRegistryApi\Json;
use FlixTech\SchemaRegistryApi\Requests;
use FlixTech\SchemaRegistryApi\Schema\AvroReference;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Promise\PromiseInterface;
Expand Down
5 changes: 3 additions & 2 deletions src/Registry/Psr18SyncRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException;
use FlixTech\SchemaRegistryApi\Json;
use FlixTech\SchemaRegistryApi\Requests;
use FlixTech\SchemaRegistryApi\Schema\AvroReference;
use FlixTech\SchemaRegistryApi\SynchronousRegistry;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\ClientInterface;
Expand All @@ -37,9 +38,9 @@ public function __construct(ClientInterface $client)
$this->map = ExceptionMap::instance();
}

public function register(string $subject, AvroSchema $schema): int
public function register(string $subject, AvroSchema $schema, AvroReference ...$references): int
{
$request = Requests::registerNewSchemaVersionWithSubjectRequest((string)$schema, $subject);
$request = Requests::registerNewSchemaVersionWithSubjectRequest((string)$schema, $subject, ...$references);

$response = $this->makeRequest($request);
$this->guardAgainstErrorResponse($response);
Expand Down
45 changes: 23 additions & 22 deletions src/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace FlixTech\SchemaRegistryApi;

use Assert\Assert;
use FlixTech\SchemaRegistryApi\Schema\AvroReference;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Utils;
use Psr\Http\Message\RequestInterface;
Expand All @@ -19,7 +20,7 @@ public static function allSubjectsRequest(): RequestInterface
{
return new Request(
'GET',
'/subjects',
'subjects',
Constants::ACCEPT_HEADER
);
}
Expand All @@ -28,7 +29,7 @@ public static function allSubjectVersionsRequest(string $subjectName): RequestIn
{
return new Request(
'GET',
Utils::uriFor("/subjects/$subjectName/versions"),
Utils::uriFor("subjects/$subjectName/versions"),
Constants::ACCEPT_HEADER
);
}
Expand All @@ -37,37 +38,37 @@ public static function singleSubjectVersionRequest(string $subjectName, string $
{
return new Request(
'GET',
Utils::uriFor("/subjects/$subjectName/versions/$versionId"),
Utils::uriFor("subjects/$subjectName/versions/$versionId"),
Constants::ACCEPT_HEADER
);
}

public static function prepareJsonSchemaForTransfer(string $schema): string
public static function prepareJsonSchemaForTransfer(string $schema, AvroReference ...$references): string
{
$decoded = Json::decode($schema);

if (is_array($decoded) && array_key_exists('schema', $decoded)) {
return Json::encode($decoded);
}
$return = [
'schema' => $schema
];

return Json::encode(['schema' => Json::encode($decoded)]);
return !$references
? Json::encode($return)
: Json::encode(array_merge($return, ['references' => $references]));
}

public static function registerNewSchemaVersionWithSubjectRequest(string $schema, string $subjectName): RequestInterface
public static function registerNewSchemaVersionWithSubjectRequest(string $schema, string $subjectName, AvroReference ...$references): RequestInterface
{
return new Request(
'POST',
Utils::uriFor("/subjects/$subjectName/versions"),
Utils::uriFor("subjects/$subjectName/versions"),
Constants::CONTENT_TYPE_HEADER + Constants::ACCEPT_HEADER,
self::prepareJsonSchemaForTransfer(Json::validateStringAsJson($schema))
self::prepareJsonSchemaForTransfer(Json::validateStringAsJson($schema), ...$references),
);
}

public static function checkSchemaCompatibilityAgainstVersionRequest(string $schema, string $subjectName, string $versionId): RequestInterface
{
return new Request(
'POST',
Utils::uriFor("/compatibility/subjects/$subjectName/versions/$versionId"),
Utils::uriFor("compatibility/subjects/$subjectName/versions/$versionId"),
Constants::CONTENT_TYPE_HEADER + Constants::ACCEPT_HEADER,
self::prepareJsonSchemaForTransfer(Json::validateStringAsJson($schema))
);
Expand All @@ -77,7 +78,7 @@ public static function checkIfSubjectHasSchemaRegisteredRequest(string $subjectN
{
return new Request(
'POST',
Utils::uriFor("/subjects/$subjectName"),
Utils::uriFor("subjects/$subjectName"),
Constants::CONTENT_TYPE_HEADER + Constants::ACCEPT_HEADER,
self::prepareJsonSchemaForTransfer(Json::validateStringAsJson($schema))
);
Expand All @@ -87,7 +88,7 @@ public static function schemaRequest(string $id): RequestInterface
{
return new Request(
'GET',
Utils::uriFor("/schemas/ids/$id"),
Utils::uriFor("schemas/ids/$id"),
Constants::ACCEPT_HEADER
);
}
Expand All @@ -96,7 +97,7 @@ public static function defaultCompatibilityLevelRequest(): RequestInterface
{
return new Request(
'GET',
'/config',
'config',
Constants::ACCEPT_HEADER
);
}
Expand Down Expand Up @@ -130,7 +131,7 @@ public static function changeDefaultCompatibilityLevelRequest(string $level): Re
{
return new Request(
'PUT',
'/config',
'config',
Constants::ACCEPT_HEADER,
self::prepareCompatibilityLevelForTransport(self::validateCompatibilityLevel($level))
);
Expand All @@ -140,7 +141,7 @@ public static function subjectCompatibilityLevelRequest(string $subjectName): Re
{
return new Request(
'GET',
Utils::uriFor("/config/$subjectName"),
Utils::uriFor("config/$subjectName"),
Constants::ACCEPT_HEADER
);
}
Expand All @@ -149,7 +150,7 @@ public static function changeSubjectCompatibilityLevelRequest(string $subjectNam
{
return new Request(
'PUT',
Utils::uriFor("/config/$subjectName"),
Utils::uriFor("config/$subjectName"),
Constants::ACCEPT_HEADER,
self::prepareCompatibilityLevelForTransport(self::validateCompatibilityLevel($level))
);
Expand Down Expand Up @@ -194,7 +195,7 @@ public static function deleteSubjectRequest(string $subjectName, bool $permanent

return new Request(
'DELETE',
Utils::uriFor("/subjects/$subjectName?permanent=$query"),
Utils::uriFor("subjects/$subjectName?permanent=$query"),
Constants::ACCEPT_HEADER
);
}
Expand All @@ -211,7 +212,7 @@ public static function deleteSubjectVersionRequest(string $subjectName, string $

return new Request(
'DELETE',
Utils::uriFor("/subjects/$subjectName/versions/$versionId?permanent=$query"),
Utils::uriFor("subjects/$subjectName/versions/$versionId?permanent=$query"),
Constants::ACCEPT_HEADER
);
}
Expand Down
30 changes: 15 additions & 15 deletions src/Requests/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Assert\Assert;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Utils;
use InvalidArgumentException;
use JsonException;
use Psr\Http\Message\RequestInterface;
Expand All @@ -21,10 +20,11 @@
use const FlixTech\SchemaRegistryApi\Constants\VERSION_LATEST;
use function implode;
use function json_decode;
use function sprintf;

/**
* @param string $jsonString
* @param int $depth
* @param int<1, max> $depth
*
* @return mixed
*
Expand Down Expand Up @@ -82,7 +82,7 @@ function allSubjectsRequest(): RequestInterface
{
return new Request(
'GET',
'/subjects',
'subjects',
ACCEPT_HEADER
);
}
Expand All @@ -98,7 +98,7 @@ function allSubjectVersionsRequest(string $subjectName): RequestInterface
{
return new Request(
'GET',
Utils::uriFor("/subjects/$subjectName/versions"),
sprintf("subjects/%s/versions", $subjectName),
ACCEPT_HEADER
);
}
Expand All @@ -115,7 +115,7 @@ function singleSubjectVersionRequest(string $subjectName, string $versionId): Re
{
return new Request(
'GET',
Utils::uriFor("/subjects/$subjectName/versions/$versionId"),
sprintf("subjects/%s/versions/%s", $subjectName, $versionId),
ACCEPT_HEADER
);
}
Expand All @@ -133,7 +133,7 @@ function registerNewSchemaVersionWithSubjectRequest(string $schema, string $subj
{
return new Request(
'POST',
Utils::uriFor("/subjects/$subjectName/versions"),
sprintf("subjects/%s/versions", $subjectName),
CONTENT_TYPE_HEADER + ACCEPT_HEADER,
prepareJsonSchemaForTransfer(validateSchemaStringAsJson($schema))
);
Expand All @@ -153,7 +153,7 @@ function checkSchemaCompatibilityAgainstVersionRequest(string $schema, string $s
{
return new Request(
'POST',
Utils::uriFor("/compatibility/subjects/$subjectName/versions/$versionId"),
sprintf("compatibility/subjects/%s/versions/%s", $subjectName, $versionId),
CONTENT_TYPE_HEADER + ACCEPT_HEADER,
prepareJsonSchemaForTransfer(validateSchemaStringAsJson($schema))
);
Expand All @@ -172,7 +172,7 @@ function checkIfSubjectHasSchemaRegisteredRequest(string $subjectName, string $s
{
return new Request(
'POST',
Utils::uriFor("/subjects/$subjectName"),
sprintf("subjects/%s", $subjectName),
CONTENT_TYPE_HEADER + ACCEPT_HEADER,
prepareJsonSchemaForTransfer(validateSchemaStringAsJson($schema))
);
Expand All @@ -188,7 +188,7 @@ function schemaRequest(string $id): RequestInterface
{
return new Request(
'GET',
Utils::uriFor("/schemas/ids/$id"),
sprintf("schemas/ids/%s", $id),
ACCEPT_HEADER
);
}
Expand All @@ -202,7 +202,7 @@ function defaultCompatibilityLevelRequest(): RequestInterface
{
return new Request(
'GET',
'/config',
'config',
ACCEPT_HEADER
);
}
Expand All @@ -219,7 +219,7 @@ function changeDefaultCompatibilityLevelRequest(string $level): RequestInterface
{
return new Request(
'PUT',
'/config',
'config',
ACCEPT_HEADER,
prepareCompatibilityLevelForTransport(validateCompatibilityLevel($level))
);
Expand All @@ -236,7 +236,7 @@ function subjectCompatibilityLevelRequest(string $subjectName): RequestInterface
{
return new Request(
'GET',
Utils::uriFor("/config/$subjectName"),
sprintf("config/%s", $subjectName),
ACCEPT_HEADER
);
}
Expand All @@ -254,7 +254,7 @@ function changeSubjectCompatibilityLevelRequest(string $subjectName, string $lev
{
return new Request(
'PUT',
Utils::uriFor("/config/$subjectName"),
sprintf("config/%s", $subjectName),
ACCEPT_HEADER,
prepareCompatibilityLevelForTransport(validateCompatibilityLevel($level))
);
Expand Down Expand Up @@ -377,7 +377,7 @@ function deleteSubjectRequest(string $subjectName): RequestInterface
{
return new Request(
'DELETE',
Utils::uriFor("/subjects/$subjectName"),
sprintf("subjects/%s", $subjectName),
ACCEPT_HEADER
);
}
Expand All @@ -394,7 +394,7 @@ function deleteSubjectVersionRequest(string $subjectName, string $versionId): Re
{
return new Request(
'DELETE',
Utils::uriFor("/subjects/$subjectName/versions/$versionId"),
sprintf("subjects/%s/versions/%s", $subjectName, $versionId),
ACCEPT_HEADER
);
}
1 change: 0 additions & 1 deletion test/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Utils;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;

Expand Down
Loading

0 comments on commit a2946cd

Please sign in to comment.