Skip to content

Commit 9d958ba

Browse files
authored
Merge pull request #187 from phpcr/php72
avoid `each` calls, test register single node type method
2 parents 10e9217 + ad15b65 commit 9d958ba

File tree

7 files changed

+59
-15
lines changed

7 files changed

+59
-15
lines changed

tests/NodeTypeDiscovery/NodeDefinitionTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ public function setUp()
7474
$defs = self::$file->getChildNodeDefinitions();
7575
$this->assertInternalType('array', $defs);
7676
$this->assertCount(1, $defs);
77-
list($key, $this->content) = each($defs);
77+
$this->content = current($defs);
7878
$this->assertInstanceOf(NodeDefinitionInterface::class, $this->content);
7979
$this->assertEquals('jcr:content', $this->content->getName());
8080

8181
$defs = self::$folder->getChildNodeDefinitions();
8282
$this->assertInternalType('array', $defs);
8383
$this->assertCount(1, $defs);
84-
list($key, $this->hierarchyNodeDef) = each($defs);
84+
$this->hierarchyNodeDef = next($defs);
8585
$this->assertInstanceOf(NodeDefinitionInterface::class, $this->hierarchyNodeDef);
8686
$this->assertEquals('*', $this->hierarchyNodeDef->getName());
8787
} catch (Exception $e) {

tests/NodeTypeDiscovery/NodeTypeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function testGetChildNodeDefinitions()
157157
$children = self::$file->getChildNodeDefinitions();
158158
$this->assertInternalType('array', $children);
159159
$this->assertCount(1, $children);
160-
list($key, $child) = each($children);
160+
$child = current($children);
161161
$this->assertInstanceOf(NodeDefinitionInterface::class, $child);
162162
$this->assertEquals('jcr:content', $child->getName());
163163
// the rest is tested in NodeDefinitionTest

tests/NodeTypeManagement/NodeTypeBaseCase.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ protected function assertTypes($types)
9898
$this->assertCount(2, $types, 'Wrong number of nodes registered');
9999

100100
// apitest
101-
list($name, $type) = each($types);
101+
$type = current($types);
102+
$name = key($types);
102103
$this->assertEquals('phpcr:apitest', $name);
103104
$this->assertInstanceOf(NodeTypeDefinitionInterface::class, $type);
104105
/* @var $type NodeTypeDefinitionInterface */
@@ -108,7 +109,8 @@ protected function assertTypes($types)
108109
$this->assertTrue($props[0]->isMultiple());
109110

110111
// test
111-
list($name, $type) = each($types);
112+
$type = next($types);
113+
$name = key($types);
112114
$this->assertEquals('phpcr:test', $name);
113115
$this->assertInstanceOf(NodeTypeDefinitionInterface::class, $type);
114116
/* @var $type NodeTypeDefinitionInterface */
@@ -164,8 +166,7 @@ public function testPrimaryItem()
164166
$root = $this->session->getRootNode();
165167

166168
if ($root->hasNode('test_node')) {
167-
$node = $root->getNode('test_node');
168-
$node->remove();
169+
$root->getNode('test_node')->remove();
169170
$this->session->save();
170171
}
171172

tests/NodeTypeManagement/NodeTypeTest.php

+40
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,53 @@
1111

1212
namespace PHPCR\Tests\NodeTypeManagement;
1313

14+
use PHPCR\NodeType\NodeTypeDefinitionInterface;
1415
use PHPCR\PropertyType;
1516

1617
/**
1718
* Covering jcr-2.8.3 spec $19.
1819
*/
1920
class NodeTypeTest extends NodeTypeBaseCase
2021
{
22+
public function testRegisterNodeType()
23+
{
24+
$ns = $this->workspace->getNamespaceRegistry();
25+
$ns->registerNamespace('phpcr', 'http://www.doctrine-project.org/projects/phpcr_odm');
26+
27+
$ntm = $this->workspace->getNodeTypeManager();
28+
29+
$apitest = $ntm->createNodeTypeTemplate();
30+
$apitest->setName('phpcr:apitest');
31+
$apitest->setMixin(true);
32+
33+
$class = $ntm->createPropertyDefinitionTemplate();
34+
$class->setName('phpcr:class');
35+
$class->setRequiredType(PropertyType::STRING);
36+
$class->setMultiple(true);
37+
$apitest->getPropertyDefinitionTemplates()->append($class);
38+
39+
$type = $ntm->registerNodeType($apitest, true);
40+
41+
$this->assertApitestType($type);
42+
43+
$session = $this->renewSession();
44+
$ntm = $session->getWorkspace()->getNodeTypeManager();
45+
46+
$this->assertTrue($ntm->hasNodeType('phpcr:apitest'));
47+
$this->assertApitestType($ntm->getNodeType('phpcr:apitest'));
48+
}
49+
50+
private function assertApitestType($type)
51+
{
52+
$this->assertInstanceOf(NodeTypeDefinitionInterface::class, $type);
53+
/* @var $type NodeTypeDefinitionInterface */
54+
$this->assertEquals('phpcr:apitest', $type->getName());
55+
$props = $type->getDeclaredPropertyDefinitions();
56+
$this->assertCount(1, $props, 'Wrong number of properties in phpcr:apitest');
57+
$this->assertEquals('phpcr:class', $props[0]->getName());
58+
$this->assertTrue($props[0]->isMultiple());
59+
}
60+
2161
protected function registerNodeTypes($allowUpdate)
2262
{
2363
$ns = $this->workspace->getNamespaceRegistry();

tests/PhpcrUtils/CndParserTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ protected function assertExampleCnd($res)
197197
// get first node type
198198
reset($res['nodeTypes']);
199199
/** @var $def NodeTypeDefinitionInterface */
200-
list($name, $def) = each($res['nodeTypes']);
200+
$def = current($res['nodeTypes']);
201+
$name = key($res['nodeTypes']);
201202

202203
$this->assertEquals('ns:NodeType', $name);
203204
$this->assertInstanceOf(NodeTypeTemplateInterface::class, $def);

tests/Reading/SessionReadMethodsTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ public function testGetNodesByIdentifier()
305305
]);
306306

307307
$this->assertCount(2, $nodes);
308-
list($key, $node) = each($nodes);
308+
$node = current($nodes);
309309
$this->assertInstanceOf(NodeInterface::class, $node);
310310
$this->assertEquals('/tests_general_base/idExample', $node->getPath());
311-
list($key, $node) = each($nodes);
311+
$node = next($nodes);
312312
$this->assertInstanceOf(NodeInterface::class, $node);
313313
$this->assertEquals('/tests_general_base/idExample/jcr:content/weakreference_target', $node->getPath());
314314
}
@@ -322,10 +322,10 @@ public function testGetNodesByIdentifierTraversable()
322322
]));
323323

