Skip to content

Commit

Permalink
Merge pull request #137 from webda2l/create-workspace
Browse files Browse the repository at this point in the history
Add option to not process existing workspace as error
  • Loading branch information
dbu committed Nov 14, 2014
2 parents 08fd6d8 + d4c8c02 commit 72e8865
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
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());
}
}

0 comments on commit 72e8865

Please sign in to comment.