Skip to content

Commit 3d80b85

Browse files
authored
feat(MPM-384): Remove return type for getSchemaDefinitionByVersion to allow optimized primitive schemas (#14)
* Bump alpine * Bump deps * Remove return type for getSchemaDefinitionByVersion * Update return type
1 parent 0e752d0 commit 3d80b85

5 files changed

+29
-13
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
"psr/http-client": "^1.0.1"
2323
},
2424
"require-dev": {
25-
"infection/infection": "^0.21",
25+
"infection/infection": "^0.25",
2626
"kriswallsmith/buzz": "^1.0",
2727
"nyholm/psr7": "^1.2",
2828
"php-mock/php-mock-phpunit": "^2.6",
29-
"phpstan/phpstan": "^0.12",
29+
"phpstan/phpstan": "^1.2",
3030
"phpunit/phpunit": "^9.5",
3131
"pimple/pimple": "^3.2",
3232
"rregeer/phpunit-coverage-check": "^0.3.1",

docker/dev/php/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:7.4-cli-alpine3.13
1+
FROM php:7.4-cli-alpine3.15
22

33
ARG HOST_USER_ID
44

src/KafkaSchemaRegistryApiClient.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ public function getSchemaByVersion(string $subjectName, string $version = self::
6565
/**
6666
* @param string $subjectName
6767
* @param string $version
68-
* @return array<string,mixed>
68+
* @return array<string, mixed>|string
6969
* @throws ClientExceptionInterface
7070
* @throws SchemaRegistryExceptionInterface
7171
* @throws JsonException
7272
*/
73-
public function getSchemaDefinitionByVersion(string $subjectName, string $version = self::VERSION_LATEST): array
73+
public function getSchemaDefinitionByVersion(string $subjectName, string $version = self::VERSION_LATEST)
7474
{
7575
return $this
7676
->httpClient
7777
->call(
7878
'GET',
7979
sprintf('subjects/%s/versions/%s/schema', $subjectName, $version)
80-
) ?? [];
80+
);
8181
}
8282

8383
/**

src/KafkaSchemaRegistryApiClientInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public function getSchemaByVersion(string $subjectName, string $version = 'lates
5252
/**
5353
* @param string $subjectName
5454
* @param string $version
55-
* @return array<string,mixed>
55+
* @return array<string, mixed>|string
5656
* @throws ClientExceptionInterface
5757
* @throws SchemaRegistryExceptionInterface
5858
* @throws JsonException
5959
*/
60-
public function getSchemaDefinitionByVersion(string $subjectName, string $version = self::VERSION_LATEST): array;
60+
public function getSchemaDefinitionByVersion(string $subjectName, string $version = self::VERSION_LATEST);
6161

6262
/**
6363
* @param string $subjectName

tests/KafkaSchemaRegistryApiClientTest.php

+21-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ private function getHttpClientMock(): MockObject
3030
->getMockBuilder(HttpClient::class)
3131
->disableOriginalConstructor()
3232
->onlyMethods(['call'])
33-
->getMock();
33+
->getMock();
3434
}
35-
35+
3636
public function testGetSubjects(): void
3737
{
3838
$httpClientMock = $this->getHttpClientMock();
@@ -59,7 +59,7 @@ public function testGetAllSubjectVersions(): void
5959
public function testGetSchemaByVersion(): void
6060
{
6161
$httpClientMock = $this->getHttpClientMock();
62-
62+
6363
$httpClientMock
6464
->expects($this->once())
6565
->method('call')
@@ -72,7 +72,7 @@ public function testGetSchemaByVersion(): void
7272
$this->assertSame(['schema' => '{}'], $result);
7373
}
7474

75-
public function testGetSchemaDefinitionByVersion(): void
75+
public function testGetSchemaDefinitionByVersionForComplexSchema(): void
7676
{
7777
$httpClientMock = $this->getHttpClientMock();
7878

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

91+
public function testGetSchemaDefinitionByVersionForOptimizedPrimitiveSchema(): void
92+
{
93+
$httpClientMock = $this->getHttpClientMock();
94+
95+
$httpClientMock
96+
->expects($this->once())
97+
->method('call')
98+
->with('GET', sprintf('subjects/%s/versions/%s/schema', self::TEST_SUBJECT_NAME, self::TEST_VERSION))
99+
->willReturn("string");
100+
101+
$api = new KafkaSchemaRegistryApiClient($httpClientMock);
102+
$result = $api->getSchemaDefinitionByVersion(self::TEST_SUBJECT_NAME, self::TEST_VERSION);
103+
104+
$this->assertSame("string", $result);
105+
}
106+
91107
public function testDeleteSchemaVersion(): void
92108
{
93109
$httpClientMock = $this->getHttpClientMock();
@@ -248,7 +264,7 @@ public function testSetSubjectCompatibilityLevel(): void
248264
self::TEST_SUBJECT_NAME,
249265
KafkaSchemaRegistryApiClientInterface::LEVEL_FULL
250266
);
251-
267+
252268
$this->assertTrue($result);
253269
}
254270

0 commit comments

Comments
 (0)