324324
$this->assertCount(2, $nodes);
325-
list($key, $node) = each($nodes);
325+
$node = current($nodes);
326326
$this->assertInstanceOf(NodeInterface::class, $node);
327327
$this->assertEquals('/tests_general_base/idExample', $node->getPath());
328-
list($key, $node) = each($nodes);
328+
$node = next($nodes);
329329
$this->assertInstanceOf(NodeInterface::class, $node);
330330
$this->assertEquals('/tests_general_base/idExample/jcr:content/weakreference_target', $node->getPath());
331331
}

tests/SameNameSiblings/DeleteMethodsTest.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,12 @@ public function testDeleteManyNodes()
140140
$parent = $this->session->getNode($parentPath);
141141
$this->assertCount(count($childrenAtEnd), $parent->getNodes());
142142

143+
$childValue = -1;
143144
foreach ($parent->getNodes() as $node) {
144-
$child = each($childrenAtEnd);
145-
$this->assertEquals($parentPath.'/'.$child['key'], $node->getPath());
146-
$this->assertEquals($child['value'], $node->getProperty('childNumber')->getValue());
145+
$childValue = (-1 === $childValue) ? current($childrenAtEnd) : next($childrenAtEnd);
146+
$childKey = key($childrenAtEnd);
147+
$this->assertEquals($parentPath.'/'.$childKey, $node->getPath());
148+
$this->assertEquals($childValue, $node->getProperty('childNumber')->getValue());
147149
}
148150
}
149151

0 commit comments

Comments
 (0)