3declare(strict_types=1);
24require_once(__DIR__ .
"/../../../../../libs/composer/vendor/autoload.php");
46 foreach (
$data[$node_id] as $subnode_id) {
47 $subnodes[] = $this->
build($data, $subnode_id);
49 return (
new NodeMock($node_id))->setSubnodes($subnodes);
55 'top' => [
'1.2',
'1.1'],
57 '1.2' => [
'1.2.1',
'1.2.2'],
58 '1.2.1' => [
'1.2.1.1'],
69 $this->assertEquals($n->getId(),
'top');
70 $this->assertInstanceOf(Node::class, $n->getSubnode(
'1.1'));
73 [
'top',
'1.2',
'1.2.2'],
74 $n->getSubnode(
'1.2')->getSubnode(
'1.2.2')->getPath()
78 [
'top',
'1.2',
'1.2.1'],
79 $n->findSubnodePath(
'1.2.1')
85 $zipper =
new Zipper($this->topnode);
86 $this->assertInstanceOf(Zipper::class, $zipper->toChild(
'1.1'));
87 $this->assertInstanceOf(
89 $zipper->toPath($this->topnode->findSubnodePath(
'1.2.1'))->toParent()
91 $this->assertInstanceOf(
93 $zipper->toPath($this->topnode->findSubnodePath(
'1.2.1'))->getRoot()
99 $zipper =
new Zipper($this->topnode);
101 $path = $this->topnode->findSubnodePath(
'1.2.1');
103 ->toPath(
$path)->modifyFocus(fn ($n) => $n->withScore(7))
104 ->toParent()->modifyFocus(fn ($n) => $n->withScore(6))
107 $zipper =
new Zipper($modified);
108 $other_path = $this->topnode->findSubnodePath(
'1.1');
110 ->toPath($other_path)->modifyFocus(fn ($n) => $n->withScore(8))
112 $this->assertEquals(7, $modified->getSubnode(
'1.2')->getSubnode(
'1.2.1')->getScore());
113 $this->assertEquals(6, $modified->getSubnode(
'1.2')->getScore());
114 $this->assertEquals(8, $modified->getSubnode(
'1.1')->getScore());
117 $zipper =
new Zipper($modified);
119 ->toPath(
$path)->modifyFocus(fn ($n) => $n->withScore(17))
121 $this->assertEquals(17, $modified->getSubnode(
'1.2')->getSubnode(
'1.2.1')->getScore());
122 $this->assertEquals(6, $modified->getSubnode(
'1.2')->getScore());
123 $this->assertEquals(8, $modified->getSubnode(
'1.1')->getScore());
128 $zipper =
new Zipper($this->topnode);
130 ->modifyAll(fn ($n) => $n->withScore(count($n->getSubnodes())))
133 $this->assertEquals(2, $modified->getScore());
134 $this->assertEquals(0, $modified->getSubnode(
'1.1')->getScore());
135 $this->assertEquals(2, $modified->getSubnode(
'1.2')->getScore());
136 $this->assertEquals(1, $modified->getSubnode(
'1.2')->getSubnode(
'1.2.1')->getScore());
137 $this->assertEquals(0, $modified->getSubnode(
'1.2')->getSubnode(
'1.2.1')->getSubnode(
'1.2.1.1')->getScore());
138 $this->assertEquals(0, $modified->getSubnode(
'1.2')->getSubnode(
'1.2.2')->getScore());
build(array $data, $node_id)
testPGSTreeZipperManipulation()
testPGSTreeZipperManipulateAll()