Skip to content

Commit 39b38dc

Browse files
committed
Merge remote-tracking branch 'origin/master' into clean-dump-command
Conflicts: tests/PHPCR/Tests/Util/Console/Command/BaseCommandTest.php
2 parents ec645f5 + 0a54685 commit 39b38dc

File tree

4 files changed

+106
-20
lines changed

4 files changed

+106
-20
lines changed

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

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

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

3144
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: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,50 @@
2121

2222
abstract class BaseCommandTest extends \PHPUnit_Framework_TestCase
2323
{
24-
/** @var SessionInterface|\PHPUnit_Framework_MockObject_MockObject */
25-
protected $session;
26-
/** @var WorkspaceInterface|\PHPUnit_Framework_MockObject_MockObject */
27-
protected $workspace;
28-
/** @var RepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
29-
protected $repository;
30-
/** @var NodeInterface|\PHPUnit_Framework_MockObject_MockObject */
24+
/**
25+
* @var SessionInterface|\PHPUnit_Framework_MockObject_MockObject
26+
* */
27+
public $session;
28+
29+
/**
30+
* @var WorkspaceInterface|\PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
public $workspace;
33+
34+
/**
35+
* @var RepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
public $repository;
38+
39+
/**
40+
* @var PhpcrConsoleDumperHelper|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
public $dumperHelper;
43+
44+
/**
45+
* @var NodeInterface|\PHPUnit_Framework_MockObject_MockObject
46+
*/
3147
protected $node1;
32-
/** @var RowInterface|\PHPUnit_Framework_MockObject_MockObject */
48+
49+
/**
50+
* @var RowInterface|\PHPUnit_Framework_MockObject_MockObject
51+
*/
3352
protected $row1;
34-
/** @var QueryManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
53+
54+
/**
55+
* @var QueryManagerInterface|\PHPUnit_Framework_MockObject_MockObject
56+
*/
3557
protected $queryManager;
36-
/** @var PhpcrConsoleDumperHelper|\PHPUnit_Framework_MockObject_MockObject */
37-
protected $dumperHelper;
38-
/** @var HelperSet */
39-
protected $helperSet;
40-
/** @var Application */
41-
protected $application;
58+
59+
/**
60+
* @var HelperSet
61+
*/
62+
public $helperSet;
63+
64+
/**
65+
* @var Application
66+
*/
67+
public $application;
4268

4369
public function setUp()
4470
{
@@ -59,6 +85,10 @@ public function setUp()
5985
'phpcr_console_dumper' => $this->dumperHelper,
6086
));
6187

88+
$this->phpcrCliHelper = $this->getMockBuilder('PHPCR\Util\Console\Helper\PhpcrCliHelper')
89+
->disableOriginalConstructor()
90+
->getMock();
91+
6292
$this->session->expects($this->any())
6393
->method('getWorkspace')
6494
->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)