Skip to content

Commit 72e8865

Browse files
committed
Merge pull request #137 from webda2l/create-workspace
Add option to not process existing workspace as error
2 parents 08fd6d8 + d4c8c02 commit 72e8865

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPCR\RepositoryInterface;
66
use PHPCR\SessionInterface;
77
use Symfony\Component\Console\Command\Command;
8+
use Symfony\Component\Console\Input\InputOption;
89
use Symfony\Component\Console\Input\InputArgument;
910
use Symfony\Component\Console\Input\InputInterface;
1011
use Symfony\Component\Console\Output\OutputInterface;
@@ -28,6 +29,12 @@ protected function configure()
2829
$this
2930
->setName('phpcr:workspace:create')
3031
->addArgument('name', InputArgument::REQUIRED, 'Name of the workspace to create')
32+
->addOption(
33+
'ignore-existing',
34+
null,
35+
InputOption::VALUE_NONE,
36+
'If set, an existing workspace will return a success code'
37+
)
3138
->setDescription('Create a workspace in the configured repository')
3239
->setHelp(<<<EOT
3340
The <info>workspace:create</info> command creates a workspace with the specified name.
@@ -65,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6572
sprintf('<comment>This repository already has a workspace called "%s"</comment>', $workspaceName)
6673
);
6774

68-
return 2;
75+
return $input->getOption('ignore-existing') ? 0 : 2;
6976
}
7077

7178
$workspace->createWorkspace($workspaceName);

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ public function testCreate()
4949
*/
5050
public function testCreateExisting()
5151
{
52-
$this->session->expects($this->once())
52+
$this->session->expects($this->exactly(2))
5353
->method('getWorkspace')
5454
->will($this->returnValue($this->workspace))
5555
;
56-
$this->session->expects($this->once())
56+
$this->session->expects($this->exactly(2))
5757
->method('getRepository')
5858
->will($this->returnValue($this->repository));
59-
$this->repository->expects($this->once())
59+
$this->repository->expects($this->exactly(2))
6060
->method('getDescriptor')
6161
->with(RepositoryInterface::OPTION_WORKSPACE_MANAGEMENT_SUPPORTED)
6262
->will($this->returnValue(true))
6363
;
64-
$this->workspace->expects($this->once())
64+
$this->workspace->expects($this->exactly(2))
6565
->method('getAccessibleWorkspaceNames')
6666
->will($this->returnValue(array('default', 'test')))
6767
;
@@ -73,5 +73,16 @@ public function testCreateExisting()
7373
);
7474

7575
$this->assertContains('already has a workspace called "test"', $tester->getDisplay());
76+
77+
$tester = $this->executeCommand(
78+
'phpcr:workspace:create',
79+
array(
80+
'name' => 'test',
81+
'--ignore-existing' => true
82+
),
83+
0
84+
);
85+
86+
$this->assertContains('already has a workspace called "test"', $tester->getDisplay());
7687
}
7788
}

0 commit comments

Comments
 (0)