Skip to content

Commit af9eaba

Browse files
committed
Added more tests
1 parent 3208e71 commit af9eaba

File tree

5 files changed

+90
-4
lines changed

5 files changed

+90
-4
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\Console\Input\InputArgument;
2626
use Symfony\Component\Console\Input\InputInterface;
2727
use Symfony\Component\Console\Output\OutputInterface;
28+
use PHPCR\RepositoryInterface;
2829

2930
/**
3031
* A command to create a workspace in the PHPCR repository
@@ -62,9 +63,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
6263
$name = $input->getArgument('name');
6364

6465
$workspace = $session->getWorkspace();
66+
$repo = $session->getRepository();
6567

66-
if (! $session->getRepository()->getDescriptor(\PHPCR\RepositoryInterface::OPTION_WORKSPACE_MANAGEMENT_SUPPORTED)) {
67-
$output->writeln('<error>Your PHPCR implementation does not support workspace management. Please refer to the documentation of your PHPCR implementation to learn how to create a workspace.</error>');
68+
if (!$repo->getDescriptor(RepositoryInterface::OPTION_WORKSPACE_MANAGEMENT_SUPPORTED)) {
69+
$output->writeln(
70+
'<error>Your PHPCR implementation does not support '.
71+
'workspace management. Please refer to the documentation '.
72+
'of your PHPCR implementation to learn how to create a workspace.</error>'
73+
);
6874

6975
return 1;
7076
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ protected function configure()
6666
*/
6767
protected function execute(InputInterface $input, OutputInterface $output)
6868
{
69-
/** @var $session \PHPCR\SessionInterface */
7069
$session = $this->getHelper('phpcr')->getSession();
71-
if (! $session->getRepository()->getDescriptor(RepositoryInterface::OPTION_XML_EXPORT_SUPPORTED)) {
70+
71+
if (!$session->getRepository()->getDescriptor(RepositoryInterface::OPTION_XML_EXPORT_SUPPORTED)) {
7272
$output->writeln('<error>This repository does not support xml export</error>');
7373

7474
return 1;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public function setUp()
4545
$this->workspace->expects($this->any())
4646
->method('getName')
4747
->will($this->returnValue('test'));
48+
49+
$this->repository = $this->getMock('PHPCR\RepositoryInterface');
4850
}
4951

5052
public function executeCommand($name, $args)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace PHPCR\Tests\Util\Console\Command;
4+
5+
use Symfony\Component\Console\Application;
6+
use PHPCR\Util\Console\Command\WorkspaceCreateCommand;
7+
use PHPCR\RepositoryInterface;
8+
9+
class WorkspaceCreateCommandTest extends BaseCommandTest
10+
{
11+
public function setUp()
12+
{
13+
parent::setUp();
14+
$this->application->add(new WorkspaceCreateCommand());
15+
}
16+
17+
public function testNodeTypeList()
18+
{
19+
$this->session->expects($this->once())
20+
->method('getWorkspace')
21+
->will($this->returnValue($this->workspace));
22+
$this->workspace->expects($this->once())
23+
->method('createWorkspace')
24+
->with('test_workspace');
25+
$this->session->expects($this->once())
26+
->method('getRepository')
27+
->will($this->returnValue($this->repository));
28+
$this->repository->expects($this->once())
29+
->method('getDescriptor')
30+
->with(RepositoryInterface::OPTION_WORKSPACE_MANAGEMENT_SUPPORTED)
31+
->will($this->returnValue(true));
32+
33+
$ct = $this->executeCommand('phpcr:workspace:create', array(
34+
'name' => 'test_workspace'
35+
));
36+
}
37+
}
38+
39+
40+
41+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace PHPCR\Tests\Util\Console\Command;
4+
5+
use Symfony\Component\Console\Application;
6+
use PHPCR\Util\Console\Command\WorkspaceExportCommand;
7+
use PHPCR\RepositoryInterface;
8+
9+
class WorkspaceExportCommandTest extends BaseCommandTest
10+
{
11+
public function setUp()
12+
{
13+
parent::setUp();
14+
$this->application->add(new WorkspaceExportCommand());
15+
}
16+
17+
public function testNodeTypeList()
18+
{
19+
$this->session->expects($this->once())
20+
->method('getRepository')
21+
->will($this->returnValue($this->repository));
22+
$this->repository->expects($this->once())
23+
->method('getDescriptor')
24+
->with(RepositoryInterface::OPTION_XML_EXPORT_SUPPORTED)
25+
->will($this->returnValue(true));
26+
$this->session->expects($this->once())
27+
->method('exportSystemView');
28+
29+
$ct = $this->executeCommand('phpcr:workspace:export', array(
30+
'filename' => 'test'
31+
));
32+
}
33+
}
34+
35+
36+
37+

0 commit comments

Comments
 (0)