Skip to content

Commit

Permalink
bump phpunit add test for attributes (#3)
Browse files Browse the repository at this point in the history
* bump phpunit add test for attributes

* fix: phpunit removed withConsecutive method

* fix: willReturnCallback usages

* update Makefile
  • Loading branch information
mattiabasone committed Jan 29, 2025
1 parent bc136d2 commit f7883b0
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,7 +77,8 @@ public function it_should_encode_with_valid_encode_context(): void
#[Test]
public function it_should_decode_with_valid_decode_context(): void
{
$this->recordSerializerMock->expects($this->exactly(2))
$matcher = $this->exactly(2);
$this->recordSerializerMock->expects($matcher)
->method('decodeMessage')
->willReturnOnConsecutiveCalls('success-1', 'success-2');

Expand Down
1 change: 1 addition & 0 deletions test/Objects/DefaultRecordSerializerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace FlixTech\AvroSerializer\Test\Objects;

use PHPUnit\Framework\Attributes\Test;
use FlixTech\AvroSerializer\Objects\DefaultRecordSerializerFactory;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand Down
1 change: 1 addition & 0 deletions test/Objects/Schema/ArrayTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace FlixTech\AvroSerializer\Test\Objects\Schema;

use PHPUnit\Framework\Attributes\Test;
use FlixTech\AvroSerializer\Objects\Schema;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand Down
1 change: 1 addition & 0 deletions test/Objects/Schema/EnumTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace FlixTech\AvroSerializer\Test\Objects\Schema;

use PHPUnit\Framework\Attributes\Test;
use FlixTech\AvroSerializer\Objects\Schema;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand Down
1 change: 1 addition & 0 deletions test/Objects/Schema/FixedTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace FlixTech\AvroSerializer\Test\Objects\Schema;

use PHPUnit\Framework\Attributes\Test;
use FlixTech\AvroSerializer\Objects\Schema;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand Down
18 changes: 16 additions & 2 deletions test/Objects/Schema/Generation/Fixture/RecordWithRecordType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
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
{
/**
Expand All @@ -23,13 +29,21 @@ 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;
}
9 changes: 9 additions & 0 deletions test/Objects/Schema/Generation/Fixture/SimpleRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
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")
Expand All @@ -13,12 +17,17 @@
*
* @SerDe\AvroType("record")
*/
#[AvroName("SimpleRecord")]
#[AvroNamespace("org.acme")]
#[AvroType("record")]
class SimpleRecord
{
/**
* @SerDe\AvroType("int")
*
* @SerDe\AvroDefault(42)
*/
#[AvroType("int")]
#[AvroDefault(42)]
private $intType;
}
54 changes: 46 additions & 8 deletions test/Objects/Schema/Generation/SchemaGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Doctrine\Common\Annotations\AnnotationReader;
use FlixTech\AvroSerializer\Objects\Schema;
use FlixTech\AvroSerializer\Objects\Schema\Generation\AttributeReader;
use FlixTech\AvroSerializer\Objects\Schema\Generation\SchemaGenerator;
use FlixTech\AvroSerializer\Objects\Schema\Record\FieldOption;
use FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\ArraysWithComplexType;
use FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\EmptyRecord;
use FlixTech\AvroSerializer\Test\Objects\Schema\Generation\Fixture\MapsWithComplexType;
Expand All @@ -18,15 +20,21 @@

class SchemaGeneratorTest extends TestCase
{
private SchemaGenerator $generator;
private SchemaGenerator $generatorDoctrineAnnotations;

private SchemaGenerator $generatorAttributes;

protected function setUp(): void
{
$this->generator = new SchemaGenerator(
$this->generatorDoctrineAnnotations = new SchemaGenerator(
new Schema\Generation\AnnotationReader(
new AnnotationReader()
)
);

$this->generatorAttributes = new SchemaGenerator(
new AttributeReader()
);
}

/**
Expand All @@ -35,7 +43,7 @@ protected function setUp(): void
#[Test]
public function it_should_generate_an_empty_record(): void
{
$schema = $this->generator->generate(EmptyRecord::class);
$schema = $this->generatorDoctrineAnnotations->generate(EmptyRecord::class);

$expected = Schema::record()
->name('EmptyRecord')
Expand All @@ -50,7 +58,7 @@ public function it_should_generate_an_empty_record(): void
#[Test]
public function it_should_generate_a_record_schema_with_primitive_types(): void
{
$schema = $this->generator->generate(PrimitiveTypes::class);
$schema = $this->generatorDoctrineAnnotations->generate(PrimitiveTypes::class);

$expected = Schema::record()
->name('PrimitiveTypes')
Expand Down Expand Up @@ -101,7 +109,7 @@ public function it_should_generate_a_record_schema_with_primitive_types(): void
#[Test]
public function it_should_generate_a_schema_record_with_complex_types(): void
{
$schema = $this->generator->generate(RecordWithComplexTypes::class);
$schema = $this->generatorDoctrineAnnotations->generate(RecordWithComplexTypes::class);

$expected = Schema::record()
->name('RecordWithComplexTypes')
Expand Down Expand Up @@ -146,7 +154,7 @@ public function it_should_generate_a_schema_record_with_complex_types(): void
#[Test]
public function it_should_generate_records_containing_records(): void
{
$schema = $this->generator->generate(RecordWithRecordType::class);
$schema = $this->generatorDoctrineAnnotations->generate(RecordWithRecordType::class);

$expected = Schema::record()
->name('RecordWithRecordType')
Expand All @@ -173,13 +181,43 @@ public function it_should_generate_records_containing_records(): void
$this->assertEquals($expected, $schema);
}

#[Test]
public function it_should_generate_records_containing_records_using_attributes(): void
{
$schema = $this->generatorAttributes->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);
}

/**
* @throws \ReflectionException
*/
#[Test]
public function it_should_generate_a_record_schema_with_arrays_containing_complex_types(): void
{
$schema = $this->generator->generate(ArraysWithComplexType::class);
$schema = $this->generatorDoctrineAnnotations->generate(ArraysWithComplexType::class);

$expected = Schema::record()
->name('ArraysWithComplexType')
Expand Down Expand Up @@ -210,7 +248,7 @@ public function it_should_generate_a_record_schema_with_arrays_containing_comple
#[Test]
public function it_should_generate_a_record_schema_with_maps_containing_complex_types(): void
{
$schema = $this->generator->generate(MapsWithComplexType::class);
$schema = $this->generatorDoctrineAnnotations->generate(MapsWithComplexType::class);

$expected = Schema::record()
->name('MapsWithComplexType')
Expand Down
1 change: 1 addition & 0 deletions test/Objects/Schema/MapTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace FlixTech\AvroSerializer\Test\Objects\Schema;

use PHPUnit\Framework\Attributes\Test;
use FlixTech\AvroSerializer\Objects\Schema;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand Down
1 change: 1 addition & 0 deletions test/Objects/Schema/RecordTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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\Attributes\Test;
Expand Down
1 change: 1 addition & 0 deletions test/Objects/SchemaResolvers/ChainResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\Attributes\Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\Attributes\Test;
Expand Down
2 changes: 2 additions & 0 deletions test/Objects/SchemaResolvers/FileResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand Down
1 change: 1 addition & 0 deletions test/ProtocolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FlixTech\AvroSerializer\Test;

use PHPUnit\Framework\Attributes\Test;
use FlixTech\AvroSerializer\Objects\Exceptions\AvroDecodingException;
use PHPUnit\Framework\Attributes\Test;
use Widmogrod\Monad\Either\Left;
Expand Down

0 comments on commit f7883b0

Please sign in to comment.