Skip to content

Fixed touch command #75

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 1 commit into from
Jun 28, 2013
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
17 changes: 15 additions & 2 deletions src/PHPCR/Util/Console/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

abstract class BaseCommand extends Command
{
protected $phpcrCliHelper;

/**
* @return PHPCR\SessionInterface
*/
Expand All @@ -23,8 +25,19 @@ protected function getPhpcrSession()
*/
protected function getPhpcrCliHelper()
{
$phpcrCliHelper = new PhpcrCliHelper($this->getPhpcrSession());
return $phpcrCliHelper;
if (!$this->phpcrCliHelper) {
$this->phpcrCliHelper = new PhpcrCliHelper($this->getPhpcrSession());
}

return $this->phpcrCliHelper;
}

/**
* Hack to enable overriding for unit tests.
*/
public function setPhpcrCliHelper(PhpcrCliHelper $helper)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should really refactor the helper logic and get them working with both DoctrinePhpcrBundle and phpcr-utils vanilla.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 - not in this PR but i really would want to fix that stuff up, its quite a mess atm. see #74

{
$this->phpcrCliHelper = $helper;
}

public function configureNodeManipulationInput()
Expand Down
4 changes: 2 additions & 2 deletions src/PHPCR/Util/Console/Command/NodeTouchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$helper->processNode($output, $node, array(
'setProps' => $setProp,
'removeProps' => $removeProp,
'setProp' => $setProp,
'removeProp' => $removeProp,
'addMixins' => $addMixins,
'removeMixins' => $removeMixins,
'dump' => $dump,
Expand Down
45 changes: 33 additions & 12 deletions tests/PHPCR/Tests/Util/Console/Command/BaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,35 @@

abstract class BaseCommandTest extends \PHPUnit_Framework_TestCase
{
/** @var SessionInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $session;
/** @var WorkspaceInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $workspace;
/** @var RepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $repository;
/** @var PhpcrConsoleDumperHelper|\PHPUnit_Framework_MockObject_MockObject */
protected $dumperHelper;
/** @var HelperSet */
protected $helperSet;
/** @var Application */
protected $application;
/**
* @var SessionInterface|\PHPUnit_Framework_MockObject_MockObject
* */
public $session;

/**
* @var WorkspaceInterface|\PHPUnit_Framework_MockObject_MockObject
*/
public $workspace;

/**
* @var RepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
public $repository;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbu changed the annotations to be in proper CS - hope thats ok.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that is correct. its just tests, otherwise i would say those should be protected and not public.


/**
* @var PhpcrConsoleDumperHelper|\PHPUnit_Framework_MockObject_MockObject
*/
public $dumperHelper;

/**
* @var HelperSet
*/
public $helperSet;

/**
* @var Application
*/
public $application;

public function setUp()
{
Expand All @@ -50,6 +67,10 @@ public function setUp()
'phpcr_console_dumper' => $this->dumperHelper,
));

$this->phpcrCliHelper = $this->getMockBuilder('PHPCR\Util\Console\Helper\PhpcrCliHelper')
->disableOriginalConstructor()
->getMock();

$this->session->expects($this->any())
->method('getWorkspace')
->will($this->returnValue($this->workspace));
Expand Down
45 changes: 44 additions & 1 deletion tests/PHPCR/Tests/Util/Console/Command/NodeTouchCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class NodeTouchCommandTest extends BaseCommandTest
public function setUp()
{
parent::setUp();
$this->application->add(new NodeTouchCommand());
$this->command = new NodeTouchCommand;

// override default concrete instance with mock
$this->command->setPhpcrCliHelper($this->phpcrCliHelper);
$this->application->add($this->command);
$this->nodeType = $this->getMock('PHPCR\NodeType\NodeTypeInterface');
}

Expand All @@ -38,8 +42,47 @@ public function testTouch()
$this->session->expects($this->once())
->method('save');


$ct = $this->executeCommand('phpcr:node:touch', array(
'path' => '/cms',
));
}

public function testUpdate()
{
$this->session->expects($this->exactly(1))
->method('getNode')
->with('/cms')
->will($this->returnValue($this->node1));
$this->node1->expects($this->once())
->method('getPrimaryNodeType')
->will($this->returnValue($this->nodeType));
$this->nodeType->expects($this->once())
->method('getName')
->will($this->returnValue('nt:unstructured'));


$me = $this;
$this->phpcrCliHelper->expects($this->once())
->method('processNode')
->will($this->returnCallback(function ($output, $node, $options) use ($me) {
$me->assertEquals($me->node1, $node);
$me->assertEquals(array(
'setProp' => array('foo=bar'),
'removeProp' => array('bar'),
'addMixins' => array('foo:bar'),
'removeMixins' => array('bar:foo'),
'dump' => true,
), $options);
}));

$ct = $this->executeCommand('phpcr:node:touch', array(
'path' => '/cms',
'--set-prop' => array('foo=bar'),
'--remove-prop' => array('bar'),
'--add-mixin' => array('foo:bar'),
'--remove-mixin' => array('bar:foo'),
'--dump' => true,
));
}
}