Skip to content

Commit f8daa3e

Browse files
middlebraindbu
authored andcommitted
Refactored to add missing inheritance check (#191)
Let PHPCR handle the node type checking including inheritance.
1 parent c496d93 commit f8daa3e

File tree

3 files changed

+8
-41
lines changed

3 files changed

+8
-41
lines changed

spec/PHPCR/Shell/Console/Helper/NodeHelperSpec.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
namespace spec\PHPCR\Shell\Console\Helper;
1414

1515
use PHPCR\NodeInterface;
16-
use PHPCR\NodeType\NodeTypeInterface;
1716
use PhpSpec\ObjectBehavior;
1817

1918
class NodeHelperSpec extends ObjectBehavior
@@ -24,37 +23,19 @@ public function it_is_initializable()
2423
}
2524

2625
public function it_should_provide_a_method_to_determine_if_a_node_has_a_given_mixin(
27-
NodeInterface $node,
28-
NodeTypeInterface $mixin1,
29-
NodeTypeInterface $mixin2,
30-
NodeTypeInterface $mixin3
26+
NodeInterface $node
3127
) {
32-
$node->getMixinNodeTypes()->willReturn([
33-
$mixin1, $mixin2, $mixin3,
34-
]);
35-
36-
$mixin1->getName()->willReturn('mixin1');
37-
$mixin2->getName()->willReturn('mixin1');
38-
$mixin3->getName()->willReturn('mixin3');
39-
40-
$this->nodeHasMixinType($node, 'mixin1')->shouldReturn(true);
41-
$this->nodeHasMixinType($node, 'mixin5')->shouldReturn(false);
28+
$node->isNodeType('mixin1')->willReturn(true);
29+
$node->isNodeType('mixin2')->willReturn(false);
4230
}
4331

4432
public function it_should_provide_a_method_to_determine_if_a_node_is_versionable(
4533
NodeInterface $nodeVersionable,
46-
NodeInterface $nodeNotVersionable,
47-
NodeTypeInterface $mixin1,
48-
NodeTypeInterface $mixin2
34+
NodeInterface $nodeNotVersionable
4935
) {
50-
$nodeVersionable->getMixinNodeTypes()->willReturn([
51-
$mixin1, $mixin2,
52-
]);
53-
$nodeNotVersionable->getMixinNodeTypes()->willReturn([
54-
$mixin2,
55-
]);
5636
$nodeNotVersionable->getPath()->willReturn('foobar');
57-
$mixin1->getName()->willReturn('mix:versionable');
37+
$nodeVersionable->isNodeType('mix:versionable')->willReturn(true);
38+
$nodeNotVersionable->isNodeType('mix:versionable')->willReturn(false);
5839
$this->assertNodeIsVersionable($nodeVersionable)->shouldReturn(null);
5940

6041
try {

src/PHPCR/Shell/Console/Helper/NodeHelper.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,7 @@ class NodeHelper extends Helper
2929
*/
3030
public function nodeHasMixinType($node, $mixinTypeName)
3131
{
32-
$mixinTypes = $node->getMixinNodeTypes();
33-
34-
foreach ($mixinTypes as $mixinType) {
35-
if ($mixinTypeName == $mixinType->getName()) {
36-
return true;
37-
}
38-
}
39-
40-
return false;
32+
return $node->isNodeType($mixinTypeName);
4133
}
4234

4335
/**

tests/PHPCR/Shell/Helper/NodeHelperTest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,8 @@ public function provideAssertNodeIsVersionable()
4040
*/
4141
public function testAssertNodeIsVersionable($isVersionable)
4242
{
43-
$this->node->getMixinNodeTypes()->willReturn([
44-
$this->nodeType1->reveal(),
45-
]);
4643
$this->node->getPath()->willReturn('/');
47-
48-
$nodeTypeName = $isVersionable ? 'mix:versionable' : 'nt:foobar';
49-
50-
$this->nodeType1->getName()->willReturn($nodeTypeName);
44+
$this->node->isNodeType('mix:versionable')->willReturn($isVersionable);
5145

5246
if (false == $isVersionable) {
5347
$this->setExpectedException('\OutOfBoundsException', 'is not versionable');

0 commit comments

Comments
 (0)