Skip to content

Commit

Permalink
feat(MPM-384): Remove return type for getSchemaDefinitionByVersion to…
Browse files Browse the repository at this point in the history
… allow optimized primitive schemas (#14)

* Bump alpine

* Bump deps

* Remove return type for getSchemaDefinitionByVersion

* Update return type
  • Loading branch information
bajdzun authored Dec 14, 2021
1 parent 0e752d0 commit 3d80b85
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"psr/http-client": "^1.0.1"
},
"require-dev": {
"infection/infection": "^0.21",
"infection/infection": "^0.25",
"kriswallsmith/buzz": "^1.0",
"nyholm/psr7": "^1.2",
"php-mock/php-mock-phpunit": "^2.6",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan": "^1.2",
"phpunit/phpunit": "^9.5",
"pimple/pimple": "^3.2",
"rregeer/phpunit-coverage-check": "^0.3.1",
Expand Down
2 changes: 1 addition & 1 deletion docker/dev/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.4-cli-alpine3.13
FROM php:7.4-cli-alpine3.15

ARG HOST_USER_ID

Expand Down
6 changes: 3 additions & 3 deletions src/KafkaSchemaRegistryApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ public function getSchemaByVersion(string $subjectName, string $version = self::
/**
* @param string $subjectName
* @param string $version
* @return array<string,mixed>
* @return array<string, mixed>|string
* @throws ClientExceptionInterface
* @throws SchemaRegistryExceptionInterface
* @throws JsonException
*/
public function getSchemaDefinitionByVersion(string $subjectName, string $version = self::VERSION_LATEST): array
public function getSchemaDefinitionByVersion(string $subjectName, string $version = self::VERSION_LATEST)
{
return $this
->httpClient
->call(
'GET',
sprintf('subjects/%s/versions/%s/schema', $subjectName, $version)
) ?? [];
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/KafkaSchemaRegistryApiClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public function getSchemaByVersion(string $subjectName, string $version = 'lates
/**
* @param string $subjectName
* @param string $version
* @return array<string,mixed>
* @return array<string, mixed>|string
* @throws ClientExceptionInterface
* @throws SchemaRegistryExceptionInterface
* @throws JsonException
*/
public function getSchemaDefinitionByVersion(string $subjectName, string $version = self::VERSION_LATEST): array;
public function getSchemaDefinitionByVersion(string $subjectName, string $version = self::VERSION_LATEST);

/**
* @param string $subjectName
Expand Down
26 changes: 21 additions & 5 deletions tests/KafkaSchemaRegistryApiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ private function getHttpClientMock(): MockObject
->getMockBuilder(HttpClient::class)
->disableOriginalConstructor()
->onlyMethods(['call'])
->getMock();
->getMock();
}

public function testGetSubjects(): void
{
$httpClientMock = $this->getHttpClientMock();
Expand All @@ -59,7 +59,7 @@ public function testGetAllSubjectVersions(): void
public function testGetSchemaByVersion(): void
{
$httpClientMock = $this->getHttpClientMock();

$httpClientMock
->expects($this->once())
->method('call')
Expand All @@ -72,7 +72,7 @@ public function testGetSchemaByVersion(): void
$this->assertSame(['schema' => '{}'], $result);
}

public function testGetSchemaDefinitionByVersion(): void
public function testGetSchemaDefinitionByVersionForComplexSchema(): void
{
$httpClientMock = $this->getHttpClientMock();

Expand All @@ -88,6 +88,22 @@ public function testGetSchemaDefinitionByVersion(): void
$this->assertSame(['a' => 'b'], $result);
}

public function testGetSchemaDefinitionByVersionForOptimizedPrimitiveSchema(): void
{
$httpClientMock = $this->getHttpClientMock();

$httpClientMock
->expects($this->once())
->method('call')
->with('GET', sprintf('subjects/%s/versions/%s/schema', self::TEST_SUBJECT_NAME, self::TEST_VERSION))
->willReturn("string");

$api = new KafkaSchemaRegistryApiClient($httpClientMock);
$result = $api->getSchemaDefinitionByVersion(self::TEST_SUBJECT_NAME, self::TEST_VERSION);

$this->assertSame("string", $result);
}

public function testDeleteSchemaVersion(): void
{
$httpClientMock = $this->getHttpClientMock();
Expand Down Expand Up @@ -248,7 +264,7 @@ public function testSetSubjectCompatibilityLevel(): void
self::TEST_SUBJECT_NAME,
KafkaSchemaRegistryApiClientInterface::LEVEL_FULL
);

$this->assertTrue($result);
}

Expand Down

0 comments on commit 3d80b85

Please sign in to comment.