Skip to content

Commit

Permalink
misc: add fixed value for root node path
Browse files Browse the repository at this point in the history
The path is no longer an empty string, the string `*root*` is now
returned.
  • Loading branch information
romm committed Jul 26, 2022
1 parent f61eb55 commit 0b37b48
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Mapper/Tree/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public function attributes(): Attributes

public function path(): string
{
if (! isset($this->parent)) {
return '*root*';
}

$node = $this;
$path = [];

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Mapper/Tree/Builder/TreeNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function test_node_leaf_values_can_be_retrieved(): void

self::assertTrue($node->isRoot());
self::assertSame('', $node->name());
self::assertSame('', $node->path());
self::assertSame('*root*', $node->path());
self::assertSame($type->toString(), $node->type());
self::assertTrue($node->sourceFilled());
self::assertSame('some source value', $node->sourceValue());
Expand Down
9 changes: 8 additions & 1 deletion tests/Unit/Mapper/Tree/ShellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public function test_type_and_value_can_be_retrieved(): void
self::assertSame($value, $shell->value());
}

public function test_root_path_is_fixed(): void
{
$shell = Shell::root(new FakeType(), 'foo');

self::assertSame('*root*', $shell->path());
}

public function test_change_type_changes_type(): void
{
$typeA = FakeType::matching($typeB = new FakeType());
Expand Down Expand Up @@ -66,7 +73,7 @@ public function test_change_type_with_invalid_type_throws_exception(): void

$this->expectException(NewShellTypeDoesNotMatch::class);
$this->expectExceptionCode(1628845224);
$this->expectExceptionMessage("Trying to change the type of the shell at path ``: `{$typeB->toString()}` is not a valid subtype of `{$typeA->toString()}`.");
$this->expectExceptionMessage("Trying to change the type of the shell at path `*root*`: `{$typeB->toString()}` is not a valid subtype of `{$typeA->toString()}`.");

(Shell::root($typeA, []))->withType($typeB);
}
Expand Down

0 comments on commit 0b37b48

Please sign in to comment.