diff --git a/src/PHPCR/Util/Console/Command/BaseCommand.php b/src/PHPCR/Util/Console/Command/BaseCommand.php new file mode 100644 index 0000000..f399b80 --- /dev/null +++ b/src/PHPCR/Util/Console/Command/BaseCommand.php @@ -0,0 +1,49 @@ +getHelper('phpcr')->getSession(); + } + + /** + * @return PHPCR\Util\Console\Helper\PhpcrCliHelper + */ + protected function getPhpcrCliHelper() + { + $phpcrCliHelper = new PhpcrCliHelper($this->getPhpcrSession()); + return $phpcrCliHelper; + } + + public function configureNodeManipulationInput() + { + $this->addOption('set-prop', 'p', + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'Set node property on nodes use foo=bar' + ); + $this->addOption('remove-prop', 'r', + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'Remove property from nodes' + ); + $this->addOption('add-mixin', null, + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'Add a mixin to the nodes' + ); + $this->addOption('remove-mixin', null, + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'Remove mixin from the nodes' + ); + } +} diff --git a/src/PHPCR/Util/Console/Command/NodeDumpCommand.php b/src/PHPCR/Util/Console/Command/NodeDumpCommand.php index 97625aa..fdc5d3a 100644 --- a/src/PHPCR/Util/Console/Command/NodeDumpCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeDumpCommand.php @@ -22,7 +22,6 @@ namespace PHPCR\Util\Console\Command; use PHPCR\Util\UUIDHelper; -use Symfony\Component\Console\Command\Command; use PHPCR\ItemNotFoundException; use PHPCR\RepositoryException; use PHPCR\PathNotFoundException; @@ -42,7 +41,7 @@ * @author Daniel Barsotti * @author Daniel Leech */ -class NodeDumpCommand extends Command +class NodeDumpCommand extends BaseCommand { /** * Limit after which to cut lines when dumping properties @@ -65,7 +64,7 @@ protected function configure() ->addOption('ref-format', 'uuid', InputOption::VALUE_REQUIRED, 'Set the way references should be displayed when dumping reference properties - either "uuid" (default) or "path"') ->addArgument('identifier', InputArgument::OPTIONAL, 'Root path to dump', '/') ->setDescription('Dump subtrees of the content repository') - ->setHelp(<<setHelp(<<dump command recursively outputs the name of the node specified by the identifier argument and its subnodes in a yaml-like style. @@ -75,7 +74,7 @@ protected function configure() By default the command filters out system nodes and properties (i.e. nodes and properties with names starting with 'jcr:'), the sys_nodes option allows to turn this filter off. -EOF +HERE ) ; } @@ -95,7 +94,7 @@ public function setDumpMaxLineLength($length) */ protected function execute(InputInterface $input, OutputInterface $output) { - $session = $this->getHelper('phpcr')->getSession(); + $session = $this->getPhpcrSession(); $dumperHelper = $this->getHelper('phpcr_console_dumper'); // node to dump diff --git a/src/PHPCR/Util/Console/Command/NodeTouchCommand.php b/src/PHPCR/Util/Console/Command/NodeTouchCommand.php index 4dfe17b..b7dc4b9 100644 --- a/src/PHPCR/Util/Console/Command/NodeTouchCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeTouchCommand.php @@ -36,7 +36,7 @@ * * @author Daniel Leech */ -class NodeTouchCommand extends Command +class NodeTouchCommand extends BaseCommand { /** * {@inheritDoc} @@ -45,6 +45,8 @@ protected function configure() { parent::configure(); + $this->configureNodeManipulationInput(); + $this->setName('phpcr:node:touch') ->addArgument( 'path', @@ -57,26 +59,10 @@ protected function configure() 'Node type, default nt:unstructured', 'nt:unstructured' ) - ->addOption('set-prop', 'p', - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'Set node property, use foo=bar' - ) - ->addOption('remove-prop', 'r', - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'Remove node property' - ) ->addOption('dump', 'd', InputOption::VALUE_NONE, 'Dump a string reperesentation of the created / modified node.' ) - ->addOption('add-mixin', null, - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'Add a mixin to the node' - ) - ->addOption('remove-mixin', null, - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'Add a mixin to the node' - ) ->setDescription('Create or modify a node') ->setHelp(<<getHelper('phpcr')->getSession(); + $helper = $this->getPhpcrCliHelper(); + $session = $this->getPhpcrSession(); $path = $input->getArgument('path'); $type = $input->getOption('type'); + $dump = $input->getOption('dump'); + $setProp = $input->getOption('set-prop'); $removeProp = $input->getOption('remove-prop'); - $dump = $input->getOption('dump'); $addMixins = $input->getOption('add-mixin'); $removeMixins = $input->getOption('remove-mixin'); @@ -155,45 +142,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $node = $parentNode->addNode($nodeName, $type); } - foreach ($setProp as $set) { - $parts = explode('=', $set); - $output->writeln(sprintf( - ' > Setting property %s to %s', - $parts[0], $parts[1] - )); - $node->setProperty($parts[0], $parts[1]); - } - - foreach ($removeProp as $unset) { - $output->writeln(sprintf( - ' > Unsetting property %s', - $unset - )); - $node->setProperty($unset, null); - } - - foreach ($addMixins as $addMixin) { - $node->addMixin($addMixin); - } - - foreach ($removeMixins as $removeMixin) { - $node->removeMixin($removeMixin); - } - - if ($dump) { - $output->writeln('Node dump: '); - /** @var $property PropertyInterface */ - foreach ($node->getProperties() as $property) { - $value = $property->getValue(); - if (!is_string($value)) { - $value = print_r($value, true); - } - $output->writeln(sprintf(' - %s = %s', - $property->getName(), - $value - )); - } - } + $helper->processNode($output, $node, array( + 'setProps' => $setProp, + 'removeProps' => $removeProp, + 'addMixins' => $addMixins, + 'removeMixins' => $removeMixins, + 'dump' => $dump, + )); $session->save(); } diff --git a/src/PHPCR/Util/Console/Command/NodeTypeListCommand.php b/src/PHPCR/Util/Console/Command/NodeTypeListCommand.php index 8bace82..d6c3fd4 100644 --- a/src/PHPCR/Util/Console/Command/NodeTypeListCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeTypeListCommand.php @@ -30,7 +30,7 @@ * * @author Daniel Leech */ -class NodeTypeListCommand extends Command +class NodeTypeListCommand extends BaseCommand { /** * {@inheritDoc} @@ -53,7 +53,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $session = $this->getHelper('phpcr')->getSession(); + $session = $this->getPhpcrSession(); $ntm = $session->getWorkspace()->getNodeTypeManager(); $nodeTypes = $ntm->getAllNodeTypes(); diff --git a/src/PHPCR/Util/Console/Command/NodeTypeRegisterCommand.php b/src/PHPCR/Util/Console/Command/NodeTypeRegisterCommand.php index 9ef93f0..f969aba 100644 --- a/src/PHPCR/Util/Console/Command/NodeTypeRegisterCommand.php +++ b/src/PHPCR/Util/Console/Command/NodeTypeRegisterCommand.php @@ -39,7 +39,7 @@ * * @author Uwe Jäger */ -class NodeTypeRegisterCommand extends Command +class NodeTypeRegisterCommand extends BaseCommand { /** * {@inheritDoc} @@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $cnd = file_get_contents($cnd_file); $allowUpdate = $input->getOption('allow-update'); - $session = $this->getHelper('phpcr')->getSession(); + $session = $this->getPhpcrSession(); try { $this->updateFromCnd($output, $session, $cnd, $allowUpdate); diff --git a/src/PHPCR/Util/Console/Command/NodesUpdateCommand.php b/src/PHPCR/Util/Console/Command/NodesUpdateCommand.php new file mode 100644 index 0000000..ffcb956 --- /dev/null +++ b/src/PHPCR/Util/Console/Command/NodesUpdateCommand.php @@ -0,0 +1,167 @@ + + */ +class NodesUpdateCommand extends BaseCommand +{ + /** + * {@inheritDoc} + */ + protected function configure() + { + parent::configure(); + + $this->configureNodeManipulationInput(); + + $this->setName('phpcr:nodes:update') + ->addOption( + 'query', null, + InputOption::VALUE_REQUIRED, + 'Query used to select the nodes' + ) + ->addOption( + 'query-language', 'l', + InputOption::VALUE_OPTIONAL, + 'The query language (e.g. sql, jcr_sql2)', + 'jcr-sql2' + ) + ->setDescription('Command to manipulate the nodes in the workspace.') + ->setHelp(<<phpcr:nodes:update can manipulate the properties of nodes +found using the given query. + +For example, to set the property "foo" to "bar" on all unstructured nodes: + + php bin/phpcr phpcr:nodes:update --query="SELECT * FROM [nt:unstructured]" --set-prop=foo=bar + +Or to update only nodes matching a certain criteria: + + php bin/phpcr nodes:update --query="SELECT * FROM [nt:unstructured] WHERE [phpcr:class]=\"Some\\Class\\Here\" --add-mixin=mix:mimetype + +The options for manipulating nodes are the same as with the +node:touch command and +can be repeated to update multiple properties. +HERE +); + } + + /** + * {@inheritDoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->dialog = new DialogHelper(); + + $query = $input->getOption('query'); + $queryLanguage = strtoupper($input->getOption('query-language')); + $setProp = $input->getOption('set-prop'); + $removeProp = $input->getOption('remove-prop'); + $addMixins = $input->getOption('add-mixin'); + $removeMixins = $input->getOption('remove-mixin'); + $noInteraction = $input->getOption('no-interaction'); + $helper = $this->getPhpcrCliHelper(); + $session = $this->getPhpcrSession(); + + if (!$query) { + throw new \InvalidArgumentException( + 'You must provide a SELECT query, e.g. --select="SELECT * FROM [nt:unstructured]"' + ); + } + + if (strtoupper(substr($query, 0, 6) != 'SELECT')) { + throw new \InvalidArgumentException(sprintf( + 'Query doesn\'t look like a SELECT query: "%s"', + $query + )); + } + + $query = $helper->createQuery($queryLanguage, $query); + $result = $query->execute(); + + if (!$noInteraction) { + if (false === $this->getAction($output, $result)) { + return 0; + } + } + + foreach ($result as $i => $row) { + $output->writeln(sprintf( + "Updating node: [%d] %s.", + $i, + $row->getPath() + )); + + $node = $row->getNode(); + + $helper->processNode($output, $node, array( + 'setProp' => $setProp, + 'removeProp' => $removeProp, + 'addMixins' => $addMixins, + 'removeMixins' => $removeMixins, + )); + } + + $output->writeln('Saving session...'); + $session->save(); + $output->writeln('Done.'); + + return 0; + } + + protected function getAction($output, $result) + { + $response = strtoupper($this->dialog->ask($output, sprintf( + 'About to update %d nodes. Enter "Y" to continue, "N" to cancel or "L" to list.', + count($result->getRows()) + ), false)); + + if ($response == 'L') { + foreach ($result as $i => $row) { + $output->writeln(sprintf(' - [%d] %s', $i, $row->getPath())); + } + + return $this->getAction($output, $result); + } + + if ($response == 'N') { + return false; + } + + if ($response == 'Y') { + return true; + } + + return $this->getAction($output, $result); + } +} diff --git a/src/PHPCR/Util/Console/Command/WorkspaceQueryCommand.php b/src/PHPCR/Util/Console/Command/WorkspaceQueryCommand.php index 0c85319..df22437 100644 --- a/src/PHPCR/Util/Console/Command/WorkspaceQueryCommand.php +++ b/src/PHPCR/Util/Console/Command/WorkspaceQueryCommand.php @@ -32,8 +32,9 @@ * resulting nodes. * * @author Daniel Barsotti + * @author Daniel Leech */ -class WorkspaceQueryCommand extends Command +class WorkspaceQueryCommand extends BaseCommand { /** * {@inheritDoc} @@ -44,7 +45,7 @@ protected function configure() $this->setName('phpcr:workspace:query') ->addArgument('query', InputArgument::REQUIRED, 'A query statement to execute') - ->addOption('language', 'l', InputOption::VALUE_OPTIONAL, 'The query language (sql, jcr_sql2', 'jcr_sql2') + ->addOption('language', 'l', InputOption::VALUE_OPTIONAL, 'The query language (e.g. jcr-sql2', 'jcr-sql2') ->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'The query limit', 0) ->addOption('offset', null, InputOption::VALUE_OPTIONAL, 'The query offset', 0) ->setDescription('Execute a JCR SQL2 statement') @@ -61,17 +62,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $limit = $input->getOption('limit'); $offset = $input->getOption('offset'); - $session = $this->getHelper('phpcr')->getSession(); - $qm = $session->getWorkspace()->getQueryManager(); + $helper = $this->getPhpcrCliHelper(); + $session = $this->getPhpcrSession(); - if (!defined('\PHPCR\Query\QueryInterface::'.$language)) { - throw new \RuntimeException(sprintf( - "Query language '\\PHPCR\\Query\\QueryInterface::%s' not defined.", - $language - )); - } - - $query = $qm->createQuery($sql, constant('\PHPCR\Query\QueryInterface::'.$language)); + $query = $helper->createQuery($language, $sql); if ($limit) { $query->setLimit($limit); diff --git a/src/PHPCR/Util/Console/Helper/PhpcrCliHelper.php b/src/PHPCR/Util/Console/Helper/PhpcrCliHelper.php new file mode 100644 index 0000000..a2048e3 --- /dev/null +++ b/src/PHPCR/Util/Console/Helper/PhpcrCliHelper.php @@ -0,0 +1,173 @@ +session = $session; + } + + /** + * Get the session + * + * @return SessionInterface + */ + public function getSession() + { + return $this->session; + } + + /** + * {@inheritDoc} + */ + public function getName() + { + return 'phpcr_cli'; + } + + /** + * Process - or update - a given node. + * Provides common processing for both touch + * and update commands. + */ + public function processNode(OutputInterface $output, $node, $options) + { + $options = array_merge(array( + 'setProp' => array(), + 'removeProp' => array(), + 'addMixins' => array(), + 'removeMixins' => array(), + 'dump' => false, + ), $options); + + foreach ($options['setProp'] as $set) { + $parts = explode('=', $set); + $output->writeln(sprintf( + ' > Setting property %s to %s', + $parts[0], $parts[1] + )); + $node->setProperty($parts[0], $parts[1]); + } + + foreach ($options['removeProp'] as $unset) { + $output->writeln(sprintf( + ' > Unsetting property %s', + $unset + )); + $node->setProperty($unset, null); + } + + foreach ($options['addMixins'] as $addMixin) { + $output->writeln(sprintf( + ' > Adding mixin %s', + $addMixin + )); + + $node->addMixin($addMixin); + } + + foreach ($options['removeMixins'] as $removeMixin) { + $output->writeln(sprintf( + ' > Removing mixin %s', + $removeMixin + )); + + $node->removeMixin($removeMixin); + } + + if ($options['dump']) { + $output->writeln('Node dump: '); + /** @var $property PropertyInterface */ + foreach ($node->getProperties() as $property) { + $value = $property->getValue(); + if (!is_string($value)) { + $value = print_r($value, true); + } + $output->writeln(sprintf(' - %s = %s', + $property->getName(), + $value + )); + } + } + } + + /** + * Create a PHPCR query using the given language and + * query string. + * + * @param string Language type - SQL, SQL2 + * @param string JCR Query + * + * @return PHPCR/QueryInterface + */ + public function createQuery($language, $sql) + { + $this->validateQueryLanguage($language); + + $session = $this->getSession(); + $qm = $session->getWorkspace()->getQueryManager(); + $language = strtoupper($language); + $query = $qm->createQuery($sql, $language); + + return $query; + } + + /** + * Validate the given query language. + * + * @param string Language type + * + * @return null + */ + protected function validateQueryLanguage($language) + { + $qm = $this->getSession()->getWorkspace()->getQueryManager(); + $langs = $qm->getSupportedQueryLanguages(); + if (!in_array($language, $langs)) { + throw new \Exception(sprintf( + 'Query language "%s" not supported, available query languages: %s', + $language, implode(',', $langs) + )); + } + } +} diff --git a/src/PHPCR/Util/Console/Helper/PhpcrHelper.php b/src/PHPCR/Util/Console/Helper/PhpcrHelper.php index d9c1ea3..3cb5db3 100644 --- a/src/PHPCR/Util/Console/Helper/PhpcrHelper.php +++ b/src/PHPCR/Util/Console/Helper/PhpcrHelper.php @@ -23,6 +23,7 @@ use Symfony\Component\Console\Helper\Helper; use PHPCR\SessionInterface; +use Symfony\Component\Console\Output\OutputInterface; /** * Helper class to make the session instance available to console commands diff --git a/test b/test new file mode 100644 index 0000000..e69de29 diff --git a/tests/PHPCR/Tests/Util/Console/Command/Stubs/MockNode.php b/tests/PHPCR/Tests/Stubs/MockNode.php similarity index 66% rename from tests/PHPCR/Tests/Util/Console/Command/Stubs/MockNode.php rename to tests/PHPCR/Tests/Stubs/MockNode.php index 13c3698..ea93721 100644 --- a/tests/PHPCR/Tests/Util/Console/Command/Stubs/MockNode.php +++ b/tests/PHPCR/Tests/Stubs/MockNode.php @@ -1,6 +1,6 @@ session = $this->getMock('PHPCR\SessionInterface'); $this->workspace = $this->getMock('PHPCR\WorkspaceInterface'); $this->repository = $this->getMock('PHPCR\RepositoryInterface'); + $this->queryManager = $this->getMock('PHPCR\Query\QueryManagerInterface'); - $this->node1 = $this->getMock('PHPCR\Tests\Util\Console\Command\Stubs\MockNode'); + $this->row1 = $this->getMock('PHPCR\Tests\Stubs\MockRow'); + $this->node1 = $this->getMock('PHPCR\Tests\Stubs\MockNode'); $this->dumperHelper = $this->getMockBuilder( 'PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper' @@ -54,6 +58,14 @@ public function setUp() ->method('getName') ->will($this->returnValue('test')); + $this->workspace->expects($this->any()) + ->method('getQueryManager') + ->will($this->returnValue($this->queryManager)); + + $this->queryManager->expects($this->any()) + ->method('getSupportedQueryLanguages') + ->will($this->returnValue(array('JCR-SQL2'))); + $this->application = new Application(); $this->application->setHelperSet($this->helperSet); } @@ -71,7 +83,7 @@ public function executeCommand($name, $args, $status = 0) { $command = $this->application->find($name); $commandTester = new CommandTester($command); - $args = $args = array_merge(array( + $args = array_merge(array( 'command' => $command->getName(), ), $args); $this->assertEquals(0, $commandTester->execute($args)); diff --git a/tests/PHPCR/Tests/Util/Console/Command/NodeTypeListCommandTest.php b/tests/PHPCR/Tests/Util/Console/Command/NodeTypeListCommandTest.php index 5e7e13e..e7b28f9 100644 --- a/tests/PHPCR/Tests/Util/Console/Command/NodeTypeListCommandTest.php +++ b/tests/PHPCR/Tests/Util/Console/Command/NodeTypeListCommandTest.php @@ -12,7 +12,7 @@ public function setUp() parent::setUp(); $this->application->add(new NodeTypeListCommand()); $this->nodeTypeManager = $this->getMockBuilder( - 'PHPCR\Tests\Util\Console\Command\Stubs\MockNodeTypeManager' + 'PHPCR\Tests\Stubs\MockNodeTypeManager' )->disableOriginalConstructor()->getMock(); } diff --git a/tests/PHPCR/Tests/Util/Console/Command/NodeTypeRegisterCommandTest.php b/tests/PHPCR/Tests/Util/Console/Command/NodeTypeRegisterCommandTest.php index 7544c2b..b023b72 100644 --- a/tests/PHPCR/Tests/Util/Console/Command/NodeTypeRegisterCommandTest.php +++ b/tests/PHPCR/Tests/Util/Console/Command/NodeTypeRegisterCommandTest.php @@ -5,8 +5,6 @@ use Symfony\Component\Console\Application; use PHPCR\Util\Console\Command\NodeTypeRegisterCommand; -require_once(__DIR__.'/Stubs/MockNodeTypeManager.php'); - class NodeTypeRegisterCommandTest extends BaseCommandTest { public function setUp() @@ -14,7 +12,7 @@ public function setUp() parent::setUp(); $this->application->add(new NodeTypeRegisterCommand()); $this->nodeTypeManager = $this->getMockBuilder( - 'PHPCR\Tests\Util\Console\Command\Stubs\MockNodeTypeManager' + 'PHPCR\Tests\Stubs\MockNodeTypeManager' )->disableOriginalConstructor()->getMock(); } diff --git a/tests/PHPCR/Tests/Util/Console/Command/NodesUpdateCommandTest.php b/tests/PHPCR/Tests/Util/Console/Command/NodesUpdateCommandTest.php new file mode 100644 index 0000000..c5e900f --- /dev/null +++ b/tests/PHPCR/Tests/Util/Console/Command/NodesUpdateCommandTest.php @@ -0,0 +1,131 @@ +application->add(new NodesUpdateCommand()); + $this->query = $this->getMock('PHPCR\Query\QueryInterface'); + } + + public function provideNodeUpdate() + { + return array( + + // no query specified + array(array( + 'exception' => 'InvalidArgumentException', + )), + + // specify query + array(array( + 'query' => 'SELECT * FROM nt:unstructured WHERE foo="bar"', + )), + + // set, remote properties and mixins + array(array( + 'setProp' => array(array('foo', 'bar')), + 'removeProp' => array('bar'), + 'addMixin' => array('mixin1'), + 'removeMixin' => array('mixin1'), + 'query' => 'SELECT * FROM nt:unstructured', + )), + ); + } + + /** + * @dataProvider provideNodeUpdate + */ + public function testNodeUpdate($options) + { + $options = array_merge(array( + 'query' => null, + 'setProp' => array(), + 'removeProp' => array(), + 'addMixin' => array(), + 'removeMixin' => array(), + 'exception' => null, + ), $options); + + if ($options['exception']) { + $this->setExpectedException($options['exception']); + } + + $this->session->expects($this->any()) + ->method('getWorkspace') + ->will($this->returnValue($this->workspace)); + $this->workspace->expects($this->any()) + ->method('getQueryManager') + ->will($this->returnValue($this->queryManager)); + + $this->queryManager->expects($this->any()) + ->method('createQuery') + ->with($options['query'], 'JCR-SQL2') + ->will($this->returnValue($this->query)); + + $this->query->expects($this->any()) + ->method('execute') + ->will($this->returnValue(array( + $this->row1, + ))); + $this->row1->expects($this->any()) + ->method('getNode') + ->will($this->returnValue($this->node1)); + + $args = array( + '--query-language' => null, + '--query' => $options['query'], + '--no-interaction' => true, + '--set-prop' => array(), + '--remove-prop' => array(), + '--add-mixin' => array(), + '--remove-mixin' => array(), + ); + + foreach ($options['setProp'] as $setProp) + { + list($prop, $value) = $setProp; + $this->node1->expects($this->at(0)) + ->method('setProperty') + ->with($prop, $value); + + $args['--set-prop'][] = $prop.'='.$value; + } + + foreach ($options['removeProp'] as $prop) + { + $this->node1->expects($this->at(1)) + ->method('setProperty') + ->with($prop, null); + + $args['--remove-prop'][] = $prop; + } + + foreach ($options['addMixin'] as $mixin) + { + $this->node1->expects($this->once()) + ->method('addMixin') + ->with($mixin); + + $args['--add-mixin'][] = $mixin; + } + + foreach ($options['removeMixin'] as $mixin) + { + $this->node1->expects($this->once()) + ->method('removeMixin') + ->with($mixin); + + $args['--remove-mixin'][] = $mixin; + } + + $ct = $this->executeCommand('phpcr:nodes:update', $args); + } +} diff --git a/tests/PHPCR/Tests/Util/Console/Command/WorkspaceQueryCommandTest.php b/tests/PHPCR/Tests/Util/Console/Command/WorkspaceQueryCommandTest.php index fc2fa1f..f2d329c 100644 --- a/tests/PHPCR/Tests/Util/Console/Command/WorkspaceQueryCommandTest.php +++ b/tests/PHPCR/Tests/Util/Console/Command/WorkspaceQueryCommandTest.php @@ -12,18 +12,18 @@ public function setUp() { parent::setUp(); $this->application->add(new WorkspaceQueryCommand()); - $this->queryManager = $this->getMock( - 'PHPCR\Query\QueryManagerInterface' - ); $this->query = $this->getMock('PHPCR\Query\QueryInterface'); } - public function testNodeTypeQuery() + public function testQuery() { - $this->session->expects($this->once()) + $this->queryManager->expects($this->any()) + ->method('getSupportedQueryLanguages') + ->will($this->returnValue(array('JCR-SQL2'))); + $this->session->expects($this->any()) ->method('getWorkspace') ->will($this->returnValue($this->workspace)); - $this->workspace->expects($this->once()) + $this->workspace->expects($this->any()) ->method('getQueryManager') ->will($this->returnValue($this->queryManager)); $this->queryManager->expects($this->once())