Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Metadata/AttributeMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ private function getPropertyMetadataList(ReflectionClass $reflectionClass): arra
continue;
}

if ($reflectionProperty->getDeclaringClass()->getName() !== $reflectionClass->getName()) {
continue;
}

$fieldName = $this->getFieldName($reflectionProperty);

if (array_key_exists($fieldName, $properties)) {
Expand Down
16 changes: 16 additions & 0 deletions tests/Unit/Fixture/DistributionCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Patchlevel\Hydrator\Tests\Unit\Fixture;

use DateTimeImmutable;

final class DistributionCreated extends DomainEvent
{
public function __construct(
DateTimeImmutable $distributionDate,
) {
parent::__construct($distributionDate);
}
}
20 changes: 20 additions & 0 deletions tests/Unit/Fixture/DomainEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Patchlevel\Hydrator\Tests\Unit\Fixture;

use DateTimeImmutable;

abstract class DomainEvent
{
public function __construct(
protected readonly DateTimeImmutable $recordedDate,
) {
}

public function occurredOn(): DateTimeImmutable
{
return $this->recordedDate;
}
}
13 changes: 13 additions & 0 deletions tests/Unit/Metadata/AttributeMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Patchlevel\Hydrator\Metadata\SubjectIdAndPersonalDataConflict;
use Patchlevel\Hydrator\Normalizer\EnumNormalizer;
use Patchlevel\Hydrator\Tests\Unit\Fixture\BrokenParentDto;
use Patchlevel\Hydrator\Tests\Unit\Fixture\DistributionCreated;
use Patchlevel\Hydrator\Tests\Unit\Fixture\DuplicateFieldNameDto;
use Patchlevel\Hydrator\Tests\Unit\Fixture\Email;
use Patchlevel\Hydrator\Tests\Unit\Fixture\EmailNormalizer;
Expand Down Expand Up @@ -249,6 +250,18 @@ public function testExtendsDuplicatedFieldName(): void
$metadataFactory->metadata(BrokenParentDto::class);
}

public function testBug70(): void
{
$metadataFactory = new AttributeMetadataFactory();
$metadata = $metadataFactory->metadata(DistributionCreated::class);

self::assertCount(1, $metadata->properties());

$property = $metadata->propertyForField('recordedDate');

self::assertSame('recordedDate', $property->propertyName());
}

public function testSameClassDuplicatedFieldName(): void
{
$this->expectException(DuplicatedFieldNameInMetadata::class);
Expand Down
Loading