Skip to content

Commit

Permalink
test: fix bug binding nested iterator aggregate
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Oct 14, 2023
1 parent 448312e commit f770625
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/ListBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public function bindListData(

if($this->isKVP($listValue)) {
$elementBinder->bind(null, $listKey, $t);
if(is_object($listValue)) {
$listValue = get_object_vars($listValue);
$listValue = array_filter($listValue, fn($item) => !is_array($item));
}

foreach($listValue as $key => $value) {
$elementBinder->bind($key, $value, $t);
Expand Down Expand Up @@ -162,7 +166,7 @@ private function isNested(mixed $item):bool {
$key = array_key_first($item);
return is_int($key) || is_iterable($item[$key]);
}
elseif($item instanceof Iterator || $item instanceof \Traversable) {
elseif($item instanceof Iterator) {
return true;
}

Expand Down
5 changes: 4 additions & 1 deletion test/phpunit/ListBinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,10 @@ public function testBindListData_iteratorAggregate_outerBinds():void {
$firstName = $arrayStudent["firstName"];
$lastName = $arrayStudent["lastName"];

self::assertSame("$firstName $lastName", $studentLi->querySelector("dd.name")->textContent);
self::assertSame(
"$firstName $lastName",
trim(preg_replace("/\s+/", " ", $studentLi->querySelector("dd.name")->textContent))
);

$arrayModuleData = $arrayStudent["modules"];
foreach($studentLi->querySelectorAll(".modules ul>li") as $moduleLi) {
Expand Down

0 comments on commit f770625

Please sign in to comment.