1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace StefanoTreeTest\Integration\Adapter; |
6
|
|
|
|
7
|
|
|
use StefanoTree\NestedSet\Adapter\AdapterInterface as TreeAdapterInterface; |
8
|
|
|
use StefanoTree\NestedSet\NodeInfo; |
9
|
|
|
use StefanoTreeTest\IntegrationTestCase; |
10
|
|
|
|
11
|
|
|
abstract class AdapterWithScopeTestAbstract extends IntegrationTestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var TreeAdapterInterface |
15
|
|
|
*/ |
16
|
|
|
protected $adapter; |
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$this->adapter = $this->getAdapter(); |
21
|
|
|
|
22
|
|
|
parent::setUp(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function tearDown() |
26
|
|
|
{ |
27
|
|
|
$this->adapter = null; |
28
|
|
|
parent::tearDown(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return TreeAdapterInterface |
33
|
|
|
*/ |
34
|
|
|
abstract protected function getAdapter(); |
35
|
|
|
|
36
|
|
|
protected function getDataSet() |
37
|
|
|
{ |
38
|
|
|
return $this->createMySQLXMLDataSet(__DIR__.'/_files/adapter/with_scope/initDataSet.xml'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testUpdateDataDoesNotChangeMetadata() |
42
|
|
|
{ |
43
|
|
|
$data = array( |
44
|
|
|
'name' => 'changed', |
45
|
|
|
'lft' => 'a', |
46
|
|
|
'rgt' => 'b', |
47
|
|
|
'parent_id' => 'c', |
48
|
|
|
'level' => 'd', |
49
|
|
|
'scope' => 'e', |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$this->adapter |
53
|
|
|
->update(2, $data); |
54
|
|
|
|
55
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testUpdateData.xml'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testInsertDataDoesNotChangeMetadata() |
59
|
|
|
{ |
60
|
|
|
$nodeInfo = new NodeInfo(null, 6, 1001, 1002, 1003, 1004); |
61
|
|
|
|
62
|
|
|
$data = array( |
63
|
|
|
'name' => 'some-name', |
64
|
|
|
'lft' => 'a', |
65
|
|
|
'rgt' => 'b', |
66
|
|
|
'parent_id' => 'c', |
67
|
|
|
'level' => 'd', |
68
|
|
|
'scope' => 'e', |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$this->adapter |
72
|
|
|
->insert($nodeInfo, $data); |
73
|
|
|
|
74
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testInsertData.xml'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testDeleteBranch() |
78
|
|
|
{ |
79
|
|
|
$this->adapter |
80
|
|
|
->delete(2); |
81
|
|
|
|
82
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testDeleteBranch.xml'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testMoveLeftIndexes() |
86
|
|
|
{ |
87
|
|
|
$this->adapter |
88
|
|
|
->moveLeftIndexes(3, 500, 2); |
89
|
|
|
|
90
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testMoveLeftIndexes.xml'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testMoveRightIndexes() |
94
|
|
|
{ |
95
|
|
|
$this->adapter |
96
|
|
|
->moveRightIndexes(4, 500, 2); |
97
|
|
|
|
98
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testMoveRightIndexes.xml'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testUpdateLevels() |
102
|
|
|
{ |
103
|
|
|
$this->adapter |
104
|
|
|
->updateLevels(2, 9, 500, 2); |
105
|
|
|
|
106
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testUpdateLevels.xml'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function testMoveBranch() |
110
|
|
|
{ |
111
|
|
|
$this->adapter |
112
|
|
|
->moveBranch(2, 9, 500, 2); |
113
|
|
|
|
114
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testMoveBranch.xml'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testGetRoots() |
118
|
|
|
{ |
119
|
|
|
$roots = $this->adapter |
120
|
|
|
->getRoots(); |
121
|
|
|
|
122
|
|
|
$expected = include __DIR__.'/_files/adapter/with_scope/testGetRoots.php'; |
123
|
|
|
$this->assertEquals($expected, $roots); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function testGetRoot() |
127
|
|
|
{ |
128
|
|
|
$roots = $this->adapter |
129
|
|
|
->getRoot(2); |
130
|
|
|
|
131
|
|
|
$expected = include __DIR__.'/_files/adapter/with_scope/testGetRoot.php'; |
132
|
|
|
$this->assertEquals($expected, $roots); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testGetNodeInfo() |
136
|
|
|
{ |
137
|
|
|
$nodeInfo = $this->adapter |
138
|
|
|
->getNodeInfo(8); |
139
|
|
|
|
140
|
|
|
$this->assertEquals($nodeInfo->getId(), 8); |
141
|
|
|
$this->assertEquals($nodeInfo->getParentId(), 7); |
142
|
|
|
$this->assertEquals($nodeInfo->getLeft(), 3); |
143
|
|
|
$this->assertEquals($nodeInfo->getRight(), 8); |
144
|
|
|
$this->assertEquals($nodeInfo->getLevel(), 2); |
145
|
|
|
$this->assertEquals($nodeInfo->getScope(), 1); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function testGetChildrenNodeInfo() |
149
|
|
|
{ |
150
|
|
|
$nodeInfo = $this->adapter |
151
|
|
|
->getChildrenNodeInfo(2); |
152
|
|
|
|
153
|
|
|
$this->assertCount(3, $nodeInfo); |
|
|
|
|
154
|
|
|
|
155
|
|
|
// check first node info |
156
|
|
|
$this->assertEquals($nodeInfo[0]->getId(), 3); |
157
|
|
|
$this->assertEquals($nodeInfo[0]->getParentId(), 2); |
158
|
|
|
$this->assertEquals($nodeInfo[0]->getLeft(), 3); |
159
|
|
|
$this->assertEquals($nodeInfo[0]->getRight(), 4); |
160
|
|
|
$this->assertEquals($nodeInfo[0]->getLevel(), 2); |
161
|
|
|
|
162
|
|
|
// check last node info |
163
|
|
|
$this->assertEquals($nodeInfo[2]->getId(), 5); |
164
|
|
|
$this->assertEquals($nodeInfo[2]->getParentId(), 2); |
165
|
|
|
$this->assertEquals($nodeInfo[2]->getLeft(), 7); |
166
|
|
|
$this->assertEquals($nodeInfo[2]->getRight(), 8); |
167
|
|
|
$this->assertEquals($nodeInfo[2]->getLevel(), 2); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function testUpdateNodeMetadata() |
171
|
|
|
{ |
172
|
|
|
$nodeInfo = new NodeInfo(3, 1000, 1001, 1002, 1003, 2); |
173
|
|
|
|
174
|
|
|
$this->adapter |
175
|
|
|
->updateNodeMetadata($nodeInfo); |
176
|
|
|
|
177
|
|
|
$this->assertCompareDataSet(array('tree_traversal_with_scope'), __DIR__.'/_files/adapter/with_scope/testUpdateNodeMetadata.xml'); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function testGetPath() |
181
|
|
|
{ |
182
|
|
|
$path = $this->adapter |
183
|
|
|
->getAncestors(5); |
184
|
|
|
|
185
|
|
|
$this->assertCount(3, $path); |
|
|
|
|
186
|
|
|
|
187
|
|
|
$expected = include __DIR__.'/_files/adapter/with_scope/testGetPath.php'; |
188
|
|
|
$this->assertEquals($expected, $path); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function testGetDescendants() |
192
|
|
|
{ |
193
|
|
|
$nodes = $this->adapter |
194
|
|
|
->getDescendants(1); |
195
|
|
|
|
196
|
|
|
$this->assertCount(5, $nodes); |
|
|
|
|
197
|
|
|
|
198
|
|
|
$expected = include __DIR__.'/_files/adapter/with_scope/testGetDescendants.php'; |
199
|
|
|
$this->assertEquals($expected, $nodes); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: