From 8b591d9459e955e97585d260da39cc486b5be6e1 Mon Sep 17 00:00:00 2001 From: Marko Jovanovic <31182987+bajdzun@users.noreply.github.com> Date: Fri, 28 Oct 2022 11:59:12 +0200 Subject: [PATCH] feat(MPM-668): Use additional check but not the result from parser (#43) --- src/Command/RegisterChangedSchemasCommand.php | 7 +++++-- tests/Command/RegisterChangedSchemasCommandTest.php | 6 ------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Command/RegisterChangedSchemasCommand.php b/src/Command/RegisterChangedSchemasCommand.php index 5cfe95b..5c95bc9 100644 --- a/src/Command/RegisterChangedSchemasCommand.php +++ b/src/Command/RegisterChangedSchemasCommand.php @@ -2,6 +2,8 @@ namespace Jobcloud\SchemaConsole\Command; +use AvroSchema; +use AvroSchemaParseException; use Jobcloud\Kafka\SchemaRegistryClient\Exception\SubjectNotFoundException; use Jobcloud\Kafka\SchemaRegistryClient\KafkaSchemaRegistryApiClientInterface; use Jobcloud\SchemaConsole\Helper\SchemaFileHelper; @@ -149,12 +151,13 @@ private function registerFiles( } try { - $this->schemaRegistryApi->registerNewSchemaVersion($schemaName, $localSchema); - } catch (\Throwable $e) { + AvroSchema::parse($localSchema); + } catch (AvroSchemaParseException $e) { $io->writeln(sprintf('Skipping %s for now because %s', $schemaName, $e->getMessage())); $failed[$schemaName] = $schemaName; continue; } + $this->schemaRegistryApi->registerNewSchemaVersion($schemaName, $localSchema); $succeeded[$schemaName] = [ 'name' => $schemaName, diff --git a/tests/Command/RegisterChangedSchemasCommandTest.php b/tests/Command/RegisterChangedSchemasCommandTest.php index 9d3d2dd..ad097ed 100644 --- a/tests/Command/RegisterChangedSchemasCommandTest.php +++ b/tests/Command/RegisterChangedSchemasCommandTest.php @@ -201,12 +201,6 @@ public function testOutputWhenCommandFailsRegisteringASchema(): void 'getLatestSubjectVersion' => '1' ]); - $schemaRegistryApi->expects(self::exactly(10)) - ->method('registerNewSchemaVersion') - ->willThrowException( - new \Exception('Skipping test.schema.1 for now because is not a schema we know about.') - ); - $application = new Application(); $application->add(new RegisterChangedSchemasCommand($schemaRegistryApi)); $command = $application->find('kafka-schema-registry:register:changed');