From 2d0f12f54ade8c0368329e980dc89ed3597646f3 Mon Sep 17 00:00:00 2001 From: mattiabasone Date: Mon, 5 Aug 2024 09:48:24 +0200 Subject: [PATCH] bump phpunit add test for attributes --- composer.json | 9 +- phpunit.xml.dist | 14 +-- test/AbstractFunctionalTestCase.php | 22 +--- test/CommonTest.php | 9 +- .../Serializer/AvroNameConverterTest.php | 9 +- .../Serializer/AvroSerDeEncoderTest.php | 42 +++---- .../DefaultRecordSerializerFactoryTest.php | 5 +- .../RecordSerializerIntegrationTest.php | 25 +++-- test/Objects/RecordSerializerTest.php | 103 +++++++++++------- test/Objects/Schema/ArrayTypeTest.php | 9 +- test/Objects/Schema/EnumTypeTest.php | 9 +- test/Objects/Schema/FixedTypeTest.php | 9 +- .../Fixture/RecordWithRecordType.php | 18 ++- .../Generation/Fixture/SimpleRecord.php | 9 ++ .../Schema/Generation/SchemaGeneratorTest.php | 98 ++++++++++------- test/Objects/Schema/LogicalTypeTest.php | 24 ++-- test/Objects/Schema/MapTypeTest.php | 9 +- test/Objects/Schema/PrimitiveTypeTest.php | 23 ++-- test/Objects/Schema/RecordTypeTest.php | 9 +- .../SchemaResolvers/CallableResolverTest.php | 6 +- .../SchemaResolvers/ChainResolverTest.php | 21 ++-- .../DefinitionInterfaceResolverTest.php | 12 +- .../SchemaResolvers/FileResolverTest.php | 16 ++- test/ProtocolTest.php | 37 ++----- test/SerializeTest.php | 35 +++--- test/bootstrap.php | 3 +- 26 files changed, 290 insertions(+), 295 deletions(-) diff --git a/composer.json b/composer.json index c975fc7..00fc411 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,10 @@ { "name": "Thomas Ploch", "email": "thomas.ploch@flixbus.com" + }, + { + "name": "Mattia Basone", + "email": "mattia.basone@gmail.com" } ], "require": { @@ -32,11 +36,12 @@ }, "require-dev": { "roave/security-advisories": "dev-latest", - "phpunit/phpunit": "^9.4.2", + "phpunit/phpunit": "^10.5", "phpbench/phpbench": "1.0.0-alpha2", "vlucas/phpdotenv": "~2.4", "symfony/serializer": "^6.4|^7.0", - "doctrine/annotations": "^1.11" + "doctrine/annotations": "^1.11", + "rector/rector": "^1.2" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d6cf711..21c792d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,14 @@ - - - - src/ - integrations/ - - + test/ + + + src/ + integrations/ + + diff --git a/test/AbstractFunctionalTestCase.php b/test/AbstractFunctionalTestCase.php index 0acd00d..0073058 100644 --- a/test/AbstractFunctionalTestCase.php +++ b/test/AbstractFunctionalTestCase.php @@ -4,7 +4,6 @@ namespace FlixTech\AvroSerializer\Test; -use AvroSchema; use PHPUnit\Framework\TestCase; abstract class AbstractFunctionalTestCase extends TestCase @@ -53,28 +52,19 @@ abstract class AbstractFunctionalTestCase extends TestCase public const INVALID_AVRO_ENCODED_RECORD_HEX_BIN = '0c54615f6d608348'; public const INVALID_BIN_WRONG_VERSION = '44686f6d617348'; - /** - * @var AvroSchema - */ - protected $avroSchema; + protected ?\AvroSchema $avroSchema; - /** - * @var AvroSchema - */ - protected $readersSchema; + protected ?\AvroSchema $readersSchema; - /** - * @var AvroSchema - */ - protected $invalidSchema; + protected ?\AvroSchema $invalidSchema; /** * @throws \AvroSchemaParseException */ protected function setUp(): void { - $this->avroSchema = AvroSchema::parse(self::SCHEMA_JSON); - $this->readersSchema = AvroSchema::parse(self::READERS_SCHEMA_JSON); - $this->invalidSchema = AvroSchema::parse(self::INVALID_READERS_SCHEMA_JSON); + $this->avroSchema = \AvroSchema::parse(self::SCHEMA_JSON); + $this->readersSchema = \AvroSchema::parse(self::READERS_SCHEMA_JSON); + $this->invalidSchema = \AvroSchema::parse(self::INVALID_READERS_SCHEMA_JSON); } } diff --git a/test/CommonTest.php b/test/CommonTest.php index bf7884f..7890486 100644 --- a/test/CommonTest.php +++ b/test/CommonTest.php @@ -4,6 +4,7 @@ namespace FlixTech\AvroSerializer\Test; +use PHPUnit\Framework\Attributes\Test; use Widmogrod\Monad\Maybe\Just; use Widmogrod\Monad\Maybe\Nothing; @@ -18,9 +19,7 @@ class CommonTest extends AbstractFunctionalTestCase { - /** - * @test - */ + #[Test] public function get_should_return_Maybe_monad(): void { $array = [ @@ -36,9 +35,7 @@ public function get_should_return_Maybe_monad(): void $this->assertInstanceOf(Nothing::class, get('INVALID', $array)); } - /** - * @test - */ + #[Test] public function getter_returns_curried_get(): void { $this->assertEquals( diff --git a/test/Integrations/Symfony/Serializer/AvroNameConverterTest.php b/test/Integrations/Symfony/Serializer/AvroNameConverterTest.php index 9e8ca21..bf3f71f 100644 --- a/test/Integrations/Symfony/Serializer/AvroNameConverterTest.php +++ b/test/Integrations/Symfony/Serializer/AvroNameConverterTest.php @@ -4,6 +4,7 @@ namespace FlixTech\AvroSerializer\Test\Integrations\Symfony\Serializer; +use PHPUnit\Framework\Attributes\Test; use Doctrine\Common\Annotations\AnnotationReader as DoctrineAnnotationReader; use FlixTech\AvroSerializer\Integrations\Symfony\Serializer\AvroSerDeEncoder; use FlixTech\AvroSerializer\Integrations\Symfony\Serializer\NameConverter\AvroNameConverter; @@ -30,9 +31,7 @@ protected function setUp(): void ); } - /** - * @test - */ + #[Test] public function it_should_return_the_normalized_property_name(): void { $normalizedName = $this->nameConverter @@ -40,9 +39,7 @@ public function it_should_return_the_normalized_property_name(): void $this->assertEquals('Name', $normalizedName); } - /** - * @test - */ + #[Test] public function it_should_return_the_denormalized_property_name(): void { $normalizedName = $this->nameConverter diff --git a/test/Integrations/Symfony/Serializer/AvroSerDeEncoderTest.php b/test/Integrations/Symfony/Serializer/AvroSerDeEncoderTest.php index b59e114..b8d5653 100644 --- a/test/Integrations/Symfony/Serializer/AvroSerDeEncoderTest.php +++ b/test/Integrations/Symfony/Serializer/AvroSerDeEncoderTest.php @@ -4,6 +4,8 @@ namespace FlixTech\AvroSerializer\Test\Integrations\Symfony\Serializer; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\DataProvider; use FlixTech\AvroSerializer\Integrations\Symfony\Serializer\AvroSerDeEncoder; use FlixTech\AvroSerializer\Objects\RecordSerializer; use FlixTech\AvroSerializer\Test\AbstractFunctionalTestCase; @@ -33,27 +35,21 @@ protected function setUp(): void $this->avroSerDeEncoder = new AvroSerDeEncoder($this->recordSerializerMock); } - /** - * @test - */ + #[Test] public function it_should_only_support_encoding_Avro_format(): void { $this->assertTrue($this->avroSerDeEncoder->supportsEncoding(AvroSerDeEncoder::FORMAT_AVRO)); $this->assertFalse($this->avroSerDeEncoder->supportsEncoding('any')); } - /** - * @test - */ + #[Test] public function it_should_only_support_decoding_Avro_format(): void { $this->assertTrue($this->avroSerDeEncoder->supportsDecoding(AvroSerDeEncoder::FORMAT_AVRO)); $this->assertFalse($this->avroSerDeEncoder->supportsDecoding('any')); } - /** - * @test - */ + #[Test] public function it_should_encode_with_valid_encode_context(): void { $context = [ @@ -75,15 +71,21 @@ public function it_should_encode_with_valid_encode_context(): void $this->assertSame('success', $result); } - /** - * @test - */ + #[Test] public function it_should_decode_with_valid_decode_context(): void { - $this->recordSerializerMock->expects($this->exactly(2)) - ->method('decodeMessage') - ->withConsecutive([AbstractFunctionalTestCase::AVRO_ENCODED_RECORD_HEX_BIN, null], [AbstractFunctionalTestCase::AVRO_ENCODED_RECORD_HEX_BIN, $this->readersSchema]) - ->willReturnOnConsecutiveCalls('success-1', 'success-2'); + $matcher = $this->exactly(2); + $this->recordSerializerMock->expects($matcher) + ->method('decodeMessage')->willReturnCallback(function ($parameters) use ($matcher) { + match ($matcher->numberOfInvocations()) { + 1 => self::assertEquals([AbstractFunctionalTestCase::AVRO_ENCODED_RECORD_HEX_BIN, null], $parameters), + 2 => self::assertEquals([AbstractFunctionalTestCase::AVRO_ENCODED_RECORD_HEX_BIN, $this->readersSchema], $parameters), + }; + return match ($matcher->numberOfInvocations()) { + 1 => 'success-1', + 2 => 'success-2', + }; + }); $result = $this->avroSerDeEncoder->decode( AbstractFunctionalTestCase::AVRO_ENCODED_RECORD_HEX_BIN, @@ -103,10 +105,8 @@ public function it_should_decode_with_valid_decode_context(): void $this->assertSame('success-2', $result); } - /** - * @test - * @dataProvider encodeContextValidationDataProvider - */ + #[DataProvider('encodeContextValidationDataProvider')] + #[Test] public function it_should_validate_encode_context(array $context): void { $this->expectException(InvalidArgumentException::class); @@ -120,7 +120,7 @@ public function it_should_validate_encode_context(array $context): void ); } - public static function encodeContextValidationDataProvider(): ?\Generator + public static function encodeContextValidationDataProvider(): \Generator { yield 'Invalid writer\'s schema in encode context' => [ [ diff --git a/test/Objects/DefaultRecordSerializerFactoryTest.php b/test/Objects/DefaultRecordSerializerFactoryTest.php index c0d094c..6d3e6af 100644 --- a/test/Objects/DefaultRecordSerializerFactoryTest.php +++ b/test/Objects/DefaultRecordSerializerFactoryTest.php @@ -4,14 +4,13 @@ namespace FlixTech\AvroSerializer\Test\Objects; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\DefaultRecordSerializerFactory; use PHPUnit\Framework\TestCase; class DefaultRecordSerializerFactoryTest extends TestCase { - /** - * @test - */ + #[Test] public function it_should_produce_a_default_RecordSerializer(): void { $one = DefaultRecordSerializerFactory::get('http://localhost'); diff --git a/test/Objects/RecordSerializerIntegrationTest.php b/test/Objects/RecordSerializerIntegrationTest.php index a7a4e3c..8f16970 100644 --- a/test/Objects/RecordSerializerIntegrationTest.php +++ b/test/Objects/RecordSerializerIntegrationTest.php @@ -4,21 +4,22 @@ namespace FlixTech\AvroSerializer\Test\Objects; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\Depends; +use FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException; use FlixTech\AvroSerializer\Objects\DefaultRecordSerializerFactory; use FlixTech\AvroSerializer\Objects\RecordSerializer; use FlixTech\AvroSerializer\Test\AbstractFunctionalTestCase; use FlixTech\SchemaRegistryApi\Exception\IncompatibleAvroSchemaException; -/** - * @group integration - */ +#[Group('integration')] class RecordSerializerIntegrationTest extends AbstractFunctionalTestCase { /** - * @test - * - * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException + * @throws SchemaRegistryException */ + #[Test] public function it_encodes_valid_records(): RecordSerializer { $serializer = DefaultRecordSerializerFactory::get(\getenv('SCHEMA_REGISTRY_HOST')); @@ -31,12 +32,12 @@ public function it_encodes_valid_records(): RecordSerializer } /** - * @test * - * @depends it_encodes_valid_records * - * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException + * @throws SchemaRegistryException */ + #[Depends('it_encodes_valid_records')] + #[Test] public function it_cannot_evolve_incompatible_schema(RecordSerializer $serializer): void { $this->expectException(IncompatibleAvroSchemaException::class); @@ -44,12 +45,12 @@ public function it_cannot_evolve_incompatible_schema(RecordSerializer $serialize } /** - * @test * - * @depends it_encodes_valid_records * - * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException + * @throws SchemaRegistryException */ + #[Depends('it_encodes_valid_records')] + #[Test] public function it_decodes_with_readers_schema(RecordSerializer $serializer): RecordSerializer { $encoded = $serializer->encodeRecord('test-value', $this->avroSchema, self::TEST_RECORD); diff --git a/test/Objects/RecordSerializerTest.php b/test/Objects/RecordSerializerTest.php index e1c0371..9617eb8 100644 --- a/test/Objects/RecordSerializerTest.php +++ b/test/Objects/RecordSerializerTest.php @@ -4,6 +4,7 @@ namespace FlixTech\AvroSerializer\Test\Objects; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\Exceptions\AvroEncodingException; use FlixTech\AvroSerializer\Objects\RecordSerializer; use FlixTech\AvroSerializer\Test\AbstractFunctionalTestCase; @@ -12,7 +13,6 @@ use FlixTech\SchemaRegistryApi\Exception\SubjectNotFoundException; use FlixTech\SchemaRegistryApi\Registry; use GuzzleHttp\Promise\FulfilledPromise; -use LogicException; use PHPUnit\Framework\MockObject\MockObject; use function FlixTech\AvroSerializer\Common\memoize; @@ -48,17 +48,24 @@ protected function tearDown(): void } /** - * @test - * * @throws SchemaRegistryException */ + #[Test] public function it_should_encode_a_record_with_schema_and_subject(): void { + $matcher = $this->exactly(2); $this->registryMock - ->expects($this->exactly(2)) - ->method('schemaId') - ->withConsecutive(['test', $this->avroSchema], ['test', $this->avroSchema]) - ->willReturnOnConsecutiveCalls(self::SCHEMA_ID, new FulfilledPromise(self::SCHEMA_ID)); + ->expects($matcher) + ->method('schemaId')->willReturnCallback(function ($parameters) use ($matcher) { + match ($matcher->numberOfInvocations()) { + 1 => self::assertEquals(['test', $this->avroSchema], $parameters), + 2 => self::assertEquals(['test', $this->avroSchema], $parameters), + }; + return match ($matcher->numberOfInvocations()) { + 1 => self::SCHEMA_ID, + 2 => new FulfilledPromise(self::SCHEMA_ID), + }; + }); $this->assertSame( self::HEX_BIN, @@ -73,10 +80,9 @@ public function it_should_encode_a_record_with_schema_and_subject(): void } /** - * @test - * * @throws SchemaRegistryException */ + #[Test] public function it_should_throw_encoding_exception_on_invalid_schema(): void { $this->expectException(AvroEncodingException::class); @@ -91,10 +97,9 @@ public function it_should_throw_encoding_exception_on_invalid_schema(): void } /** - * @test - * * @throws SchemaRegistryException */ + #[Test] public function it_should_not_register_new_schemas_by_default(): void { $this->expectException(SchemaNotFoundException::class); @@ -112,10 +117,9 @@ public function it_should_not_register_new_schemas_by_default(): void } /** - * @test - * * @throws SchemaRegistryException */ + #[Test] public function it_should_register_new_schemas_when_configured(): void { $recordSerializer = new RecordSerializer($this->registryMock, ['register_missing_schemas' => true]); @@ -145,10 +149,9 @@ public function it_should_register_new_schemas_when_configured(): void } /** - * @test - * * @throws SchemaRegistryException */ + #[Test] public function it_should_fail_when_the_subject_is_not_found(): void { $this->expectException(SubjectNotFoundException::class); @@ -166,10 +169,9 @@ public function it_should_fail_when_the_subject_is_not_found(): void } /** - * @test - * * @throws SchemaRegistryException */ + #[Test] public function it_should_register_new_subject_when_configured(): void { $recordSerializer = new RecordSerializer($this->registryMock, ['register_missing_subjects' => true]); @@ -179,12 +181,20 @@ public function it_should_register_new_subject_when_configured(): void ->method('schemaId') ->with('test', $this->avroSchema) ->willThrowException(new SubjectNotFoundException()); + $matcher = $this->exactly(2); $this->registryMock - ->expects($this->exactly(2)) - ->method('register') - ->withConsecutive(['test', $this->avroSchema], ['test', $this->avroSchema]) - ->willReturnOnConsecutiveCalls(self::SCHEMA_ID, new FulfilledPromise(self::SCHEMA_ID)); + ->expects($matcher) + ->method('register')->willReturnCallback(function ($parameters) use ($matcher) { + match ($matcher->numberOfInvocations()) { + 1 => self::assertEquals(['test', $this->avroSchema], $parameters), + 2 => self::assertEquals(['test', $this->avroSchema], $parameters), + }; + return match ($matcher->numberOfInvocations()) { + 1 => self::SCHEMA_ID, + 2 => new FulfilledPromise(self::SCHEMA_ID), + }; + }); $this->assertSame( self::HEX_BIN, @@ -199,10 +209,9 @@ public function it_should_register_new_subject_when_configured(): void } /** - * @test - * * @throws SchemaRegistryException */ + #[Test] public function it_should_fail_when_the_subject_is_not_found_via_promise(): void { $this->expectException(SubjectNotFoundException::class); @@ -219,19 +228,15 @@ public function it_should_fail_when_the_subject_is_not_found_via_promise(): void $this->recordSerializer->encodeRecord('test', $this->avroSchema, self::TEST_RECORD); } - /** - * @test - * -s * @throws SchemaRegistryException - */ + #[Test] public function it_should_fail_when_an_unexpected_exception_is_wrapped_in_a_promise(): void { - $this->expectException(LogicException::class); + $this->expectException(\LogicException::class); $this->registryMock ->expects($this->once()) ->method('schemaId') ->with('test', $this->avroSchema) - ->willThrowException(new LogicException()); + ->willThrowException(new \LogicException()); $this->registryMock ->expects($this->never()) @@ -241,17 +246,24 @@ public function it_should_fail_when_an_unexpected_exception_is_wrapped_in_a_prom } /** - * @test - * * @throws SchemaRegistryException */ + #[Test] public function it_should_decode_wire_protocol_messages_correctly(): void { + $matcher = $this->exactly(2); $this->registryMock - ->expects($this->exactly(2)) - ->method('schemaForId') - ->withConsecutive([self::SCHEMA_ID], [self::SCHEMA_ID]) - ->willReturnOnConsecutiveCalls($this->avroSchema, new FulfilledPromise($this->avroSchema)); + ->expects($matcher) + ->method('schemaForId')->willReturnCallback(function ($parameters) use ($matcher) { + match ($matcher->numberOfInvocations()) { + 1 => self::assertEquals([self::SCHEMA_ID], $parameters), + 2 => self::assertEquals([self::SCHEMA_ID], $parameters), + }; + return match ($matcher->numberOfInvocations()) { + 1 => $this->avroSchema, + 2 => new FulfilledPromise($this->avroSchema), + }; + }); $this->assertSame( self::TEST_RECORD, @@ -266,17 +278,24 @@ public function it_should_decode_wire_protocol_messages_correctly(): void } /** - * @test - * * @throws SchemaRegistryException */ + #[Test] public function it_should_decode_with_readers_schema(): void { + $matcher = $this->exactly(2); $this->registryMock - ->expects($this->exactly(2)) - ->method('schemaForId') - ->withConsecutive([self::SCHEMA_ID], [self::SCHEMA_ID]) - ->willReturnOnConsecutiveCalls($this->avroSchema, new FulfilledPromise($this->avroSchema)); + ->expects($matcher) + ->method('schemaForId')->willReturnCallback(function ($parameters) use ($matcher) { + match ($matcher->numberOfInvocations()) { + 1 => self::assertEquals([self::SCHEMA_ID], $parameters), + 2 => self::assertEquals([self::SCHEMA_ID], $parameters), + }; + return match ($matcher->numberOfInvocations()) { + 1 => $this->avroSchema, + 2 => new FulfilledPromise($this->avroSchema), + }; + }); $this->assertSame( self::READERS_TEST_RECORD, diff --git a/test/Objects/Schema/ArrayTypeTest.php b/test/Objects/Schema/ArrayTypeTest.php index 2aa9949..2182cfb 100644 --- a/test/Objects/Schema/ArrayTypeTest.php +++ b/test/Objects/Schema/ArrayTypeTest.php @@ -4,14 +4,13 @@ namespace FlixTech\AvroSerializer\Test\Objects\Schema; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\Schema; use PHPUnit\Framework\TestCase; class ArrayTypeTest extends TestCase { - /** - * @test - */ + #[Test] public function it_should_serialize_array_types(): void { $serializedArray = Schema::array() @@ -28,9 +27,7 @@ public function it_should_serialize_array_types(): void $this->assertEquals($expectedArray, $serializedArray); } - /** - * @test - */ + #[Test] public function it_should_parse_array_types(): void { $parsedSchema = Schema::array() diff --git a/test/Objects/Schema/EnumTypeTest.php b/test/Objects/Schema/EnumTypeTest.php index f2e49f4..db776b5 100644 --- a/test/Objects/Schema/EnumTypeTest.php +++ b/test/Objects/Schema/EnumTypeTest.php @@ -4,14 +4,13 @@ namespace FlixTech\AvroSerializer\Test\Objects\Schema; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\Schema; use PHPUnit\Framework\TestCase; class EnumTypeTest extends TestCase { - /** - * @test - */ + #[Test] public function it_should_serialize_enum_types(): void { $serializedEnum = Schema::enum() @@ -36,9 +35,7 @@ public function it_should_serialize_enum_types(): void $this->assertEquals($expectedEnum, $serializedEnum); } - /** - * @test - */ + #[Test] public function it_should_parse_enum_types(): void { $parsedSchema = Schema::enum() diff --git a/test/Objects/Schema/FixedTypeTest.php b/test/Objects/Schema/FixedTypeTest.php index 3b7757b..01b08e1 100644 --- a/test/Objects/Schema/FixedTypeTest.php +++ b/test/Objects/Schema/FixedTypeTest.php @@ -4,14 +4,13 @@ namespace FlixTech\AvroSerializer\Test\Objects\Schema; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\Schema; use PHPUnit\Framework\TestCase; class FixedTypeTest extends TestCase { - /** - * @test - */ + #[Test] public function it_should_serialize_fixed_types(): void { $serializedFixedType = Schema::fixed() @@ -32,9 +31,7 @@ public function it_should_serialize_fixed_types(): void $this->assertEquals($expectedFixedType, $serializedFixedType); } - /** - * @test - */ + #[Test] public function it_should_parse_fixed_types(): void { $parsedSchema = Schema::fixed() diff --git a/test/Objects/Schema/Generation/Fixture/RecordWithRecordType.php b/test/Objects/Schema/Generation/Fixture/RecordWithRecordType.php index 4a9a08c..0197ce1 100644 --- a/test/Objects/Schema/Generation/Fixture/RecordWithRecordType.php +++ b/test/Objects/Schema/Generation/Fixture/RecordWithRecordType.php @@ -5,11 +5,17 @@ namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture; use FlixTech\AvroSerializer\Objects\Schema\Generation\Annotations as SerDe; +use FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes\AvroDoc; +use FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes\AvroName; +use FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes\AvroTargetClass; +use FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes\AvroType; /** * @SerDe\AvroType("record") * @SerDe\AvroName("RecordWithRecordType") */ +#[AvroType("record")] +#[AvroName("RecordWithRecordType")] class RecordWithRecordType { /** @@ -19,12 +25,20 @@ class RecordWithRecordType * @SerDe\AvroDoc("This a simple record for testing purposes") * }) */ - private $simpleRecord; + #[AvroName("simpleField")] + #[AvroType("record", + new AvroTargetClass(SimpleRecord::class), + new AvroDoc("This a simple record for testing purposes") + )] + private SimpleRecord $simpleRecord; /** * @SerDe\AvroName("unionField") * @SerDe\AvroType("null") * @SerDe\AvroType("org.acme.SimpleRecord") */ - private $unionRecord; + #[AvroName("unionField")] + #[AvroType("null")] + #[AvroType("org.acme.SimpleRecord")] + private ?SimpleRecord $unionRecord; } diff --git a/test/Objects/Schema/Generation/Fixture/SimpleRecord.php b/test/Objects/Schema/Generation/Fixture/SimpleRecord.php index 16e4769..517984b 100644 --- a/test/Objects/Schema/Generation/Fixture/SimpleRecord.php +++ b/test/Objects/Schema/Generation/Fixture/SimpleRecord.php @@ -5,17 +5,26 @@ namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture; use FlixTech\AvroSerializer\Objects\Schema\Generation\Annotations as SerDe; +use FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes\AvroDefault; +use FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes\AvroName; +use FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes\AvroNamespace; +use FlixTech\AvroSerializer\Objects\Schema\Generation\Attributes\AvroType; /** * @SerDe\AvroName("SimpleRecord") * @SerDe\AvroNamespace("org.acme") * @SerDe\AvroType("record") */ +#[AvroName("SimpleRecord")] +#[AvroNamespace("org.acme")] +#[AvroType("record")] class SimpleRecord { /** * @SerDe\AvroType("int") * @SerDe\AvroDefault(42) */ + #[AvroType("int")] + #[AvroDefault(42)] private $intType; } diff --git a/test/Objects/Schema/Generation/SchemaGeneratorTest.php b/test/Objects/Schema/Generation/SchemaGeneratorTest.php index 05fc440..a1a08a7 100644 --- a/test/Objects/Schema/Generation/SchemaGeneratorTest.php +++ b/test/Objects/Schema/Generation/SchemaGeneratorTest.php @@ -4,8 +4,12 @@ namespace FlixTech\AvroSerializer\Test\Objects\Schema\Generation; +use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaGenerator; +use FlixTech\AvroSerializer\Objects\Schema\Generation\AttributeReader; +use PHPUnit\Framework\Attributes\Test; +use FlixTech\AvroSerializer\Objects\Schema\Record\FieldOption; +use FlixTech\AvroSerializer\Objects\Schema\Record\FieldOrder; use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\Annotations\AnnotationRegistry; use FlixTech\AvroSerializer\Objects\Schema; use FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\ArraysWithComplexType; use FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\EmptyRecord; @@ -17,28 +21,27 @@ class SchemaGeneratorTest extends TestCase { - /** - * @var Schema\Generation\SchemaGenerator - */ - private $generator; + private ?SchemaGenerator $generatorDoctrineAnnotations; + + private ?SchemaGenerator $generatorAttributes; protected function setUp(): void { - AnnotationRegistry::registerLoader('class_exists'); - - $this->generator = new Schema\Generation\SchemaGenerator( + $this->generatorDoctrineAnnotations = new SchemaGenerator( new Schema\Generation\AnnotationReader( new AnnotationReader() ) ); + + $this->generatorAttributes = new SchemaGenerator( + new AttributeReader() + ); } - /** - * @test - */ + #[Test] public function it_should_generate_an_empty_record() { - $schema = $this->generator->generate(EmptyRecord::class); + $schema = $this->generatorDoctrineAnnotations->generate(EmptyRecord::class); $expected = Schema::record() ->name('EmptyRecord') @@ -47,12 +50,10 @@ public function it_should_generate_an_empty_record() $this->assertEquals($expected, $schema); } - /** - * @test - */ + #[Test] public function it_should_generate_a_record_schema_with_primitive_types() { - $schema = $this->generator->generate(PrimitiveTypes::class); + $schema = $this->generatorDoctrineAnnotations->generate(PrimitiveTypes::class); $expected = Schema::record() ->name('PrimitiveTypes') @@ -60,12 +61,12 @@ public function it_should_generate_a_record_schema_with_primitive_types() ->field( 'nullType', Schema::null(), - Schema\Record\FieldOption::doc('null type') + FieldOption::doc('null type') ) ->field( 'isItTrue', Schema::boolean(), - Schema\Record\FieldOption::default(false) + FieldOption::default(false) ) ->field( 'intType', @@ -74,12 +75,12 @@ public function it_should_generate_a_record_schema_with_primitive_types() ->field( 'longType', Schema::long(), - Schema\Record\FieldOption::orderAsc() + FieldOption::orderAsc() ) ->field( 'floatType', Schema::float(), - Schema\Record\FieldOption::aliases('foo', 'bar') + FieldOption::aliases('foo', 'bar') ) ->field( 'doubleType', @@ -97,12 +98,10 @@ public function it_should_generate_a_record_schema_with_primitive_types() $this->assertEquals($expected, $schema); } - /** - * @test - */ + #[Test] public function it_should_generate_a_schema_record_with_complex_types() { - $schema = $this->generator->generate(RecordWithComplexTypes::class); + $schema = $this->generatorDoctrineAnnotations->generate(RecordWithComplexTypes::class); $expected = Schema::record() ->name('RecordWithComplexTypes') @@ -123,7 +122,7 @@ public function it_should_generate_a_schema_record_with_complex_types() Schema::enum() ->name('Suit') ->symbols('SPADES', 'HEARTS', 'DIAMONDS', 'CLUBS'), - Schema\Record\FieldOrder::asc() + FieldOrder::asc() ) ->field( 'fixed', @@ -141,12 +140,39 @@ public function it_should_generate_a_schema_record_with_complex_types() $this->assertEquals($expected, $schema); } - /** - * @test - */ + #[Test] public function it_should_generate_records_containing_records() { - $schema = $this->generator->generate(RecordWithRecordType::class); + $schema = $this->generatorDoctrineAnnotations->generate(RecordWithRecordType::class); + + $expected = Schema::record() + ->name('RecordWithRecordType') + ->field( + 'simpleField', + Schema::record() + ->name('SimpleRecord') + ->namespace('org.acme') + ->doc('This a simple record for testing purposes') + ->field( + 'intType', + Schema::int(), + FieldOption::default(42) + ), + ) + ->field( + 'unionField', + Schema::union( + Schema::null(), + Schema::named('org.acme.SimpleRecord') + ) + ); + + $this->assertEquals($expected, $schema); + } + + public function test_it_should_generate_records_containing_records_using_attributes(): void + { + $schema = $this->generatorAttributes->generate(RecordWithRecordType::class); $expected = Schema::record() ->name('RecordWithRecordType') @@ -159,7 +185,7 @@ public function it_should_generate_records_containing_records() ->field( 'intType', Schema::int(), - Schema\Record\FieldOption::default(42) + FieldOption::default(42) ), ) ->field( @@ -173,12 +199,10 @@ public function it_should_generate_records_containing_records() $this->assertEquals($expected, $schema); } - /** - * @test - */ + #[Test] public function it_should_generate_a_record_schema_with_arrays_containing_complex_types() { - $schema = $this->generator->generate(ArraysWithComplexType::class); + $schema = $this->generatorDoctrineAnnotations->generate(ArraysWithComplexType::class); $expected = Schema::record() ->name('ArraysWithComplexType') @@ -203,12 +227,10 @@ public function it_should_generate_a_record_schema_with_arrays_containing_comple $this->assertEquals($expected, $schema); } - /** - * @test - */ + #[Test] public function it_should_generate_a_record_schema_with_maps_containing_complex_types() { - $schema = $this->generator->generate(MapsWithComplexType::class); + $schema = $this->generatorDoctrineAnnotations->generate(MapsWithComplexType::class); $expected = Schema::record() ->name('MapsWithComplexType') diff --git a/test/Objects/Schema/LogicalTypeTest.php b/test/Objects/Schema/LogicalTypeTest.php index f1fa67c..bc93c95 100644 --- a/test/Objects/Schema/LogicalTypeTest.php +++ b/test/Objects/Schema/LogicalTypeTest.php @@ -4,15 +4,15 @@ namespace FlixTech\AvroSerializer\Test\Objects\Schema; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\Schema; use PHPUnit\Framework\TestCase; class LogicalTypeTest extends TestCase { - /** - * @test - * @dataProvider provideLogicalTypes() - */ + #[DataProvider('provideLogicalTypes')] + #[Test] public function it_should_serialize_simple_logical_types(Schema $type, string $expectedAnnotatedType, string $expectedLogicalType) { $expectedSchema = [ @@ -23,10 +23,8 @@ public function it_should_serialize_simple_logical_types(Schema $type, string $e $this->assertEquals($expectedSchema, $type->serialize()); } - /** - * @test - * @dataProvider provideLogicalTypes() - */ + #[DataProvider('provideLogicalTypes')] + #[Test] public function it_should_parse_simple_logical_types(Schema $type, string $expectedType, string $expectedLogicalType) { $parsedSchema = $type->parse(); @@ -34,9 +32,7 @@ public function it_should_parse_simple_logical_types(Schema $type, string $expec $this->assertEquals($expectedLogicalType, $parsedSchema->logical_type()); } - /** - * @test - */ + #[Test] public function it_should_serialize_duration_types() { $schema = Schema::duration() @@ -57,9 +53,7 @@ public function it_should_serialize_duration_types() $this->assertEquals($expected, $schema); } - /** - * @test - */ + #[Test] public function it_should_parse_duration_types() { $parsedSchema = Schema::duration() @@ -72,7 +66,7 @@ public function it_should_parse_duration_types() $this->assertEquals('duration', $parsedSchema->logical_type()); } - public function provideLogicalTypes(): array + public static function provideLogicalTypes(): array { return [ 'uuid' => [Schema::uuid(), 'string', 'uuid'], diff --git a/test/Objects/Schema/MapTypeTest.php b/test/Objects/Schema/MapTypeTest.php index 4f30ea8..0ba9669 100644 --- a/test/Objects/Schema/MapTypeTest.php +++ b/test/Objects/Schema/MapTypeTest.php @@ -4,14 +4,13 @@ namespace FlixTech\AvroSerializer\Test\Objects\Schema; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\Schema; use PHPUnit\Framework\TestCase; class MapTypeTest extends TestCase { - /** - * @test - */ + #[Test] public function it_should_serialize_map_types(): void { $serializedMap = Schema::map() @@ -30,9 +29,7 @@ public function it_should_serialize_map_types(): void $this->assertEquals($expectedMap, $serializedMap); } - /** - * @test - */ + #[Test] public function it_should_parse_map_types(): void { $parsedSchema = Schema::map() diff --git a/test/Objects/Schema/PrimitiveTypeTest.php b/test/Objects/Schema/PrimitiveTypeTest.php index 5dac4f9..2b2878d 100644 --- a/test/Objects/Schema/PrimitiveTypeTest.php +++ b/test/Objects/Schema/PrimitiveTypeTest.php @@ -4,32 +4,33 @@ namespace FlixTech\AvroSerializer\Test\Objects\Schema; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\Schema; use PHPUnit\Framework\TestCase; class PrimitiveTypeTest extends TestCase { - /** - * @dataProvider providePrimitiveTypes() - * @test - */ - public function it_should_serialize_primitive_types(Schema $type, string $expectedName) + #[DataProvider('providePrimitiveTypes')] + #[Test] + public function it_should_serialize_primitive_types(Schema $type, string $expectedName): void { $this->assertEquals($expectedName, $type->serialize()); } - /** - * @dataProvider providePrimitiveTypes() - * @test - */ - public function it_should_parse_primitive_types(Schema $type, string $expectedName) + #[DataProvider('providePrimitiveTypes')] + #[Test] + public function it_should_parse_primitive_types(Schema $type, string $expectedName): void { $parsedSchema = $type->parse(); $this->assertInstanceOf(\AvroSchema::class, $parsedSchema); $this->assertEquals($expectedName, $parsedSchema->type()); } - public function providePrimitiveTypes(): array + /** + * @return array + */ + public static function providePrimitiveTypes(): array { return [ 'null' => [Schema::null(), 'null'], diff --git a/test/Objects/Schema/RecordTypeTest.php b/test/Objects/Schema/RecordTypeTest.php index eb8cd91..3d4e146 100644 --- a/test/Objects/Schema/RecordTypeTest.php +++ b/test/Objects/Schema/RecordTypeTest.php @@ -2,15 +2,14 @@ namespace FlixTech\AvroSerializer\Test\Objects\Schema; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\Schema; use FlixTech\AvroSerializer\Objects\Schema\Record\FieldOption; use PHPUnit\Framework\TestCase; class RecordTypeTest extends TestCase { - /** - * @test - */ + #[Test] public function it_should_serialize_record_types(): void { $serializedRecord = Schema::record() @@ -54,9 +53,7 @@ public function it_should_serialize_record_types(): void $this->assertEquals($expectedRecord, $serializedRecord); } - /** - * @test - */ + #[Test] public function it_should_parse_record_types(): void { $parsedSchema = Schema::record() diff --git a/test/Objects/SchemaResolvers/CallableResolverTest.php b/test/Objects/SchemaResolvers/CallableResolverTest.php index 8c7defd..beade06 100644 --- a/test/Objects/SchemaResolvers/CallableResolverTest.php +++ b/test/Objects/SchemaResolvers/CallableResolverTest.php @@ -4,6 +4,7 @@ namespace FlixTech\AvroSerializer\Test\Objects\SchemaResolvers; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\SchemaResolvers\CallableResolver; use FlixTech\AvroSerializer\Test\AbstractFunctionalTestCase; @@ -12,11 +13,11 @@ class CallableResolverTest extends AbstractFunctionalTestCase { /** - * @test * * @throws \AvroSchemaParseException * @throws \AvroSchemaParseException */ + #[Test] public function it_should_use_callable_for_resolving_value_schemas(): void { $resolver = new CallableResolver(constt($this->avroSchema)); @@ -26,10 +27,9 @@ public function it_should_use_callable_for_resolving_value_schemas(): void } /** - * @test - * * @throws \AvroSchemaParseException */ + #[Test] public function it_should_use_callable_for_resolving_key_schemas(): void { $resolver = new CallableResolver(constt($this->avroSchema), constt($this->readersSchema)); diff --git a/test/Objects/SchemaResolvers/ChainResolverTest.php b/test/Objects/SchemaResolvers/ChainResolverTest.php index 629b409..f344713 100644 --- a/test/Objects/SchemaResolvers/ChainResolverTest.php +++ b/test/Objects/SchemaResolvers/ChainResolverTest.php @@ -2,6 +2,7 @@ namespace FlixTech\AvroSerializer\Test\Objects\SchemaResolvers; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\SchemaResolverInterface; use FlixTech\AvroSerializer\Objects\SchemaResolvers\ChainResolver; use PHPUnit\Framework\MockObject\MockObject; @@ -36,10 +37,9 @@ protected function setUp(): void } /** - * @test - * * @throws \AvroSchemaParseException */ + #[Test] public function it_will_exit_early_when_a_schema_has_been_resolved(): void { $record = 'I am a record'; @@ -59,10 +59,9 @@ public function it_will_exit_early_when_a_schema_has_been_resolved(): void } /** - * @test - * * @throws \AvroSchemaParseException */ + #[Test] public function it_will_exit_early_when_a_key_schema_has_been_resolved(): void { $record = 'I am a record'; @@ -82,10 +81,9 @@ public function it_will_exit_early_when_a_key_schema_has_been_resolved(): void } /** - * @test - * * @throws \AvroSchemaParseException */ + #[Test] public function it_will_call_all_resolvers(): void { $record = 'I am a record'; @@ -107,10 +105,9 @@ public function it_will_call_all_resolvers(): void } /** - * @test - * * @throws \AvroSchemaParseException */ + #[Test] public function it_will_call_all_resolvers_for_key_schemas(): void { $record = 'I am a record'; @@ -131,9 +128,7 @@ public function it_will_call_all_resolvers_for_key_schemas(): void $this->assertEquals($avroSchema, $actual); } - /** - * @test - */ + #[Test] public function it_should_call_all_resolvers_and_throw_for_value_when_no_resolver_has_a_result(): void { $this->expectException(\InvalidArgumentException::class); @@ -153,9 +148,7 @@ public function it_should_call_all_resolvers_and_throw_for_value_when_no_resolve $this->chain->valueSchemaFor($record); } - /** - * @test - */ + #[Test] public function it_should_call_all_resolvers_and_return_null_when_no_key_resolver_has_a_result(): void { $record = 'I am a record'; diff --git a/test/Objects/SchemaResolvers/DefinitionInterfaceResolverTest.php b/test/Objects/SchemaResolvers/DefinitionInterfaceResolverTest.php index 56c56b9..6658bdd 100644 --- a/test/Objects/SchemaResolvers/DefinitionInterfaceResolverTest.php +++ b/test/Objects/SchemaResolvers/DefinitionInterfaceResolverTest.php @@ -2,6 +2,7 @@ namespace FlixTech\AvroSerializer\Test\Objects\SchemaResolvers; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\HasSchemaDefinitionInterface; use FlixTech\AvroSerializer\Objects\SchemaResolvers\DefinitionInterfaceResolver; use PHPUnit\Framework\TestCase; @@ -9,10 +10,9 @@ class DefinitionInterfaceResolverTest extends TestCase { /** - * @test - * * @throws \AvroSchemaParseException */ + #[Test] public function it_should_allow_correct_interfaces(): void { $definitionInterfaceResolver = new DefinitionInterfaceResolver(); @@ -43,9 +43,7 @@ public function it_should_allow_correct_interfaces(): void ); } - /** - * @test - */ + #[Test] public function it_should_fail_for_records_not_implementing_the_interface_for_value_schema(): void { $this->expectException(\InvalidArgumentException::class); @@ -54,9 +52,7 @@ public function it_should_fail_for_records_not_implementing_the_interface_for_va $definitionInterfaceResolver->valueSchemaFor([]); } - /** - * @test - */ + #[Test] public function it_should_fail_for_records_not_implementing_the_interface_for_key_schema(): void { $this->expectException(\InvalidArgumentException::class); diff --git a/test/Objects/SchemaResolvers/FileResolverTest.php b/test/Objects/SchemaResolvers/FileResolverTest.php index e8fdb47..d561814 100644 --- a/test/Objects/SchemaResolvers/FileResolverTest.php +++ b/test/Objects/SchemaResolvers/FileResolverTest.php @@ -4,6 +4,8 @@ namespace FlixTech\AvroSerializer\Test\Objects\SchemaResolvers; +use PHPUnit\Framework\Attributes\Test; +use Widmogrod\Common\ValueOfInterface; use FlixTech\AvroSerializer\Objects\SchemaResolvers\FileResolver; use PHPUnit\Framework\TestCase; @@ -12,10 +14,9 @@ class FileResolverTest extends TestCase { /** - * @test - * * @throws \AvroSchemaParseException */ + #[Test] public function it_should_find_value_and_key_schemas_when_defined(): void { $fileSchemaResolver = $this->getFileSchemaResolverInstance(); @@ -33,10 +34,9 @@ public function it_should_find_value_and_key_schemas_when_defined(): void } /** - * @test - * * @throws \AvroSchemaParseException */ + #[Test] public function it_should_fail_for_non_existing_value_schema(): void { $this->expectException(\InvalidArgumentException::class); @@ -47,10 +47,9 @@ public function it_should_fail_for_non_existing_value_schema(): void } /** - * @test - * * @throws \AvroSchemaParseException */ + #[Test] public function it_should_fail_for_value_schema_for_invalid_inflector_result(): void { $this->expectException(\InvalidArgumentException::class); @@ -65,10 +64,9 @@ public function it_should_fail_for_value_schema_for_invalid_inflector_result(): } /** - * @test - * * @throws \AvroSchemaParseException */ + #[Test] public function it_should_fail_for_key_schema_for_invalid_inflector_result(): void { $this->expectException(\InvalidArgumentException::class); @@ -89,7 +87,7 @@ protected function getFileSchemaResolverInstance(): FileResolver $inflector = static function ($record, bool $isKey) { $ext = $isKey ? '.key.json' : '.json'; - /** @var \Widmogrod\Common\ValueOfInterface $inflectedString */ + /** @var ValueOfInterface $inflectedString */ $inflectedString = inflectRecord($record) ->map( static function ($inflectedObjectName) use ($ext) { diff --git a/test/ProtocolTest.php b/test/ProtocolTest.php index cd55aa6..2fbd4c6 100644 --- a/test/ProtocolTest.php +++ b/test/ProtocolTest.php @@ -2,6 +2,7 @@ namespace FlixTech\AvroSerializer\Test; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\Exceptions\AvroDecodingException; use Widmogrod\Monad\Either\Left; use Widmogrod\Monad\Either\Right; @@ -28,17 +29,13 @@ class ProtocolTest extends AbstractFunctionalTestCase private const NULL_TERMINATED_HEX = '000000270f303000000000'; private const NULL_TERMINATED_AVRO_HEX = '303000000000'; - /** - * @test - */ + #[Test] public function it_should_always_provide_correct_version(): void { $this->assertSame(version(), WIRE_FORMAT_PROTOCOL_VERSION); } - /** - * @test - */ + #[Test] public function encode_should_produce_Right_Either_Monad_with_valid_protocol(): void { $encoded = encode(WIRE_FORMAT_PROTOCOL_VERSION, self::SCHEMA_ID, self::HEX_BIN); @@ -47,9 +44,7 @@ public function encode_should_produce_Right_Either_Monad_with_valid_protocol(): $this->assertSame(self::VALID_PROTOCOL_HEX_BIN, \bin2hex($encoded->extract())); } - /** - * @test - */ + #[Test] public function encoder_factory_should_create_curried_function(): void { $encoder = encoder(WIRE_FORMAT_PROTOCOL_VERSION); @@ -60,9 +55,7 @@ public function encoder_factory_should_create_curried_function(): void ); } - /** - * @test - */ + #[Test] public function protocol_decoder_should_decode_correctly(): void { $binaryInput = \hex2bin(self::HEX_BIN); @@ -78,9 +71,7 @@ public function protocol_decoder_should_decode_correctly(): void $this->assertSame(self::AVRO_ENCODED_RECORD_HEX_BIN, \bin2hex($unpacked[PROTOCOL_ACCESSOR_AVRO])); } - /** - * @test - */ + #[Test] public function protocol_decoder_should_turn_Left_with_Exception_for_invalid_inputs(): void { $binaryInput = \hex2bin(self::INVALID_BIN_TOO_SHORT); @@ -90,9 +81,7 @@ public function protocol_decoder_should_turn_Left_with_Exception_for_invalid_inp $this->assertInstanceOf(AvroDecodingException::class, $decoded->extract()); } - /** - * @test - */ + #[Test] public function validator_factory_should_return_curried_function(): void { $this->assertEquals( @@ -101,9 +90,7 @@ public function validator_factory_should_return_curried_function(): void ); } - /** - * @test - */ + #[Test] public function validate_should_inspect_unpacked_array_correctly(): void { $decoded = [ @@ -118,9 +105,7 @@ public function validate_should_inspect_unpacked_array_correctly(): void $this->assertSame($decoded, $just->extract()); } - /** - * @test - */ + #[Test] public function validate_returns_nothing_for_invalid_unpacked(): void { $decoded = [ @@ -155,9 +140,7 @@ public function validate_returns_nothing_for_invalid_unpacked(): void $this->assertInstanceOf(Nothing::class, validate(WIRE_FORMAT_PROTOCOL_VERSION, $decoded)); } - /** - * @test - */ + #[Test] public function null_terminated_values_unpacked_correctly(): void { $decoded = decode(\hex2bin(self::NULL_TERMINATED_HEX)); diff --git a/test/SerializeTest.php b/test/SerializeTest.php index 5b7d97a..82351ae 100644 --- a/test/SerializeTest.php +++ b/test/SerializeTest.php @@ -2,7 +2,7 @@ namespace FlixTech\AvroSerializer\Test; -use AvroIODatumWriter; +use PHPUnit\Framework\Attributes\Test; use FlixTech\AvroSerializer\Objects\Exceptions\AvroDecodingException; use FlixTech\AvroSerializer\Objects\Exceptions\AvroEncodingException; use Widmogrod\Monad\Either\Left; @@ -22,10 +22,9 @@ class SerializeTest extends AbstractFunctionalTestCase { /** - * @test - * * @throws \AvroIOException */ + #[Test] public function avroStringIo_should_produce_new_instances_of_AvroStringIO(): void { $avroStringIo = avroStringIo('test'); @@ -36,10 +35,9 @@ public function avroStringIo_should_produce_new_instances_of_AvroStringIO(): voi } /** - * @test - * * @throws \AvroIOException */ + #[Test] public function avroBinaryEncoder_should_produce_new_instances_of_AvroBinaryEncoder(): void { $avroStringIo = avroStringIo('test'); @@ -52,10 +50,9 @@ public function avroBinaryEncoder_should_produce_new_instances_of_AvroBinaryEnco } /** - * @test - * * @throws \AvroIOException */ + #[Test] public function avroBinaryDecoder_should_produce_new_instances_of_AvroBinaryDecoder(): void { $avroStringIo = avroStringIo('test'); @@ -68,13 +65,12 @@ public function avroBinaryDecoder_should_produce_new_instances_of_AvroBinaryDeco } /** - * @test - * * @throws \AvroIOException */ + #[Test] public function avroDatumWriter_should_create_curried_function(): void { - $writer = new AvroIODatumWriter(); + $writer = new \AvroIODatumWriter(); $io = avroStringIo(''); $this->assertEquals( @@ -84,13 +80,12 @@ public function avroDatumWriter_should_create_curried_function(): void } /** - * @test - * * @throws \AvroIOException */ + #[Test] public function writeDatum_should_correctly_produce_avro_encoded_binary_string_Right_Monad(): void { - $writer = new AvroIODatumWriter(); + $writer = new \AvroIODatumWriter(); $io = avroStringIo(''); $firstCall = writeDatum($writer, $io, $this->avroSchema, self::TEST_RECORD); @@ -108,13 +103,12 @@ public function writeDatum_should_correctly_produce_avro_encoded_binary_string_R } /** - * @test - * * @throws \AvroIOException */ + #[Test] public function writeDatum_should_produce_Left_Monad_for_invalid_inputs(): void { - $writer = new AvroIODatumWriter(); + $writer = new \AvroIODatumWriter(); $io = avroStringIo(''); $left = writeDatum($writer, $io, $this->avroSchema, self::INVALID_TEST_RECORD); @@ -124,10 +118,9 @@ public function writeDatum_should_produce_Left_Monad_for_invalid_inputs(): void } /** - * @test - * * @throws \AvroIOException */ + #[Test] public function avroDatumReader_should_return_curried_function(): void { $writer = new \AvroIODatumReader(); @@ -140,10 +133,9 @@ public function avroDatumReader_should_return_curried_function(): void } /** - * @test - * * @throws \AvroIOException */ + #[Test] public function readDatum_should_return_Right_Monad_for_valid_inputs(): void { $reader = new \AvroIODatumReader(); @@ -167,10 +159,9 @@ public function readDatum_should_return_Right_Monad_for_valid_inputs(): void } /** - * @test - * * @throws \AvroIOException */ + #[Test] public function readDatum_should_turn_Left_Monad_for_invalid_reader_and_writer_schemas(): void { $reader = new \AvroIODatumReader(); diff --git a/test/bootstrap.php b/test/bootstrap.php index 7d5af00..e8f34e0 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -1,5 +1,6 @@ load(); +(new Dotenv(__DIR__ . '/..', '.env.dist'))->load();