diff --git a/composer.json b/composer.json index 88e6cb9..82142f1 100644 --- a/composer.json +++ b/composer.json @@ -9,14 +9,15 @@ "license": "MIT", "require": { "ext-json": "*", - "flix-tech/avro-php": "^3.0|^4.0", + "flix-tech/avro-php": "^3.0|^4.0|^5.0", "symfony/console": "^4.3|^5.1|^6.0", "nikic/php-parser": "^4.13", "pimple/pimple": "^3.5" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.15", - "infection/infection": "^0.25", + "friendsofphp/php-cs-fixer": "^2.19|^3.15", + "infection/infection": "^0.25|^0.27", + "composer/xdebug-handler": "^2.0|^3.0", "phpstan/phpstan": "^1.2", "phpunit/phpunit": "^9.3", "rregeer/phpunit-coverage-check": "^0.3", diff --git a/example/classes/SomeOtherTestClass.php b/example/classes/SomeOtherTestClass.php index 1c0c5f6..4d7aedf 100644 --- a/example/classes/SomeOtherTestClass.php +++ b/example/classes/SomeOtherTestClass.php @@ -6,5 +6,4 @@ class SomeOtherTestClass { - } diff --git a/example/classes/SomeTestClass.php b/example/classes/SomeTestClass.php index 84d428f..cbeaa9d 100644 --- a/example/classes/SomeTestClass.php +++ b/example/classes/SomeTestClass.php @@ -9,7 +9,6 @@ class SomeTestClass extends SomeBaseClass { - /** * @var string */ diff --git a/example/classes/SomeTestInterface.php b/example/classes/SomeTestInterface.php index 3c30069..283ce4d 100644 --- a/example/classes/SomeTestInterface.php +++ b/example/classes/SomeTestInterface.php @@ -4,5 +4,4 @@ interface SomeTestInterface { - } diff --git a/example/classes/Wonderland/Wonderland.php b/example/classes/Wonderland/Wonderland.php index 7336803..eaef557 100644 --- a/example/classes/Wonderland/Wonderland.php +++ b/example/classes/Wonderland/Wonderland.php @@ -6,5 +6,4 @@ class Wonderland { - } diff --git a/phpstan.neon b/phpstan.neon index d24029b..bb651d1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,11 @@ parameters: level: 8 paths: [ src ] - checkGenericClassInNonGenericObjectType: false \ No newline at end of file + checkGenericClassInNonGenericObjectType: false + excludePaths: + - vendor + ignoreErrors: + # Disable error in class for example of generation + - + message: '#Property PhpKafka\\PhpAvroSchemaGenerator\\Example\\SomeTestClass::\$string is unused.#' + path: example/classes/SomeTestClass.php \ No newline at end of file diff --git a/src/Optimizer/FullNameOptimizer.php b/src/Optimizer/FullNameOptimizer.php index 642a8dc..9d7b192 100644 --- a/src/Optimizer/FullNameOptimizer.php +++ b/src/Optimizer/FullNameOptimizer.php @@ -127,8 +127,8 @@ private function removeNamespaceFromString(string $currentNamespace, $data) $currentNameSpacePaths = explode('.', $currentNamespace); $dataNameSpacePaths = explode('.', $data); - foreach ($dataNameSpacePaths as $idx => $dataNameSpacePath) { - if ($currentNameSpacePaths[$idx] === $dataNameSpacePath) { + foreach ($currentNameSpacePaths as $idx => $currentNameSpacePath) { + if ($currentNameSpacePath === $dataNameSpacePaths[$idx]) { unset($dataNameSpacePaths[$idx]); } else { break; diff --git a/src/Parser/ClassParser.php b/src/Parser/ClassParser.php index d6baa50..ddf24f7 100644 --- a/src/Parser/ClassParser.php +++ b/src/Parser/ClassParser.php @@ -61,7 +61,7 @@ public function getClassName(): ?string } /** - * @return string|null + * @return class-string|null */ public function getParentClassName(): ?string { @@ -74,14 +74,14 @@ public function getParentClassName(): ?string foreach ($statement->stmts as $nsStatement) { if ($nsStatement instanceof Class_) { if (null !== $nsStatement->extends) { - return implode('\\', $nsStatement->extends->parts); + return $this->buildClassName($nsStatement->extends->getParts()); } } } } else { if ($statement instanceof Class_) { if (null !== $statement->extends) { - return implode('\\', $statement->extends->parts); + return $this->buildClassName($statement->extends->getParts()); } } } @@ -90,6 +90,9 @@ public function getParentClassName(): ?string return null; } + /** + * @return class-string[] + */ public function getUsedClasses(): array { $usedClasses = []; @@ -104,8 +107,8 @@ public function getUsedClasses(): array if ($nStatement instanceof Use_) { /** @var UseUse $use */ foreach ($nStatement->uses as $use) { - $className = $use->name->parts[array_key_last($use->name->parts)]; - $usedClasses[$className] = implode('\\', $use->name->parts); + $className = $use->name->getParts()[array_key_last($use->name->getParts())]; + $usedClasses[$className] = $this->buildClassName($use->name->getParts()); } } } @@ -115,6 +118,18 @@ public function getUsedClasses(): array return $usedClasses; } + /** + * @param string[] $parts + * @return class-string + */ + public function buildClassName(array $parts): string + { + /** @var class-string $classname */ + $classname = implode('\\', $parts); + + return $classname; + } + /** * @return string */ @@ -196,7 +211,6 @@ private function getAllClassProperties(Class_ $class, array $properties): array */ private function getParentClassStatements(): ?array { - /** @var class-string[] $usedClasses */ $usedClasses = $this->getUsedClasses(); $parentClass = $this->getParentClassName(); @@ -204,8 +218,8 @@ private function getParentClassStatements(): ?array return []; } - if (null !== $usedClasses[$this->getParentClassName()]) { - $parentClass = $usedClasses[$this->getParentClassName()]; + if (array_key_exists($parentClass, $usedClasses) && null !== $usedClasses[$parentClass]) { + $parentClass = $usedClasses[$parentClass]; } $rc = new ReflectionClass($parentClass); diff --git a/src/Registry/SchemaRegistry.php b/src/Registry/SchemaRegistry.php index ca4ec1b..a64dcfb 100644 --- a/src/Registry/SchemaRegistry.php +++ b/src/Registry/SchemaRegistry.php @@ -135,12 +135,13 @@ private function registerSchemaFile(\SplFileInfo $fileInfo): void } $schemaData = json_decode($fileContent, true, JSON_THROW_ON_ERROR); - $namespace = (string) $schemaData['namespace']; if (null === $schemaData) { throw new SchemaRegistryException(sprintf(SchemaRegistryException::FILE_INVALID, $fileName)); } + $namespace = array_key_exists('namespace', $schemaData) ? (string) $schemaData['namespace'] : ''; + $template = (new SchemaTemplate()) ->withFilename($fileInfo->getBasename()) ->withSchemaDefinition($fileContent) diff --git a/tests/Integration/Parser/ClassParserTest.php b/tests/Integration/Parser/ClassParserTest.php index ccf267c..d712bbf 100644 --- a/tests/Integration/Parser/ClassParserTest.php +++ b/tests/Integration/Parser/ClassParserTest.php @@ -12,45 +12,45 @@ use PHPUnit\Framework\TestCase; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\Parser\ClassParser + * @covers \PhpKafka\PhpAvroSchemaGenerator\Parser\ClassParser */ class ClassParserTest extends TestCase { - public function testGetClassName() + public function testGetClassName(): void { $filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php'; $propertyParser = new ClassPropertyParser(new DocCommentParser()); $parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser); - $parser->setCode(file_get_contents($filePath)); + $parser->setCode((string) file_get_contents($filePath)); self::assertEquals('SomeTestClass', $parser->getClassName()); self::assertEquals('SomeTestClass', $parser->getClassName()); } - public function testGetClassNameForInterface() + public function testGetClassNameForInterface(): void { $filePath = __DIR__ . '/../../../example/classes/SomeTestInterface.php'; $propertyParser = new ClassPropertyParser(new DocCommentParser()); $parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser); - $parser->setCode(file_get_contents($filePath)); + $parser->setCode((string) file_get_contents($filePath)); self::assertNull($parser->getClassName()); } - public function testGetNamespace() + public function testGetNamespace(): void { $filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php'; $propertyParser = new ClassPropertyParser(new DocCommentParser()); $parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser); - $parser->setCode(file_get_contents($filePath)); + $parser->setCode((string) file_get_contents($filePath)); self::assertEquals('PhpKafka\\PhpAvroSchemaGenerator\\Example', $parser->getNamespace()); self::assertEquals('PhpKafka\\PhpAvroSchemaGenerator\\Example', $parser->getNamespace()); } - public function testGetProperties() + public function testGetProperties(): void { $filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php'; $propertyParser = new ClassPropertyParser(new DocCommentParser()); $parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser); - $parser->setCode(file_get_contents($filePath)); + $parser->setCode((string) file_get_contents($filePath)); $properties = $parser->getProperties(); self::assertCount(16, $properties); @@ -65,7 +65,7 @@ public function testClassAndNamespaceAreNullWithNoCode(): void $parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser); $refObject = new \ReflectionObject($parser); $refProperty = $refObject->getProperty('statements'); - $refProperty->setAccessible( true ); + $refProperty->setAccessible(true); $refProperty->setValue($parser, null); self::assertNull($parser->getClassName()); self::assertNull($parser->getNamespace()); diff --git a/tests/Integration/Parser/DocCommentParserTest.php b/tests/Integration/Parser/DocCommentParserTest.php index a15e6cb..1766949 100644 --- a/tests/Integration/Parser/DocCommentParserTest.php +++ b/tests/Integration/Parser/DocCommentParserTest.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\Parser\DocCommentParser + * @covers \PhpKafka\PhpAvroSchemaGenerator\Parser\DocCommentParser */ class DocCommentParserTest extends TestCase { @@ -23,9 +23,9 @@ public function testParseDoc(): void self::assertEquals( [ 'var' => 'string', - 'function-description' =>'' + 'function-description' => '' ], $result ); } -} \ No newline at end of file +} diff --git a/tests/Integration/Registry/ClassRegistryTest.php b/tests/Integration/Registry/ClassRegistryTest.php index 7812c9c..c60b7b2 100644 --- a/tests/Integration/Registry/ClassRegistryTest.php +++ b/tests/Integration/Registry/ClassRegistryTest.php @@ -18,11 +18,11 @@ use SplFileInfo; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\Registry\ClassRegistry + * @covers \PhpKafka\PhpAvroSchemaGenerator\Registry\ClassRegistry */ class ClassRegistryTest extends TestCase { - public function testClassDirectory() + public function testClassDirectory(): void { $propertyParser = new ClassPropertyParser(new DocCommentParser()); $parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser); @@ -34,7 +34,7 @@ public function testClassDirectory() self::assertEquals(['/tmp' => 1], $result->getClassDirectories()); } - public function testLoad() + public function testLoad(): void { $classDir = __DIR__ . '/../../../example/classes'; @@ -54,7 +54,7 @@ public function testLoad() } } - public function testRegisterSchemaFileThatDoesntExist() + public function testRegisterSchemaFileThatDoesntExist(): void { $fileInfo = new SplFileInfo('somenonexistingfile'); $propertyParser = new ClassPropertyParser(new DocCommentParser()); @@ -71,7 +71,7 @@ public function testRegisterSchemaFileThatDoesntExist() $method->invokeArgs($registry, [$fileInfo]); } - public function testRegisterSchemaFileThatIsNotReadable() + public function testRegisterSchemaFileThatIsNotReadable(): void { touch('testfile'); chmod('testfile', 222); diff --git a/tests/Integration/Registry/SchemaRegistryTest.php b/tests/Integration/Registry/SchemaRegistryTest.php index 87a0e00..3834616 100644 --- a/tests/Integration/Registry/SchemaRegistryTest.php +++ b/tests/Integration/Registry/SchemaRegistryTest.php @@ -11,11 +11,11 @@ use SplFileInfo; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\Registry\SchemaRegistry + * @covers \PhpKafka\PhpAvroSchemaGenerator\Registry\SchemaRegistry */ class SchemaRegistryTest extends TestCase { - public function testSchemaDirectories() + public function testSchemaDirectories(): void { $registry = new SchemaRegistry(); $result = $registry->addSchemaTemplateDirectory('/tmp'); @@ -24,7 +24,7 @@ public function testSchemaDirectories() self::assertEquals(['/tmp' => 1], $result->getSchemaDirectories()); } - public function testLoad() + public function testLoad(): void { $schemaIds = [ 'Book', @@ -49,10 +49,12 @@ public function testLoad() $expectedNames = ['CD', 'Collection', 'Page', 'Library']; - self::assertSame(sort($expectedNames), sort($registry->getSchemaNamesPerNamespace('com.example'))); + $actualNamespaces = $registry->getSchemaNamesPerNamespace('com.example'); + + self::assertSame(sort($expectedNames), sort($actualNamespaces)); } - public function testGetRootSchemas() + public function testGetRootSchemas(): void { $schemaDir = __DIR__ . '/../../../example/schemaTemplates'; $registry = (new SchemaRegistry())->addSchemaTemplateDirectory($schemaDir)->load(); @@ -66,14 +68,14 @@ public function testGetRootSchemas() } } - public function testGetSchemaByIdNotExisting() + public function testGetSchemaByIdNotExisting(): void { $registry = new SchemaRegistry(); self::assertNull($registry->getSchemaById('test')); } - public function testGetSchemaById() + public function testGetSchemaById(): void { $template = $this->getMockForAbstractClass(SchemaTemplateInterface::class); @@ -87,7 +89,7 @@ public function testGetSchemaById() self::assertEquals($template, $registry->getSchemaById('test')); } - public function testRegisterSchemaFileThatDoesntExist() + public function testRegisterSchemaFileThatDoesntExist(): void { $fileInfo = new SplFileInfo('somenonexistingfile'); $registry = new SchemaRegistry(); @@ -101,7 +103,7 @@ public function testRegisterSchemaFileThatDoesntExist() $method->invokeArgs($registry, [$fileInfo]); } - public function testRegisterSchemaFileThatIsNotReadable() + public function testRegisterSchemaFileThatIsNotReadable(): void { touch('testfile'); chmod('testfile', 222); @@ -125,7 +127,7 @@ public function testRegisterSchemaFileThatIsNotReadable() } } - public function testRegisterSchemaWithInvalidContent() + public function testRegisterSchemaWithInvalidContent(): void { touch('testfile'); diff --git a/tests/Unit/Generator/SchemaGeneratorTest.php b/tests/Unit/Generator/SchemaGeneratorTest.php index bd4199a..24280f6 100644 --- a/tests/Unit/Generator/SchemaGeneratorTest.php +++ b/tests/Unit/Generator/SchemaGeneratorTest.php @@ -9,11 +9,11 @@ use PHPUnit\Framework\TestCase; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\Generator\SchemaGenerator + * @covers \PhpKafka\PhpAvroSchemaGenerator\Generator\SchemaGenerator */ class SchemaGeneratorTest extends TestCase { - public function testDefaultOutputDirectory() + public function testDefaultOutputDirectory(): void { $registry = $this->getMockForAbstractClass(ClassRegistryInterface::class); @@ -24,7 +24,7 @@ public function testDefaultOutputDirectory() self::assertEquals('/tmp', $generator->getOutputDirectory()); } - public function testGetters() + public function testGetters(): void { $registry = $this->getMockForAbstractClass(ClassRegistryInterface::class); $directory = '/tmp/foo'; @@ -37,7 +37,7 @@ public function testGetters() self::assertEquals($directory, $generator->getOutputDirectory()); } - public function testGenerate() + public function testGenerate(): void { $expectedResult = [ 'name.space.TestClass' => json_encode([ @@ -109,7 +109,7 @@ public function testGenerate() self::assertCount(2, $result); } - public function testGeneratePreservesZeroFraction() + public function testGeneratePreservesZeroFraction(): void { $expectedResult = [ 'name.space.TestClass' => json_encode([ @@ -151,7 +151,7 @@ public function testGeneratePreservesZeroFraction() self::assertCount(1, $result); } - public function testExportSchemas() + public function testExportSchemas(): void { $schemas = [ 'filename' => 'test foo bar' @@ -169,7 +169,7 @@ public function testExportSchemas() unlink('/tmp/filename.avsc'); } - public function testGenerateWithoutRegistry() + public function testGenerateWithoutRegistry(): void { self::expectException(\RuntimeException::class); self::expectExceptionMessage('Please set a ClassRegistry for the generator'); @@ -177,7 +177,7 @@ public function testGenerateWithoutRegistry() $generator = new SchemaGenerator(); $refObject = new \ReflectionObject($generator); $refProperty = $refObject->getProperty('classRegistry'); - $refProperty->setAccessible( true ); + $refProperty->setAccessible(true); $refProperty->setValue($generator, null); $generator->generate(); } diff --git a/tests/Unit/Merger/SchemaMergerTest.php b/tests/Unit/Merger/SchemaMergerTest.php index 1558c21..d64812f 100644 --- a/tests/Unit/Merger/SchemaMergerTest.php +++ b/tests/Unit/Merger/SchemaMergerTest.php @@ -14,11 +14,11 @@ use PHPUnit\Framework\TestCase; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\Merger\SchemaMerger + * @covers \PhpKafka\PhpAvroSchemaGenerator\Merger\SchemaMerger */ class SchemaMergerTest extends TestCase { - public function testGetSchemaRegistry() + public function testGetSchemaRegistry(): void { $schemaRegistry = $this->getMockForAbstractClass(SchemaRegistryInterface::class); $merger = new SchemaMerger(); @@ -26,20 +26,20 @@ public function testGetSchemaRegistry() self::assertEquals($schemaRegistry, $merger->getSchemaRegistry()); } - public function testGetOutputDirectoryDefault() + public function testGetOutputDirectoryDefault(): void { $merger = new SchemaMerger(); self::assertEquals('/tmp', $merger->getOutputDirectory()); } - public function testGetOutputDirectory() + public function testGetOutputDirectory(): void { $outputDirectory = '/root'; $merger = new SchemaMerger($outputDirectory); self::assertEquals($outputDirectory, $merger->getOutputDirectory()); } - public function testSetOutputDirectory() + public function testSetOutputDirectory(): void { $outputDirectory = '/root'; $merger = new SchemaMerger(); @@ -47,7 +47,7 @@ public function testSetOutputDirectory() self::assertEquals($outputDirectory, $merger->getOutputDirectory()); } - public function testGetResolvedSchemaTemplateThrowsException() + public function testGetResolvedSchemaTemplateThrowsException(): void { self::expectException(\AvroSchemaParseException::class); @@ -60,7 +60,7 @@ public function testGetResolvedSchemaTemplateThrowsException() self::assertEquals([], $merger->getResolvedSchemaTemplate($schemaTemplate)); } - public function testGetResolvedSchemaTemplateResolveEmbeddedException() + public function testGetResolvedSchemaTemplateResolveEmbeddedException(): void { self::expectException(SchemaMergerException::class); self::expectExceptionMessage(sprintf(SchemaMergerException::UNKNOWN_SCHEMA_TYPE_EXCEPTION_MESSAGE, 'com.example.Page')); @@ -85,7 +85,7 @@ public function testGetResolvedSchemaTemplateResolveEmbeddedException() self::assertEquals([], $merger->getResolvedSchemaTemplate($schemaTemplate)); } - public function testGetResolvedSchemaTemplate() + public function testGetResolvedSchemaTemplate(): void { $rootDefinition = '{ "type": "record", @@ -134,7 +134,7 @@ public function testGetResolvedSchemaTemplate() $merger->getResolvedSchemaTemplate($rootSchemaTemplate); } - public function testGetResolvedSchemaTemplateWithMultiEmbedd() + public function testGetResolvedSchemaTemplateWithMultiEmbedd(): void { $rootDefinition = $this->reformatJsonString('{ "type": "record", @@ -305,7 +305,7 @@ public function testGetResolvedSchemaTemplateWithMultiEmbedd() $merger->getResolvedSchemaTemplate($rootSchemaTemplate); } - public function testGetResolvedSchemaTemplateWithDifferentNamespaceForEmbeddedSchema() + public function testGetResolvedSchemaTemplateWithDifferentNamespaceForEmbeddedSchema(): void { $rootDefinition = '{ "type": "record", @@ -356,7 +356,7 @@ public function testGetResolvedSchemaTemplateWithDifferentNamespaceForEmbeddedSc $merger->getResolvedSchemaTemplate($rootSchemaTemplate); } - public function testMergeException() + public function testMergeException(): void { self::expectException(SchemaMergerException::class); self::expectExceptionMessage(sprintf(SchemaMergerException::UNKNOWN_SCHEMA_TYPE_EXCEPTION_MESSAGE, 'com.example.Page')); @@ -386,7 +386,7 @@ public function testMergeException() $merger->merge(); } - public function testMerge() + public function testMerge(): void { $definition = '{ "type": "record", @@ -426,7 +426,7 @@ public function testMerge() rmdir('/tmp/foobar'); } - public function testMergePrimitive() + public function testMergePrimitive(): void { $definition = '{ "type": "string" @@ -461,7 +461,7 @@ public function testMergePrimitive() rmdir('/tmp/foobar'); } - public function testMergePrimitiveWithOptimizerEnabled() + public function testMergePrimitiveWithOptimizerEnabled(): void { $definition = '{ "type": "string" @@ -503,7 +503,7 @@ public function testMergePrimitiveWithOptimizerEnabled() rmdir('/tmp/foobar'); } - public function testMergeWithFilenameOption() + public function testMergeWithFilenameOption(): void { $definition = '{ "type": "record", @@ -543,7 +543,7 @@ public function testMergeWithFilenameOption() rmdir('/tmp/foobar'); } - public function testExportSchema() + public function testExportSchema(): void { $schemaTemplate = $this->getMockForAbstractClass(SchemaTemplateInterface::class); $schemaTemplate @@ -560,7 +560,7 @@ public function testExportSchema() unlink('/tmp/test.avsc'); } - public function testExportSchemaPrimitiveWithWrongOptions() + public function testExportSchemaPrimitiveWithWrongOptions(): void { $schemaTemplate = $this->getMockForAbstractClass(SchemaTemplateInterface::class); $schemaTemplate @@ -586,7 +586,7 @@ public function testExportSchemaPrimitiveWithWrongOptions() unlink('/tmp/test.avsc'); } - public function testMergeWithoutRegistry() + public function testMergeWithoutRegistry(): void { self::expectException(\RuntimeException::class); self::expectExceptionMessage('Please set a SchemaRegistery for the merger'); @@ -599,7 +599,7 @@ public function testMergeWithoutRegistry() $merger->merge(); } - public function testGetResolvedSchemaTemplateWithoutRegistry() + public function testGetResolvedSchemaTemplateWithoutRegistry(): void { self::expectException(\RuntimeException::class); self::expectExceptionMessage('Please set a SchemaRegistery for the merger'); diff --git a/tests/Unit/Optimizer/FieldOrderOptimizerTest.php b/tests/Unit/Optimizer/FieldOrderOptimizerTest.php index 7be0902..7bca7e2 100644 --- a/tests/Unit/Optimizer/FieldOrderOptimizerTest.php +++ b/tests/Unit/Optimizer/FieldOrderOptimizerTest.php @@ -212,7 +212,7 @@ public function testOptimize(): void ] } ] - }'),JSON_PRESERVE_ZERO_FRACTION); + }'), JSON_PRESERVE_ZERO_FRACTION); $schemaTemplate = $this->getMockForAbstractClass(SchemaTemplateInterface::class); $schemaTemplate @@ -230,4 +230,4 @@ public function testOptimize(): void self::assertInstanceOf(SchemaTemplateInterface::class, $optimizer->optimize($schemaTemplate)); } -} \ No newline at end of file +} diff --git a/tests/Unit/Optimizer/FullNameOptimizerTest.php b/tests/Unit/Optimizer/FullNameOptimizerTest.php index 69357e4..8591ea3 100644 --- a/tests/Unit/Optimizer/FullNameOptimizerTest.php +++ b/tests/Unit/Optimizer/FullNameOptimizerTest.php @@ -188,4 +188,4 @@ public function testOptimize(): void self::assertInstanceOf(SchemaTemplateInterface::class, $optimizer->optimize($schemaTemplate)); } -} \ No newline at end of file +} diff --git a/tests/Unit/Optimizer/PrimitiveSchemaOptimizerTest.php b/tests/Unit/Optimizer/PrimitiveSchemaOptimizerTest.php index 2e65ac0..274ca1a 100644 --- a/tests/Unit/Optimizer/PrimitiveSchemaOptimizerTest.php +++ b/tests/Unit/Optimizer/PrimitiveSchemaOptimizerTest.php @@ -83,4 +83,4 @@ public function testOptimizeForRecordSchema(): void self::assertInstanceOf(SchemaTemplateInterface::class, $optimizer->optimize($schemaTemplate)); } -} \ No newline at end of file +} diff --git a/tests/Unit/Parser/ClassPropertyParserTest.php b/tests/Unit/Parser/ClassPropertyParserTest.php index 1811e1f..bf3c729 100644 --- a/tests/Unit/Parser/ClassPropertyParserTest.php +++ b/tests/Unit/Parser/ClassPropertyParserTest.php @@ -38,7 +38,7 @@ public function testParseProperty(): void $property1->props = [$propertyProperty]; $property1->type = $identifier; $property2 = $this->getMockBuilder(Property::class)->disableOriginalConstructor()->getMock(); - $property2->type = 'string'; + $property2->type = new Identifier('string'); $property2->props = [$propertyProperty]; $property3 = $this->getMockBuilder(Property::class)->disableOriginalConstructor()->getMock(); $property3->type = $ut; @@ -63,4 +63,4 @@ public function testParsePropertyExceptionOnNonProperty(): void $cpp->parseProperty(1); } -} \ No newline at end of file +} diff --git a/tests/Unit/PhpClass/PhpClassPropertyTest.php b/tests/Unit/PhpClass/PhpClassPropertyTest.php index 4a59531..97fe192 100644 --- a/tests/Unit/PhpClass/PhpClassPropertyTest.php +++ b/tests/Unit/PhpClass/PhpClassPropertyTest.php @@ -8,11 +8,11 @@ use PHPUnit\Framework\TestCase; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClassProperty + * @covers \PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClassProperty */ class PhpClassPropertyTest extends TestCase { - public function testGetters() + public function testGetters(): void { $property = new PhpClassProperty('propertyName', 'array', 'default', 'doc', 'logicalType'); diff --git a/tests/Unit/PhpClass/PhpClassTest.php b/tests/Unit/PhpClass/PhpClassTest.php index fbe9d40..5a0d079 100644 --- a/tests/Unit/PhpClass/PhpClassTest.php +++ b/tests/Unit/PhpClass/PhpClassTest.php @@ -8,11 +8,11 @@ use PHPUnit\Framework\TestCase; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClass + * @covers \PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClass */ class PhpClassTest extends TestCase { - public function testGetters() + public function testGetters(): void { $phpClass = new PhpClass('TestClass', 'Test\\Space', 'some php code', []); diff --git a/tests/Unit/PhpClassConverterTest.php b/tests/Unit/PhpClassConverterTest.php index 154971f..33e2903 100644 --- a/tests/Unit/PhpClassConverterTest.php +++ b/tests/Unit/PhpClassConverterTest.php @@ -65,4 +65,4 @@ public function testConvertOfNonClass(): void $converter = new PhpClassConverter($parser); self::assertNull($converter->convert('some class stuff')); } -} \ No newline at end of file +} diff --git a/tests/Unit/Schema/SchemaTemplateTest.php b/tests/Unit/Schema/SchemaTemplateTest.php index 8d06ee2..e860fe1 100644 --- a/tests/Unit/Schema/SchemaTemplateTest.php +++ b/tests/Unit/Schema/SchemaTemplateTest.php @@ -9,11 +9,11 @@ use PHPUnit\Framework\TestCase; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\Schema\SchemaTemplate + * @covers \PhpKafka\PhpAvroSchemaGenerator\Schema\SchemaTemplate */ class SchemaTemplateTest extends TestCase { - public function testSchemaId() + public function testSchemaId(): void { $template = (new SchemaTemplate())->withSchemaId('test'); @@ -21,7 +21,7 @@ public function testSchemaId() self::assertEquals('test', $template->getSchemaId()); } - public function testSchemaLevel() + public function testSchemaLevel(): void { $template = (new SchemaTemplate())->withSchemaLevel('root'); @@ -29,7 +29,7 @@ public function testSchemaLevel() self::assertEquals('root', $template->getSchemaLevel()); } - public function testSchemaDefinition() + public function testSchemaDefinition(): void { $template = (new SchemaTemplate())->withSchemaDefinition('test'); @@ -37,7 +37,7 @@ public function testSchemaDefinition() self::assertEquals('test', $template->getSchemaDefinition()); } - public function testFilename() + public function testFilename(): void { $template = (new SchemaTemplate())->withFilename('test'); @@ -45,35 +45,35 @@ public function testFilename() self::assertEquals('test', $template->getFilename()); } - public function testIsPrimitiveTrue() + public function testIsPrimitiveTrue(): void { $template = (new SchemaTemplate())->withSchemaDefinition('{"type":"string"}'); self::assertTrue($template->isPrimitive()); } - public function testIsPrimitiveFalse() + public function testIsPrimitiveFalse(): void { $template = (new SchemaTemplate())->withSchemaDefinition('{"type":"record"}'); self::assertFalse($template->isPrimitive()); } - public function testIsPrimitiveTrueForOptimizedSchema() + public function testIsPrimitiveTrueForOptimizedSchema(): void { $template = (new SchemaTemplate())->withSchemaDefinition('"string"'); self::assertTrue($template->isPrimitive()); } - public function testIsPrimitiveFalseForOptimizedSchema() + public function testIsPrimitiveFalseForOptimizedSchema(): void { $template = (new SchemaTemplate())->withSchemaDefinition('"foo"'); self::assertFalse($template->isPrimitive()); } - public function testIsPrimitiveFalseOnMissingType() + public function testIsPrimitiveFalseOnMissingType(): void { $template = (new SchemaTemplate())->withSchemaDefinition('{"foo":"bar"}'); diff --git a/tests/Unit/ServiceProvider/CommandServiceProviderTest.php b/tests/Unit/ServiceProvider/CommandServiceProviderTest.php index f135972..145bc33 100644 --- a/tests/Unit/ServiceProvider/CommandServiceProviderTest.php +++ b/tests/Unit/ServiceProvider/CommandServiceProviderTest.php @@ -13,7 +13,7 @@ use Pimple\Container; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\ServiceProvider\CommandServiceProvider + * @covers \PhpKafka\PhpAvroSchemaGenerator\ServiceProvider\CommandServiceProvider */ class CommandServiceProviderTest extends TestCase { @@ -30,4 +30,4 @@ public function testRegister(): void self::assertTrue(isset($container['console.commands'])); self::assertEquals(2, count($container['console.commands'])); } -} \ No newline at end of file +} diff --git a/tests/Unit/ServiceProvider/ConverterServiceProviderTest.php b/tests/Unit/ServiceProvider/ConverterServiceProviderTest.php index e02505e..02902e2 100644 --- a/tests/Unit/ServiceProvider/ConverterServiceProviderTest.php +++ b/tests/Unit/ServiceProvider/ConverterServiceProviderTest.php @@ -11,7 +11,7 @@ use Pimple\Container; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\ServiceProvider\ConverterServiceProvider + * @covers \PhpKafka\PhpAvroSchemaGenerator\ServiceProvider\ConverterServiceProvider */ class ConverterServiceProviderTest extends TestCase { @@ -25,4 +25,4 @@ public function testRegister(): void self::assertTrue(isset($container[PhpClassConverterInterface::class])); self::assertInstanceOf(PhpClassConverterInterface::class, $container[PhpClassConverterInterface::class]); } -} \ No newline at end of file +} diff --git a/tests/Unit/ServiceProvider/GeneratorServiceProviderTest.php b/tests/Unit/ServiceProvider/GeneratorServiceProviderTest.php index cca783c..2664138 100644 --- a/tests/Unit/ServiceProvider/GeneratorServiceProviderTest.php +++ b/tests/Unit/ServiceProvider/GeneratorServiceProviderTest.php @@ -10,7 +10,7 @@ use Pimple\Container; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\ServiceProvider\GeneratorServiceProvider + * @covers \PhpKafka\PhpAvroSchemaGenerator\ServiceProvider\GeneratorServiceProvider */ class GeneratorServiceProviderTest extends TestCase { @@ -23,4 +23,4 @@ public function testRegister(): void self::assertTrue(isset($container[SchemaGeneratorInterface::class])); self::assertInstanceOf(SchemaGeneratorInterface::class, $container[SchemaGeneratorInterface::class]); } -} \ No newline at end of file +} diff --git a/tests/Unit/ServiceProvider/MergerServiceProviderTest.php b/tests/Unit/ServiceProvider/MergerServiceProviderTest.php index 419b13b..5328791 100644 --- a/tests/Unit/ServiceProvider/MergerServiceProviderTest.php +++ b/tests/Unit/ServiceProvider/MergerServiceProviderTest.php @@ -10,7 +10,7 @@ use Pimple\Container; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\ServiceProvider\MergerServiceProvider + * @covers \PhpKafka\PhpAvroSchemaGenerator\ServiceProvider\MergerServiceProvider */ class MergerServiceProviderTest extends TestCase { @@ -23,4 +23,4 @@ public function testRegister(): void self::assertTrue(isset($container[SchemaMergerInterface::class])); self::assertInstanceOf(SchemaMergerInterface::class, $container[SchemaMergerInterface::class]); } -} \ No newline at end of file +} diff --git a/tests/Unit/ServiceProvider/ParserServiceProviderTest.php b/tests/Unit/ServiceProvider/ParserServiceProviderTest.php index 89ba158..c28aa44 100644 --- a/tests/Unit/ServiceProvider/ParserServiceProviderTest.php +++ b/tests/Unit/ServiceProvider/ParserServiceProviderTest.php @@ -14,7 +14,7 @@ use Pimple\Container; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\ServiceProvider\ParserServiceProvider + * @covers \PhpKafka\PhpAvroSchemaGenerator\ServiceProvider\ParserServiceProvider */ class ParserServiceProviderTest extends TestCase { @@ -35,4 +35,4 @@ public function testRegister(): void self::assertInstanceOf(ClassParserInterface::class, $container[ClassParserInterface::class]); } -} \ No newline at end of file +} diff --git a/tests/Unit/ServiceProvider/RegistryServiceProviderTest.php b/tests/Unit/ServiceProvider/RegistryServiceProviderTest.php index d8344a8..96253e8 100644 --- a/tests/Unit/ServiceProvider/RegistryServiceProviderTest.php +++ b/tests/Unit/ServiceProvider/RegistryServiceProviderTest.php @@ -12,7 +12,7 @@ use Pimple\Container; /** - * @covers PhpKafka\PhpAvroSchemaGenerator\ServiceProvider\RegistryServiceProvider + * @covers \PhpKafka\PhpAvroSchemaGenerator\ServiceProvider\RegistryServiceProvider */ class RegistryServiceProviderTest extends TestCase { @@ -28,4 +28,4 @@ public function testRegister(): void self::assertTrue(isset($container[SchemaRegistryInterface::class])); self::assertInstanceOf(SchemaRegistryInterface::class, $container[SchemaRegistryInterface::class]); } -} \ No newline at end of file +}