Skip to content

Commit

Permalink
fix: fetch correct node value for children
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed Sep 26, 2022
1 parent c009ab9 commit 3ee526c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
12 changes: 2 additions & 10 deletions src/Mapper/Tree/Builder/TreeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ public function withMessage(Message $message): self
return $clone;
}

/**
* @return array<self>
*/
public function children(): array
{
return $this->children;
}

public function node(): Node
{
return $this->buildNode($this);
Expand Down Expand Up @@ -157,8 +149,8 @@ private function buildNode(self $self): Node
$self->shell->name(),
$self->shell->path(),
$self->shell->type()->toString(),
$this->shell->hasValue(),
$this->shell->hasValue() ? $this->shell->value() : null,
$self->shell->hasValue(),
$self->shell->hasValue() ? $self->shell->value() : null,
$self->valid ? $self->value : null,
$self->messages,
array_map(
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Mapper/Tree/Builder/ArrayNodeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function test_build_with_null_value_in_flexible_mode_returns_empty_branch
$node = (new RootNodeBuilder(new ArrayNodeBuilder(true)))->build(FakeShell::new(ArrayType::native()));

self::assertSame([], $node->value());
self::assertEmpty($node->children());
self::assertEmpty($node->node()->children());
}

public function test_invalid_type_fails_assertion(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Mapper/Tree/Builder/ListNodeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function test_build_with_null_value_in_flexible_mode_returns_empty_branch
$node = (new RootNodeBuilder(new ListNodeBuilder(true)))->build(FakeShell::new(ListType::native()));

self::assertSame([], $node->value());
self::assertEmpty($node->children());
self::assertEmpty($node->node()->children());
}

public function test_invalid_type_fails_assertion(): void
Expand Down
25 changes: 16 additions & 9 deletions tests/Unit/Mapper/Tree/Builder/TreeNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,24 @@ public function test_node_branch_values_can_be_retrieved(): void
$attributesChildA = new FakeAttributes();
$attributesChildB = new FakeAttributes();

$children = FakeTreeNode::branch([
$node = FakeTreeNode::branch([
'foo' => ['type' => $typeChildA, 'value' => 'foo', 'attributes' => $attributesChildA],
'bar' => ['type' => $typeChildB, 'value' => 'bar', 'attributes' => $attributesChildB],
])->children();

self::assertSame('foo', $children['foo']->node()->name());
self::assertSame('foo', $children['foo']->node()->path());
self::assertFalse($children['foo']->node()->isRoot());
self::assertSame('bar', $children['bar']->node()->name());
self::assertSame('bar', $children['bar']->node()->path());
self::assertFalse($children['bar']->node()->isRoot());
]);

$childFoo = $node->node()->children()['foo'];
$childBar = $node->node()->children()['bar'];

self::assertSame('foo', $childFoo->name());
self::assertSame('foo', $childFoo->path());
self::assertSame('foo', $childFoo->sourceValue());
self::assertSame(true, $childFoo->sourceFilled());
self::assertFalse($childFoo->isRoot());
self::assertSame('bar', $childBar->name());
self::assertSame('bar', $childBar->path());
self::assertSame('bar', $childBar->sourceValue());
self::assertSame(true, $childBar->sourceFilled());
self::assertFalse($childBar->isRoot());
}

public function test_node_branch_with_duplicated_child_name_throws_exception(): void
Expand Down

0 comments on commit 3ee526c

Please sign in to comment.