Skip to content

Add option to not process existing workspace as error #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/PHPCR/Util/Console/Command/WorkspaceCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPCR\RepositoryInterface;
use PHPCR\SessionInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -28,6 +29,12 @@ protected function configure()
$this
->setName('phpcr:workspace:create')
->addArgument('name', InputArgument::REQUIRED, 'Name of the workspace to create')
->addOption(
'ignore-existing',
null,
InputOption::VALUE_NONE,
'If set, an existing workspace will return a success code'
)
->setDescription('Create a workspace in the configured repository')
->setHelp(<<<EOT
The <info>workspace:create</info> command creates a workspace with the specified name.
Expand Down Expand Up @@ -65,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
sprintf('<comment>This repository already has a workspace called "%s"</comment>', $workspaceName)
);

return 2;
return $input->getOption('ignore-existing') ? 0 : 2;
}

$workspace->createWorkspace($workspaceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ public function testCreate()
*/
public function testCreateExisting()
{
$this->session->expects($this->once())
$this->session->expects($this->exactly(2))
->method('getWorkspace')
->will($this->returnValue($this->workspace))
;
$this->session->expects($this->once())
$this->session->expects($this->exactly(2))
->method('getRepository')
->will($this->returnValue($this->repository));
$this->repository->expects($this->once())
$this->repository->expects($this->exactly(2))
->method('getDescriptor')
->with(RepositoryInterface::OPTION_WORKSPACE_MANAGEMENT_SUPPORTED)
->will($this->returnValue(true))
;
$this->workspace->expects($this->once())
$this->workspace->expects($this->exactly(2))
->method('getAccessibleWorkspaceNames')
->will($this->returnValue(array('default', 'test')))
;
Expand All @@ -73,5 +73,16 @@ public function testCreateExisting()
);

$this->assertContains('already has a workspace called "test"', $tester->getDisplay());

$tester = $this->executeCommand(
'phpcr:workspace:create',
array(
'name' => 'test',
'--ignore-existing' => true
),
0
);

$this->assertContains('already has a workspace called "test"', $tester->getDisplay());
}
}