Skip to content

Refactored to add missing inheritance check #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions spec/PHPCR/Shell/Console/Helper/NodeHelperSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace spec\PHPCR\Shell\Console\Helper;

use PHPCR\NodeInterface;
use PHPCR\NodeType\NodeTypeInterface;
use PhpSpec\ObjectBehavior;

class NodeHelperSpec extends ObjectBehavior
Expand All @@ -24,37 +23,19 @@ public function it_is_initializable()
}

public function it_should_provide_a_method_to_determine_if_a_node_has_a_given_mixin(
NodeInterface $node,
NodeTypeInterface $mixin1,
NodeTypeInterface $mixin2,
NodeTypeInterface $mixin3
NodeInterface $node
) {
$node->getMixinNodeTypes()->willReturn([
$mixin1, $mixin2, $mixin3,
]);

$mixin1->getName()->willReturn('mixin1');
$mixin2->getName()->willReturn('mixin1');
$mixin3->getName()->willReturn('mixin3');

$this->nodeHasMixinType($node, 'mixin1')->shouldReturn(true);
$this->nodeHasMixinType($node, 'mixin5')->shouldReturn(false);
$node->isNodeType('mixin1')->willReturn(true);
$node->isNodeType('mixin2')->willReturn(false);
}

public function it_should_provide_a_method_to_determine_if_a_node_is_versionable(
NodeInterface $nodeVersionable,
NodeInterface $nodeNotVersionable,
NodeTypeInterface $mixin1,
NodeTypeInterface $mixin2
NodeInterface $nodeNotVersionable
) {
$nodeVersionable->getMixinNodeTypes()->willReturn([
$mixin1, $mixin2,
]);
$nodeNotVersionable->getMixinNodeTypes()->willReturn([
$mixin2,
]);
$nodeNotVersionable->getPath()->willReturn('foobar');
$mixin1->getName()->willReturn('mix:versionable');
$nodeVersionable->isNodeType('mix:versionable')->willReturn(true);
$nodeNotVersionable->isNodeType('mix:versionable')->willReturn(false);
$this->assertNodeIsVersionable($nodeVersionable)->shouldReturn(null);

try {
Expand Down
10 changes: 1 addition & 9 deletions src/PHPCR/Shell/Console/Helper/NodeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@ class NodeHelper extends Helper
*/
public function nodeHasMixinType($node, $mixinTypeName)
{
$mixinTypes = $node->getMixinNodeTypes();

foreach ($mixinTypes as $mixinType) {
if ($mixinTypeName == $mixinType->getName()) {
return true;
}
}

return false;
return $node->isNodeType($mixinTypeName);
}

/**
Expand Down
8 changes: 1 addition & 7 deletions tests/PHPCR/Shell/Helper/NodeHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,8 @@ public function provideAssertNodeIsVersionable()
*/
public function testAssertNodeIsVersionable($isVersionable)
{
$this->node->getMixinNodeTypes()->willReturn([
$this->nodeType1->reveal(),
]);
$this->node->getPath()->willReturn('/');

$nodeTypeName = $isVersionable ? 'mix:versionable' : 'nt:foobar';

$this->nodeType1->getName()->willReturn($nodeTypeName);
$this->node->isNodeType('mix:versionable')->willReturn($isVersionable);

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