Skip to content

Commit 0a54685

Browse files
committed
Merge pull request #75 from dantleech/node-touch-fix
Fixed touch command
2 parents 2f586fb + 4a1475b commit 0a54685

File tree

4 files changed

+94
-17
lines changed

4 files changed

+94
-17
lines changed

src/PHPCR/Util/Console/Command/BaseCommand.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
abstract class BaseCommand extends Command
1212
{
13+
protected $phpcrCliHelper;
14+
1315
/**
1416
* @return PHPCR\SessionInterface
1517
*/
@@ -23,8 +25,19 @@ protected function getPhpcrSession()
2325
*/
2426
protected function getPhpcrCliHelper()
2527
{
26-
$phpcrCliHelper = new PhpcrCliHelper($this->getPhpcrSession());
27-
return $phpcrCliHelper;
28+
if (!$this->phpcrCliHelper) {
29+
$this->phpcrCliHelper = new PhpcrCliHelper($this->getPhpcrSession());
30+
}
31+
32+
return $this->phpcrCliHelper;
33+
}
34+
35+
/**
36+
* Hack to enable overriding for unit tests.
37+
*/
38+
public function setPhpcrCliHelper(PhpcrCliHelper $helper)
39+
{
40+
$this->phpcrCliHelper = $helper;
2841
}
2942

3043
public function configureNodeManipulationInput()

src/PHPCR/Util/Console/Command/NodeTouchCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
143143
}
144144

145145
$helper->processNode($output, $node, array(
146-
'setProps' => $setProp,
147-
'removeProps' => $removeProp,
146+
'setProp' => $setProp,
147+
'removeProp' => $removeProp,
148148
'addMixins' => $addMixins,
149149
'removeMixins' => $removeMixins,
150150
'dump' => $dump,

tests/PHPCR/Tests/Util/Console/Command/BaseCommandTest.php

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,35 @@
1818

1919
abstract class BaseCommandTest extends \PHPUnit_Framework_TestCase
2020
{
21-
/** @var SessionInterface|\PHPUnit_Framework_MockObject_MockObject */
22-
protected $session;
23-
/** @var WorkspaceInterface|\PHPUnit_Framework_MockObject_MockObject */
24-
protected $workspace;
25-
/** @var RepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
26-
protected $repository;
27-
/** @var PhpcrConsoleDumperHelper|\PHPUnit_Framework_MockObject_MockObject */
28-
protected $dumperHelper;
29-
/** @var HelperSet */
30-
protected $helperSet;
31-
/** @var Application */
32-
protected $application;
21+
/**
22+
* @var SessionInterface|\PHPUnit_Framework_MockObject_MockObject
23+
* */
24+
public $session;
25+
26+
/**
27+
* @var WorkspaceInterface|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
public $workspace;
30+
31+
/**
32+
* @var RepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
public $repository;
35+
36+
/**
37+
* @var PhpcrConsoleDumperHelper|\PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
public $dumperHelper;
40+
41+
/**
42+
* @var HelperSet
43+
*/
44+
public $helperSet;
45+
46+
/**
47+
* @var Application
48+
*/
49+
public $application;
3350

3451
public function setUp()
3552
{
@@ -50,6 +67,10 @@ public function setUp()
5067
'phpcr_console_dumper' => $this->dumperHelper,
5168
));
5269

70+
$this->phpcrCliHelper = $this->getMockBuilder('PHPCR\Util\Console\Helper\PhpcrCliHelper')
71+
->disableOriginalConstructor()
72+
->getMock();
73+
5374
$this->session->expects($this->any())
5475
->method('getWorkspace')
5576
->will($this->returnValue($this->workspace));

tests/PHPCR/Tests/Util/Console/Command/NodeTouchCommandTest.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ class NodeTouchCommandTest extends BaseCommandTest
1313
public function setUp()
1414
{
1515
parent::setUp();
16-
$this->application->add(new NodeTouchCommand());
16+
$this->command = new NodeTouchCommand;
17+
18+
// override default concrete instance with mock
19+
$this->command->setPhpcrCliHelper($this->phpcrCliHelper);
20+
$this->application->add($this->command);
1721
$this->nodeType = $this->getMock('PHPCR\NodeType\NodeTypeInterface');
1822
}
1923

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

45+
46+
$ct = $this->executeCommand('phpcr:node:touch', array(
47+
'path' => '/cms',
48+
));
49+
}
50+
51+
public function testUpdate()
52+
{
53+
$this->session->expects($this->exactly(1))
54+
->method('getNode')
55+
->with('/cms')
56+
->will($this->returnValue($this->node1));
57+
$this->node1->expects($this->once())
58+
->method('getPrimaryNodeType')
59+
->will($this->returnValue($this->nodeType));
60+
$this->nodeType->expects($this->once())
61+
->method('getName')
62+
->will($this->returnValue('nt:unstructured'));
63+
64+
65+
$me = $this;
66+
$this->phpcrCliHelper->expects($this->once())
67+
->method('processNode')
68+
->will($this->returnCallback(function ($output, $node, $options) use ($me) {
69+
$me->assertEquals($me->node1, $node);
70+
$me->assertEquals(array(
71+
'setProp' => array('foo=bar'),
72+
'removeProp' => array('bar'),
73+
'addMixins' => array('foo:bar'),
74+
'removeMixins' => array('bar:foo'),
75+
'dump' => true,
76+
), $options);
77+
}));
78+
4179
$ct = $this->executeCommand('phpcr:node:touch', array(
4280
'path' => '/cms',
81+
'--set-prop' => array('foo=bar'),
82+
'--remove-prop' => array('bar'),
83+
'--add-mixin' => array('foo:bar'),
84+
'--remove-mixin' => array('bar:foo'),
85+
'--dump' => true,
4386
));
4487
}
4588
}

0 commit comments

Comments
 (0)