type()); self::assertSame($value, $shell->value()); } public function test_change_type_changes_type(): void { $typeA = FakeType::thatWillMatch($typeB = new FakeType()); $shellA = Shell::root($typeA, []); $shellB = $shellA->withType($typeB); self::assertNotSame($shellA, $shellB); self::assertSame($typeB, $shellB->type()); } public function test_unresolvable_type_throws_exception(): void { $type = new UnresolvableType('some message'); $this->expectException(UnresolvableShellType::class); $this->expectExceptionCode(1630943848); $this->expectExceptionMessage('some message'); Shell::root($type, []); } public function test_change_type_with_invalid_type_throws_exception(): void { $typeA = new FakeType(); $typeB = new FakeType(); $this->expectException(NewShellTypeDoesNotMatch::class); $this->expectExceptionCode(1628845224); $this->expectExceptionMessage("Trying to change the type of the shell at path ``: `$typeB` is not a valid subtype of `$typeA`."); (Shell::root($typeA, []))->withType($typeB); } public function test_change_value_changes_value(): void { $valueA = 'foo'; $valueB = 'bar'; $shellA = Shell::root(new FakeType(), $valueA); $shellB = $shellA->withValue($valueB); self::assertNotSame($shellA, $shellB); self::assertSame($valueB, $shellB->value()); } public function test_root_shell_is_root(): void { $shell = Shell::root(new FakeType(), []); self::assertTrue($shell->isRoot()); self::assertSame('', $shell->name()); } public function test_get_root_shell_parent_throws_exception(): void { $this->expectException(CannotGetParentOfRootShell::class); $this->expectExceptionCode(1630674894); $this->expectExceptionMessage('Impossible to get the parent of a root shell.'); $shell = Shell::root(new FakeType(), []); $shell->parent(); } public function test_shell_child_values_can_be_retrieved(): void { $value = 'some value'; $type = FakeType::thatWillAccept($value); $attributes = new FakeAttributes(); $shell = Shell::root(new FakeType(), []); $child = $shell->child('foo', $type, $value, $attributes); self::assertSame('foo', $child->name()); self::assertSame('foo', $child->path()); self::assertSame($type, $child->type()); self::assertSame($value, $child->value()); self::assertSame($attributes, $child->attributes()); } }