Skip to content

Commit ea62327

Browse files
committed
test
1 parent 84fb16e commit ea62327

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

src/Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ private function getProperties(string $resourceClass, ?Parameter $parameter = nu
132132
$relationSegments = [];
133133
$convertedRelationSegments = [];
134134
$relationClasses = [];
135+
$traversalSuccessful = true;
135136

136137
foreach ($parts as $i => $part) {
137138
$isLastPart = ($i === \count($parts) - 1);
138139

139140
try {
140141
$propertyMetadata = $this->propertyMetadataFactory->create($currentClass, $part);
141142
} catch (\Exception $e) {
143+
$traversalSuccessful = false;
142144
break;
143145
}
144146

@@ -174,17 +176,17 @@ private function getProperties(string $resourceClass, ?Parameter $parameter = nu
174176
}
175177

176178
if (!$nextClass) {
179+
$traversalSuccessful = false;
177180
break;
178181
}
179182

180183
$currentClass = $nextClass;
181184
}
182185

183186
if ($propertyMetadata->isReadable()) {
184-
$propertyNames[] = $property;
185-
186187
// For leaf property, apply name conversion and store full metadata
187188
if ($isLastPart) {
189+
$propertyNames[] = $property;
188190
$leafProperty = $this->nameConverter?->normalize($part) ?? $part;
189191

190192
$properties[$property] = $propertyMetadata->withExtraProperties([
@@ -207,6 +209,12 @@ private function getProperties(string $resourceClass, ?Parameter $parameter = nu
207209
continue;
208210
}
209211

212+
// If traversal wasn't fully successful but the property was explicitly listed
213+
// (e.g., in parameter's properties array for placeholder expansion), still include it
214+
if (!$traversalSuccessful && !\in_array($property, $propertyNames, true)) {
215+
$propertyNames[] = $property;
216+
}
217+
210218
// Skip the simple property processing below for nested properties
211219
continue;
212220
}

src/Metadata/Tests/Resource/Factory/ParameterResourceMetadataCollectionFactoryTest.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ public function testParameterFactory(): void
3838
$nameCollection = $this->createStub(PropertyNameCollectionFactoryInterface::class);
3939
$nameCollection->method('create')->willReturn(new PropertyNameCollection(['id', 'hydra', 'everywhere']));
4040
$propertyMetadata = $this->createStub(PropertyMetadataFactoryInterface::class);
41-
$propertyMetadata->method('create')->willReturnOnConsecutiveCalls(
42-
new ApiProperty(identifier: true),
43-
new ApiProperty(readable: true),
44-
new ApiProperty(readable: true),
45-
new ApiProperty(identifier: true),
46-
new ApiProperty(readable: true),
47-
new ApiProperty(readable: true)
41+
$propertyMetadata->method('create')->willReturnCallback(
42+
static fn (string $class, string $property) => match ($property) {
43+
'id' => new ApiProperty(identifier: true),
44+
default => new ApiProperty(readable: true),
45+
}
4846
);
4947
$filterLocator = $this->createStub(ContainerInterface::class);
5048
$filterLocator->method('has')->willReturn(true);
@@ -185,13 +183,11 @@ public function testParameterFactoryNoFilter(): void
185183
$nameCollection = $this->createStub(PropertyNameCollectionFactoryInterface::class);
186184
$nameCollection->method('create')->willReturn(new PropertyNameCollection(['id', 'hydra', 'everywhere']));
187185
$propertyMetadata = $this->createStub(PropertyMetadataFactoryInterface::class);
188-
$propertyMetadata->method('create')->willReturnOnConsecutiveCalls(
189-
new ApiProperty(identifier: true),
190-
new ApiProperty(readable: true),
191-
new ApiProperty(readable: true),
192-
new ApiProperty(identifier: true),
193-
new ApiProperty(readable: true),
194-
new ApiProperty(readable: true)
186+
$propertyMetadata->method('create')->willReturnCallback(
187+
static fn (string $class, string $property) => match ($property) {
188+
'id' => new ApiProperty(identifier: true),
189+
default => new ApiProperty(readable: true),
190+
}
195191
);
196192
$filterLocator = $this->createStub(ContainerInterface::class);
197193
$filterLocator->method('has')->willReturn(false);

0 commit comments

Comments
 (0)