Skip to content

Commit a867785

Browse files
committed
analyze only the current class
1 parent e4caf6a commit a867785

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

src/Metadata/AttributeMetadataFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ private function getPropertyMetadataList(ReflectionClass $reflectionClass): arra
138138
continue;
139139
}
140140

141+
if ($reflectionProperty->getDeclaringClass()->getName() !== $reflectionClass->getName()) {
142+
continue;
143+
}
144+
141145
$fieldName = $this->getFieldName($reflectionProperty);
142146

143147
if (array_key_exists($fieldName, $properties)) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\Hydrator\Tests\Unit\Fixture;
6+
7+
use DateTimeImmutable;
8+
9+
final class DistributionCreated extends DomainEvent
10+
{
11+
public function __construct(
12+
DateTimeImmutable $distributionDate,
13+
) {
14+
parent::__construct($distributionDate);
15+
}
16+
}

tests/Unit/Fixture/DomainEvent.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\Hydrator\Tests\Unit\Fixture;
6+
7+
use DateTimeImmutable;
8+
9+
abstract class DomainEvent
10+
{
11+
public function __construct(
12+
protected readonly DateTimeImmutable $recordedDate,
13+
) {
14+
}
15+
16+
public function occurredOn(): DateTimeImmutable
17+
{
18+
return $this->recordedDate;
19+
}
20+
}

tests/Unit/Metadata/AttributeMetadataFactoryTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Patchlevel\Hydrator\Metadata\SubjectIdAndPersonalDataConflict;
1919
use Patchlevel\Hydrator\Normalizer\EnumNormalizer;
2020
use Patchlevel\Hydrator\Tests\Unit\Fixture\BrokenParentDto;
21+
use Patchlevel\Hydrator\Tests\Unit\Fixture\DistributionCreated;
2122
use Patchlevel\Hydrator\Tests\Unit\Fixture\DuplicateFieldNameDto;
2223
use Patchlevel\Hydrator\Tests\Unit\Fixture\Email;
2324
use Patchlevel\Hydrator\Tests\Unit\Fixture\EmailNormalizer;
@@ -249,6 +250,18 @@ public function testExtendsDuplicatedFieldName(): void
249250
$metadataFactory->metadata(BrokenParentDto::class);
250251
}
251252

253+
public function testBug70(): void
254+
{
255+
$metadataFactory = new AttributeMetadataFactory();
256+
$metadata = $metadataFactory->metadata(DistributionCreated::class);
257+
258+
self::assertCount(1, $metadata->properties());
259+
260+
$property = $metadata->propertyForField('recordedDate');
261+
262+
self::assertSame('recordedDate', $property->propertyName());
263+
}
264+
252265
public function testSameClassDuplicatedFieldName(): void
253266
{
254267
$this->expectException(DuplicatedFieldNameInMetadata::class);

0 commit comments

Comments
 (0)