diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 49c3746..890ef91 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -33,6 +33,10 @@ jobs: - version: 8.0 xdebug: 3.1.1 + + - + version: 8.1.0RC3 + xdebug: 3.1.1 runs-on: ubuntu-20.04 steps: - @@ -81,12 +85,18 @@ jobs: - version: 8.0 composer: --prefer-lowest + - + version: 8.1.0RC3 + composer: --prefer-lowest - version: 7.4 composer: --prefer-stable - version: 8.0 composer: --prefer-stable + - + version: 8.1.0RC3 + composer: --prefer-stable steps: - name: Download sources @@ -190,6 +200,7 @@ jobs: run: | chmod a+x bin/wait-for-all.sh bin/wait-for-it.sh make platform + make platform-logs docker run -i --rm --net=host --sig-proxy=true --pid=host \ -v "${GITHUB_WORKSPACE}":"${GITHUB_WORKSPACE}" -w "${GITHUB_WORKSPACE}" php-avro-serde:7.4 \ vendor/bin/phpunit --group integration diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 474bb52..4df4185 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -6,6 +6,13 @@ ->in(['src', 'test']) ; +if (version_compare(PHP_VERSION, '8.1') < 0) { + $finder = $finder + ->notPath('Objects/Schema/Generation/Attributes') + ->notPath('Objects/Schema/Generation/AttributeReader.php') + ->notPath('Objects/Schema/Generation/Fixture/Attributes'); +} + return (new PhpCsFixer\Config()) ->setRules([ '@Symfony' => true, diff --git a/Dockerfile b/Dockerfile index 59c571f..d477231 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ ARG PHP_VERSION=7.4 -FROM php:${PHP_VERSION}-cli-alpine +FROM php:${PHP_VERSION}-cli-alpine3.13 ARG XDEBUG_VERSION=3.1.1 diff --git a/Makefile b/Makefile index 25c6e9f..0b20df7 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ ZOOKEEPER_IPV4 ?= 192.168.104.101 COMPOSER ?= bin/composer.phar COMPOSER_VERSION ?= 2.1.9 PHP_STAN ?= bin/phpstan.phar -PHP_STAN_VERSION ?= 0.12.99 +PHP_STAN_VERSION ?= 1.0.1 PHP_CS_FIXER ?= bin/php-cs-fixer.phar PHP_CS_FIXER_VERSION ?= 3.2.1 PHPUNIT ?= vendor/bin/phpunit @@ -75,6 +75,10 @@ platform: docker-compose up -d bin/wait-for-all.sh +platform-logs: + docker-compose ps + docker-compose logs schema_registry + clean: rm -rf build docker-compose down diff --git a/composer.json b/composer.json index 2a6e6a8..91e877d 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "widmogrod/php-functional": "^6.0" }, "require-dev": { - "phpunit/phpunit": "^8.2.3|^9.4.2", + "phpunit/phpunit": "^9.5.10", "phpbench/phpbench": "1.0.0-alpha2", "vlucas/phpdotenv": "~2.4", "symfony/serializer": "^3.4|^4.3", diff --git a/phpstan-conditional.config.php b/phpstan-conditional.config.php new file mode 100644 index 0000000..911b9fc --- /dev/null +++ b/phpstan-conditional.config.php @@ -0,0 +1,15 @@ + [ + 'src/Objects/Schema/Generation/Attributes/', + 'src/Objects/Schema/Generation/AttributeReader.php' + ], + ]; +} + +return $config; diff --git a/phpstan.neon b/phpstan.neon index c7b1758..0532808 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,3 +1,5 @@ +includes: + - phpstan-conditional.config.php parameters: level: 8 paths: [ src ] diff --git a/src/Objects/Exceptions/Exceptions.php b/src/Objects/Exceptions/Exceptions.php index 0b2a96b..f597ade 100644 --- a/src/Objects/Exceptions/Exceptions.php +++ b/src/Objects/Exceptions/Exceptions.php @@ -8,6 +8,7 @@ final class Exceptions { public const ERROR_ENCODING = 501; public const ERROR_DECODING = 502; + public const ERROR_PHP_VERSION = 503; /** * @param mixed $record @@ -41,4 +42,19 @@ public static function forDecode(string $binaryMessage, \Exception $previous = n return new AvroDecodingException($message, self::ERROR_DECODING, $previous); } + + public static function forPhpVersion(string $currentVersion, string $minimumVersion): UnsupportedPhpVersionException + { + $message = sprintf( + 'The current php version \'%s\' is not supported for this feature. ' . + 'Minimum supported version is \'%s\'', + $currentVersion, + $minimumVersion, + ); + + return new UnsupportedPhpVersionException( + $message, + self::ERROR_PHP_VERSION + ); + } } diff --git a/src/Objects/Exceptions/UnsupportedPhpVersionException.php b/src/Objects/Exceptions/UnsupportedPhpVersionException.php new file mode 100644 index 0000000..af319ba --- /dev/null +++ b/src/Objects/Exceptions/UnsupportedPhpVersionException.php @@ -0,0 +1,11 @@ +value) ? $this->value : [$this->value]; + + return array_map(function ($value) { + if ($value instanceof AvroType) { + return $value; + } + + return AvroType::create($value); + }, $value); + } + + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(...$this->value()); + } /** * {@inheritdoc} diff --git a/src/Objects/Schema/Generation/Annotations/AvroValues.php b/src/Objects/Schema/Generation/Annotations/AvroValues.php index 581d580..05dde2a 100644 --- a/src/Objects/Schema/Generation/Annotations/AvroValues.php +++ b/src/Objects/Schema/Generation/Annotations/AvroValues.php @@ -5,6 +5,7 @@ namespace FlixTech\AvroSerializer\Objects\Schema\Generation\Annotations; use FlixTech\AvroSerializer\Objects\Schema\AttributeName; +use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaAttributes; use FlixTech\AvroSerializer\Objects\Schema\Generation\TypeOnlyAttribute; /** @@ -12,7 +13,28 @@ */ final class AvroValues implements TypeOnlyAttribute { - use ContainsOnlyTypes; + /** + * @var mixed + */ + public $value; + + public function value(): array + { + $value = \is_array($this->value) ? $this->value : [$this->value]; + + return array_map(function ($value) { + if ($value instanceof AvroType) { + return $value; + } + + return AvroType::create($value); + }, $value); + } + + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(...$this->value()); + } /** * {@inheritdoc} diff --git a/src/Objects/Schema/Generation/Annotations/ContainsOnlyTypes.php b/src/Objects/Schema/Generation/Annotations/ContainsOnlyTypes.php deleted file mode 100644 index 8340848..0000000 --- a/src/Objects/Schema/Generation/Annotations/ContainsOnlyTypes.php +++ /dev/null @@ -1,50 +0,0 @@ - - */ - public $value; - - /** - * {@inheritdoc} - * - * @return array - */ - public function value(): array - { - if (!\is_array($this->value)) { - return [$this->valueToType($this->value)]; - } - - return \array_map([$this, 'valueToType'], $this->value); - } - - /** - * {@inheritdoc} - */ - public function attributes(): SchemaAttributes - { - return new SchemaAttributes(...$this->value()); - } - - /** - * @param string|AvroType $value - */ - private function valueToType($value): AvroType - { - if ($value instanceof AvroType) { - return $value; - } - - return AvroType::create($value); - } -} diff --git a/src/Objects/Schema/Generation/AttributeReader.php b/src/Objects/Schema/Generation/AttributeReader.php new file mode 100644 index 0000000..5c0e69b --- /dev/null +++ b/src/Objects/Schema/Generation/AttributeReader.php @@ -0,0 +1,44 @@ +getAttributes(); + return $this->getSchemaAttributes(...$attributes); + } + + public function readPropertyAttributes(ReflectionProperty $property): SchemaAttributes + { + $attributes = $property->getAttributes(); + return $this->getSchemaAttributes(...$attributes); + } + + private function getSchemaAttributes(ReflectionAttribute ...$attributes): SchemaAttributes + { + $attributes = array_map(fn($attr) => $attr->newInstance(), $attributes); + $attributes = array_filter($attributes, fn($attr) => $attr instanceof SchemaAttribute); + return new SchemaAttributes(...$attributes); + } +} diff --git a/src/Objects/Schema/Generation/Attributes/AvroAliases.php b/src/Objects/Schema/Generation/Attributes/AvroAliases.php new file mode 100644 index 0000000..77277a7 --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/AvroAliases.php @@ -0,0 +1,50 @@ + + */ + public array $aliases; + + public function __construct( + string ...$aliases, + ) { + $this->aliases = $aliases; + } + + /** + * {@inheritdoc} + */ + public function name(): string + { + return AttributeName::ALIASES; + } + + /** + * {@inheritdoc} + * + * @return array + */ + public function value(): array + { + return $this->aliases; + } + + /** + * {@inheritdoc} + */ + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(); + } +} diff --git a/src/Objects/Schema/Generation/Attributes/AvroDefault.php b/src/Objects/Schema/Generation/Attributes/AvroDefault.php new file mode 100644 index 0000000..ba5593c --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/AvroDefault.php @@ -0,0 +1,42 @@ +value; + } + + /** + * {@inheritdoc} + */ + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(); + } +} diff --git a/src/Objects/Schema/Generation/Attributes/AvroDoc.php b/src/Objects/Schema/Generation/Attributes/AvroDoc.php new file mode 100644 index 0000000..934e605 --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/AvroDoc.php @@ -0,0 +1,43 @@ +value; + } + + /** + * {@inheritdoc} + */ + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(); + } +} diff --git a/src/Objects/Schema/Generation/Attributes/AvroItems.php b/src/Objects/Schema/Generation/Attributes/AvroItems.php new file mode 100644 index 0000000..b3c38de --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/AvroItems.php @@ -0,0 +1,45 @@ +types = array_map(function ($type) { + if ($type instanceof AvroType) { + return $type; + } + + return new AvroType($type); + }, $types); + } + + public function value(): array + { + return $this->types; + } + + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(...$this->value()); + } + + /** + * {@inheritdoc} + */ + public function name(): string + { + return AttributeName::ITEMS; + } +} diff --git a/src/Objects/Schema/Generation/Attributes/AvroName.php b/src/Objects/Schema/Generation/Attributes/AvroName.php new file mode 100644 index 0000000..c9ccc94 --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/AvroName.php @@ -0,0 +1,33 @@ +value; + } + + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(); + } +} diff --git a/src/Objects/Schema/Generation/Attributes/AvroNamespace.php b/src/Objects/Schema/Generation/Attributes/AvroNamespace.php new file mode 100644 index 0000000..db72efa --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/AvroNamespace.php @@ -0,0 +1,34 @@ +value; + } + + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(); + } +} diff --git a/src/Objects/Schema/Generation/Attributes/AvroOrder.php b/src/Objects/Schema/Generation/Attributes/AvroOrder.php new file mode 100644 index 0000000..b9b7d85 --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/AvroOrder.php @@ -0,0 +1,42 @@ +order->value; + } + + /** + * {@inheritdoc} + */ + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(); + } +} diff --git a/src/Objects/Schema/Generation/Attributes/AvroSize.php b/src/Objects/Schema/Generation/Attributes/AvroSize.php new file mode 100644 index 0000000..abadebe --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/AvroSize.php @@ -0,0 +1,42 @@ +size; + } + + /** + * {@inheritdoc} + */ + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(); + } +} diff --git a/src/Objects/Schema/Generation/Attributes/AvroSymbols.php b/src/Objects/Schema/Generation/Attributes/AvroSymbols.php new file mode 100644 index 0000000..f11a4fb --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/AvroSymbols.php @@ -0,0 +1,50 @@ + + */ + private array $symbols; + + public function __construct( + string ...$symbols, + ) { + $this->symbols = $symbols; + } + + /** + * {@inheritdoc} + */ + public function name(): string + { + return AttributeName::SYMBOLS; + } + + /** + * {@inheritdoc} + * + * @return array + */ + public function value(): array + { + return $this->symbols; + } + + /** + * {@inheritdoc} + */ + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(); + } +} diff --git a/src/Objects/Schema/Generation/Attributes/AvroTargetClass.php b/src/Objects/Schema/Generation/Attributes/AvroTargetClass.php new file mode 100644 index 0000000..b5d9c1f --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/AvroTargetClass.php @@ -0,0 +1,33 @@ +value; + } + + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(); + } +} diff --git a/src/Objects/Schema/Generation/Attributes/AvroType.php b/src/Objects/Schema/Generation/Attributes/AvroType.php new file mode 100644 index 0000000..f109ae5 --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/AvroType.php @@ -0,0 +1,58 @@ + + */ + public $attributes = []; + + public string $value; + + public function __construct( + Type|string $value, + SchemaAttribute ...$attributes + ) { + if (is_string($value)) { + $this->value = $value; + } else { + $this->value = $value->value; + } + + $this->attributes = $attributes; + } + + /** + * {@inheritdoc} + */ + public function name(): string + { + return AttributeName::TYPE; + } + + /** + * {@inheritdoc} + */ + public function value(): string + { + return $this->value; + } + + /** + * {@inheritdoc} + */ + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(...$this->attributes); + } +} diff --git a/src/Objects/Schema/Generation/Attributes/AvroValues.php b/src/Objects/Schema/Generation/Attributes/AvroValues.php new file mode 100644 index 0000000..af2cecd --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/AvroValues.php @@ -0,0 +1,45 @@ +types = array_map(function ($type) { + if ($type instanceof AvroType) { + return $type; + } + + return new AvroType($type); + }, $types); + } + + public function value(): array + { + return $this->types; + } + + public function attributes(): SchemaAttributes + { + return new SchemaAttributes(...$this->value()); + } + + /** + * {@inheritdoc} + */ + public function name(): string + { + return AttributeName::VALUES; + } +} diff --git a/src/Objects/Schema/Generation/Attributes/Order.php b/src/Objects/Schema/Generation/Attributes/Order.php new file mode 100644 index 0000000..32ad437 --- /dev/null +++ b/src/Objects/Schema/Generation/Attributes/Order.php @@ -0,0 +1,12 @@ + + */ + public function value(): array; } diff --git a/test/Objects/Schema/Generation/AnnotationSchemaGeneratorTest.php b/test/Objects/Schema/Generation/AnnotationSchemaGeneratorTest.php new file mode 100644 index 0000000..86dc6bd --- /dev/null +++ b/test/Objects/Schema/Generation/AnnotationSchemaGeneratorTest.php @@ -0,0 +1,58 @@ +expectException(UnsupportedPhpVersionException::class); + + new AttributeReader(); + } +} diff --git a/test/Objects/Schema/Generation/AttributeSchemaGeneratorTest.php b/test/Objects/Schema/Generation/AttributeSchemaGeneratorTest.php new file mode 100644 index 0000000..f865e61 --- /dev/null +++ b/test/Objects/Schema/Generation/AttributeSchemaGeneratorTest.php @@ -0,0 +1,55 @@ += 8.1 + */ +class AttributeSchemaGeneratorTest extends SchemaGeneratorTest +{ + protected function makeSchemaAttributeReader(): SchemaAttributeReader + { + return new AttributeReader(); + } + + protected function getEmptyRecordClass(): string + { + return EmptyRecord::class; + } + + protected function getPrimitiveTypesClass(): string + { + return PrimitiveTypes::class; + } + + protected function getRecordWithComplexTypesClass(): string + { + return RecordWithComplexTypes::class; + } + + protected function getRecordWithRecordTypeClass(): string + { + return RecordWithRecordType::class; + } + + protected function getArraysWithComplexTypeClass(): string + { + return ArraysWithComplexType::class; + } + + protected function getMapsWithComplexTypeClass(): string + { + return MapsWithComplexType::class; + } +} diff --git a/test/Objects/Schema/Generation/Fixture/ArraysWithComplexType.php b/test/Objects/Schema/Generation/Fixture/Annotations/ArraysWithComplexType.php similarity index 97% rename from test/Objects/Schema/Generation/Fixture/ArraysWithComplexType.php rename to test/Objects/Schema/Generation/Fixture/Annotations/ArraysWithComplexType.php index ff552e3..40d20a3 100644 --- a/test/Objects/Schema/Generation/Fixture/ArraysWithComplexType.php +++ b/test/Objects/Schema/Generation/Fixture/Annotations/ArraysWithComplexType.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture; +namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\Annotations; use FlixTech\AvroSerializer\Objects\Schema\Generation\Annotations as SerDe; diff --git a/test/Objects/Schema/Generation/Fixture/EmptyRecord.php b/test/Objects/Schema/Generation/Fixture/Annotations/EmptyRecord.php similarity index 93% rename from test/Objects/Schema/Generation/Fixture/EmptyRecord.php rename to test/Objects/Schema/Generation/Fixture/Annotations/EmptyRecord.php index 0825882..7058f5d 100644 --- a/test/Objects/Schema/Generation/Fixture/EmptyRecord.php +++ b/test/Objects/Schema/Generation/Fixture/Annotations/EmptyRecord.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture; +namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\Annotations; use FlixTech\AvroSerializer\Objects\Schema\Generation\Annotations as SerDe; diff --git a/test/Objects/Schema/Generation/Fixture/MapsWithComplexType.php b/test/Objects/Schema/Generation/Fixture/Annotations/MapsWithComplexType.php similarity index 97% rename from test/Objects/Schema/Generation/Fixture/MapsWithComplexType.php rename to test/Objects/Schema/Generation/Fixture/Annotations/MapsWithComplexType.php index cc178a7..ca7be79 100644 --- a/test/Objects/Schema/Generation/Fixture/MapsWithComplexType.php +++ b/test/Objects/Schema/Generation/Fixture/Annotations/MapsWithComplexType.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture; +namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\Annotations; use FlixTech\AvroSerializer\Objects\Schema\Generation\Annotations as SerDe; diff --git a/test/Objects/Schema/Generation/Fixture/PrimitiveTypes.php b/test/Objects/Schema/Generation/Fixture/Annotations/PrimitiveTypes.php similarity index 97% rename from test/Objects/Schema/Generation/Fixture/PrimitiveTypes.php rename to test/Objects/Schema/Generation/Fixture/Annotations/PrimitiveTypes.php index efadf45..a3350a3 100644 --- a/test/Objects/Schema/Generation/Fixture/PrimitiveTypes.php +++ b/test/Objects/Schema/Generation/Fixture/Annotations/PrimitiveTypes.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture; +namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\Annotations; use FlixTech\AvroSerializer\Objects\Schema\Generation\Annotations as SerDe; diff --git a/test/Objects/Schema/Generation/Fixture/RecordWithComplexTypes.php b/test/Objects/Schema/Generation/Fixture/Annotations/RecordWithComplexTypes.php similarity index 98% rename from test/Objects/Schema/Generation/Fixture/RecordWithComplexTypes.php rename to test/Objects/Schema/Generation/Fixture/Annotations/RecordWithComplexTypes.php index 59cd395..fe74b9c 100644 --- a/test/Objects/Schema/Generation/Fixture/RecordWithComplexTypes.php +++ b/test/Objects/Schema/Generation/Fixture/Annotations/RecordWithComplexTypes.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture; +namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\Annotations; use FlixTech\AvroSerializer\Objects\Schema\Generation\Annotations as SerDe; diff --git a/test/Objects/Schema/Generation/Fixture/RecordWithRecordType.php b/test/Objects/Schema/Generation/Fixture/Annotations/RecordWithRecordType.php similarity index 80% rename from test/Objects/Schema/Generation/Fixture/RecordWithRecordType.php rename to test/Objects/Schema/Generation/Fixture/Annotations/RecordWithRecordType.php index 4a9a08c..b9f35a3 100644 --- a/test/Objects/Schema/Generation/Fixture/RecordWithRecordType.php +++ b/test/Objects/Schema/Generation/Fixture/Annotations/RecordWithRecordType.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture; +namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\Annotations; use FlixTech\AvroSerializer\Objects\Schema\Generation\Annotations as SerDe; @@ -15,8 +15,8 @@ class RecordWithRecordType /** * @SerDe\AvroName("simpleField") * @SerDe\AvroType("record", attributes={ - * @SerDe\AvroTargetClass("\FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\SimpleRecord"), - * @SerDe\AvroDoc("This a simple record for testing purposes") + * @SerDe\AvroTargetClass("\FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\Annotations\SimpleRecord"), + * @SerDe\AvroDoc("This is a simple record for testing purposes") * }) */ private $simpleRecord; diff --git a/test/Objects/Schema/Generation/Fixture/SimpleRecord.php b/test/Objects/Schema/Generation/Fixture/Annotations/SimpleRecord.php similarity index 94% rename from test/Objects/Schema/Generation/Fixture/SimpleRecord.php rename to test/Objects/Schema/Generation/Fixture/Annotations/SimpleRecord.php index 16e4769..ce7f16c 100644 --- a/test/Objects/Schema/Generation/Fixture/SimpleRecord.php +++ b/test/Objects/Schema/Generation/Fixture/Annotations/SimpleRecord.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture; +namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\Annotations; use FlixTech\AvroSerializer\Objects\Schema\Generation\Annotations as SerDe; diff --git a/test/Objects/Schema/Generation/Fixture/Attributes/ArraysWithComplexType.php b/test/Objects/Schema/Generation/Fixture/Attributes/ArraysWithComplexType.php new file mode 100644 index 0000000..541e7be --- /dev/null +++ b/test/Objects/Schema/Generation/Fixture/Attributes/ArraysWithComplexType.php @@ -0,0 +1,43 @@ + 42, 'bar' => 42]), + )] + private $map; + + #[AvroOrder(Order::ASC)] + #[AvroType( + Type::ENUM, + new AvroName("Suit"), + new AvroSymbols("SPADES", "HEARTS", "DIAMONDS", "CLUBS"), + )] + private $enum; + + #[AvroType( + Type::FIXED, + new AvroName("md5"), + new AvroNamespace("org.acme"), + new AvroAliases("foo", "bar"), + new AvroSize(16) + )] + private $fixed; + + #[AvroType(Type::STRING)] + #[AvroType(Type::INT)] + #[AvroType( + Type::ARRAY, + new AvroItems(Type::STRING), + )] + private $union; +} diff --git a/test/Objects/Schema/Generation/Fixture/Attributes/RecordWithRecordType.php b/test/Objects/Schema/Generation/Fixture/Attributes/RecordWithRecordType.php new file mode 100644 index 0000000..9902fcc --- /dev/null +++ b/test/Objects/Schema/Generation/Fixture/Attributes/RecordWithRecordType.php @@ -0,0 +1,29 @@ +generator = new Schema\Generation\SchemaGenerator( - new Schema\Generation\AnnotationReader( - new AnnotationReader() - ) + $this->makeSchemaAttributeReader() ); } @@ -38,7 +27,7 @@ protected function setUp(): void */ public function it_should_generate_an_empty_record() { - $schema = $this->generator->generate(EmptyRecord::class); + $schema = $this->generator->generate($this->getEmptyRecordClass()); $expected = Schema::record() ->name('EmptyRecord') @@ -52,7 +41,7 @@ public function it_should_generate_an_empty_record() */ public function it_should_generate_a_record_schema_with_primitive_types() { - $schema = $this->generator->generate(PrimitiveTypes::class); + $schema = $this->generator->generate($this->getPrimitiveTypesClass()); $expected = Schema::record() ->name('PrimitiveTypes') @@ -102,7 +91,7 @@ public function it_should_generate_a_record_schema_with_primitive_types() */ public function it_should_generate_a_schema_record_with_complex_types() { - $schema = $this->generator->generate(RecordWithComplexTypes::class); + $schema = $this->generator->generate($this->getRecordWithComplexTypesClass()); $expected = Schema::record() ->name('RecordWithComplexTypes') @@ -146,7 +135,7 @@ public function it_should_generate_a_schema_record_with_complex_types() */ public function it_should_generate_records_containing_records() { - $schema = $this->generator->generate(RecordWithRecordType::class); + $schema = $this->generator->generate($this->getRecordWithRecordTypeClass()); $expected = Schema::record() ->name('RecordWithRecordType') @@ -155,7 +144,7 @@ public function it_should_generate_records_containing_records() Schema::record() ->name('SimpleRecord') ->namespace('org.acme') - ->doc('This a simple record for testing purposes') + ->doc('This is a simple record for testing purposes') ->field( 'intType', Schema::int(), @@ -178,7 +167,7 @@ public function it_should_generate_records_containing_records() */ public function it_should_generate_a_record_schema_with_arrays_containing_complex_types() { - $schema = $this->generator->generate(ArraysWithComplexType::class); + $schema = $this->generator->generate($this->getArraysWithComplexTypeClass()); $expected = Schema::record() ->name('ArraysWithComplexType') @@ -208,7 +197,7 @@ public function it_should_generate_a_record_schema_with_arrays_containing_comple */ public function it_should_generate_a_record_schema_with_maps_containing_complex_types() { - $schema = $this->generator->generate(MapsWithComplexType::class); + $schema = $this->generator->generate($this->getMapsWithComplexTypeClass()); $expected = Schema::record() ->name('MapsWithComplexType') @@ -232,4 +221,18 @@ public function it_should_generate_a_record_schema_with_maps_containing_complex_ $this->assertEquals($expected, $schema); } + + abstract protected function makeSchemaAttributeReader(): SchemaAttributeReader; + + abstract protected function getEmptyRecordClass(): string; + + abstract protected function getPrimitiveTypesClass(): string; + + abstract protected function getRecordWithComplexTypesClass(): string; + + abstract protected function getRecordWithRecordTypeClass(): string; + + abstract protected function getArraysWithComplexTypeClass(): string; + + abstract protected function getMapsWithComplexTypeClass(): string; }