Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions src/Hydrators/PrestyledAssoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use function explode;
use function is_array;
use function strtolower;

/**
* Hydrates associative rows whose keys are pre-styled as `specifier__styledProp`.
Expand Down Expand Up @@ -41,7 +42,7 @@ public function hydrateAll(
$grouped = [];
foreach ($raw as $alias => $value) {
[$prefix, $prop] = explode('__', $alias, 2);
$grouped[$prefix][$prop] = $value;
$grouped[strtolower($prefix)][$prop] = $value;
}

/** @var SplObjectStorage<object, Scope> $entities */
Expand Down Expand Up @@ -83,9 +84,13 @@ private function buildScopeMap(Scope $scope): array
return $this->scopeMap;
}

// Keys are lowercased: a column specifier survives the round-trip through
// the database as the alias case the driver chose (PostgreSQL folds
// unquoted identifiers to lower case, others preserve them), so the
// prefix is matched case-insensitively.
$this->scopeMap = [];
foreach (ScopeIterator::recursive($scope) as $spec => $c) {
$this->scopeMap[$spec] = $c;
$this->scopeMap[strtolower($spec)] = $c;
}

$this->cachedScope = $scope;
Expand Down
20 changes: 20 additions & 0 deletions tests/Hydrators/PrestyledAssocTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ public function hydrateSingleEntity(): void
$this->assertEquals('Alice', $this->factory->get($entity, 'name'));
}

#[Test]
public function hydrateMatchesSpecifierPrefixCaseInsensitively(): void
{
// A camelCase scope name (`edgeCaseEntity`) becomes the column specifier;
// PostgreSQL folds the unquoted alias to lower case, so the row comes back
// prefixed `edgecaseentity__`. The prefix must still resolve to its scope.
$hydrator = new PrestyledAssoc($this->factory);
$scope = new Scope('edgeCaseEntity');

$result = $hydrator->hydrateAll(
['edgecaseentity__initialized' => 'folded'],
$scope,
);

$this->assertNotFalse($result);
$this->assertCount(1, $result);
$result->rewind();
$this->assertEquals('folded', $this->factory->get($result->current(), 'initialized'));
}

#[Test]
public function hydrateMultipleEntitiesFromJoinedRow(): void
{
Expand Down
Loading