Skip to content

Commit 0ea38a1

Browse files
committed
Added remaining tests
1 parent af9eaba commit 0ea38a1

16 files changed

+196
-70
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ protected function configure()
6767
protected function execute(InputInterface $input, OutputInterface $output)
6868
{
6969
$session = $this->getHelper('phpcr')->getSession();
70+
$repo = $session->getRepository();
7071

71-
if (!$session->getRepository()->getDescriptor(RepositoryInterface::OPTION_XML_EXPORT_SUPPORTED)) {
72+
if (!$repo->getDescriptor(RepositoryInterface::OPTION_XML_EXPORT_SUPPORTED)) {
7273
$output->writeln('<error>This repository does not support xml export</error>');
7374

7475
return 1;

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,22 @@ protected function configure()
6767
*/
6868
protected function execute(InputInterface $input, OutputInterface $output)
6969
{
70-
/** @var $session \PHPCR\SessionInterface */
70+
$filename = $input->getArgument('filename');
71+
$parentPath = $input->getOption('parentpath');
7172
$session = $this->getHelper('phpcr')->getSession();
72-
if (! $session->getRepository()->getDescriptor(RepositoryInterface::OPTION_XML_IMPORT_SUPPORTED)) {
73+
$repo = $session->getRepository();
74+
75+
if (!$repo->getDescriptor(RepositoryInterface::OPTION_XML_IMPORT_SUPPORTED)) {
7376
$output->writeln('<error>This repository does not support xml import</error>');
7477

7578
return 1;
7679
}
7780

78-
$parentpath = $input->getOption('parentpath');
79-
$session->importXml($parentpath, $input->getArgument('filename'), ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW);
81+
$session->importXml(
82+
$parentPath,
83+
$filename,
84+
ImportUUIDBehaviorInterface::IMPORT_UUID_CREATE_NEW
85+
);
8086
$session->save();
8187

8288
return 0;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
8383
}
8484

8585
$output->writeln(sprintf('<info>Purging workspace:</info> %s', $workspaceName));
86+
87+
// Note that this is bad for testing purposes, we HAVE to
88+
// use the concrete implementation of NodeHelper and mocking it
89+
// is spreading behvioral dependencies. Even if we move it to
90+
// the CommandHelper class, we need to test that class and have
91+
// the same problem again.
8692
NodeHelper::purgeWorkspace($session);
8793
$session->save();
8894

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,26 @@ protected function configure()
5757
protected function execute(InputInterface $input, OutputInterface $output)
5858
{
5959
$sql = $input->getArgument('query');
60-
61-
$session = $this->getHelper('phpcr')->getSession();
62-
$qm = $session->getWorkspace()->getQueryManager();
6360
$language = strtoupper($input->getOption('language'));
6461
$limit = $input->getOption('limit');
6562
$offset = $input->getOption('offset');
63+
64+
$session = $this->getHelper('phpcr')->getSession();
65+
$qm = $session->getWorkspace()->getQueryManager();
66+
6667
if (!defined('\PHPCR\Query\QueryInterface::'.$language)) {
67-
throw new \RuntimeException("Query language '\\PHPCR\\Query\\QueryInterface::$language' not defined.");
68+
throw new \RuntimeException(sprintf(
69+
"Query language '\\PHPCR\\Query\\QueryInterface::%s' not defined.",
70+
$language
71+
));
6872
}
6973

7074
$query = $qm->createQuery($sql, constant('\PHPCR\Query\QueryInterface::'.$language));
75+
7176
if ($limit) {
7277
$query->setLimit($limit);
7378
}
79+
7480
if ($offset) {
7581
$query->setOffset($offset);
7682
}

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

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,22 @@ abstract class BaseCommandTest extends \PHPUnit_Framework_TestCase
1313
public function setUp()
1414
{
1515
$this->session = $this->getMock('PHPCR\SessionInterface');
16-
$this->dumperHelper = $this->getMockBuilder('PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper')
16+
$this->workspace = $this->getMock('PHPCR\WorkspaceInterface');
17+
$this->repository = $this->getMock('PHPCR\RepositoryInterface');
18+
19+
$this->node1 = $this->getMockBuilder('Jackalope\Node')
1720
->disableOriginalConstructor()
1821
->getMock();
22+
23+
$this->dumperHelper = $this->getMockBuilder(
24+
'PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper'
25+
)->disableOriginalConstructor()->getMock();
26+
1927
$this->helperSet = new HelperSet(array(
2028
'session' => new PhpcrHelper($this->session),
2129
'phpcr_console_dumper' => $this->dumperHelper,
2230
));
2331

24-
$this->application = new Application();
25-
$this->application->setHelperSet($this->helperSet);
26-
27-
for ($i = 1; $i <= 3; $i++) {
28-
$varName = 'node'.$i;
29-
$this->$varName = $this->getMockBuilder('Jackalope\Node')
30-
->disableOriginalConstructor()
31-
->getMock();
32-
if ($i > 1) {
33-
$this->$varName->expects($this->any())
34-
->method('getNodes')
35-
->will($this->returnValue(array()));
36-
}
37-
}
38-
39-
$this->workspace = $this->getMock('PHPCR\WorkspaceInterface');
40-
4132
$this->session->expects($this->any())
4233
->method('getWorkspace')
4334
->will($this->returnValue($this->workspace));
@@ -46,7 +37,8 @@ public function setUp()
4637
->method('getName')
4738
->will($this->returnValue('test'));
4839

49-
$this->repository = $this->getMock('PHPCR\RepositoryInterface');
40+
$this->application = new Application();
41+
$this->application->setHelperSet($this->helperSet);
5042
}
5143

5244
public function executeCommand($name, $args)

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ public function testCommand()
2323
$this->session->expects($this->once())
2424
->method('getNode')
2525
->will($this->returnValue($this->node1));
26-
$this->node1->expects($this->any())
27-
->method('getNodes')
28-
->will($this->returnValue(array(
29-
$this->node1,
30-
$this->node2,
31-
)));
3226

3327
$this->application->add(new NodeDumpCommand());
3428

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ public function setUp()
1919

2020
public function testTouch()
2121
{
22-
$test = $this;
22+
$node = $this->node1;
23+
2324
$this->session->expects($this->exactly(2))
2425
->method('getNode')
25-
->will($this->returnCallback(function ($path) use ($test) {
26+
->will($this->returnCallback(function ($path) use ($node) {
2627
switch ($path) {
2728
case '/':
28-
return $this->node1;
29+
return $node;
2930
case '/cms':
3031
return null;
3132
}
@@ -42,4 +43,3 @@ public function testTouch()
4243
));
4344
}
4445
}
45-

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,3 @@ public function testNodeTypeList()
3131
));
3232
}
3333
}
34-
35-

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,3 @@ public function testNodeTypeList()
3232
));
3333
}
3434
}
35-
36-
37-

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,3 @@ public function testNodeTypeList()
3535
));
3636
}
3737
}
38-
39-
40-
41-

0 commit comments

Comments
 (0)