Skip to content

Commit 9d9e560

Browse files
committed
Removed array tests
1 parent 5bc8e1a commit 9d9e560

File tree

6 files changed

+42
-80
lines changed

6 files changed

+42
-80
lines changed

spec/PHPCR/Shell/Query/UpdateParserSpec.php

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -69,77 +69,18 @@ function it_should_provide_a_qom_object_for_selecting(
6969
$res->offsetGet(0)->shouldHaveType('PHPCR\Query\QueryInterface');
7070
$res->offsetGet(1)->shouldReturn(array(
7171
array(
72-
'array_op' => null,
7372
'selector' => 'parent',
7473
'name' => 'foo',
7574
'value' => 'PHPCR\\FOO\\Bar',
7675
),
7776
array(
78-
'array_op' => null,
7977
'selector' => 'parent',
8078
'name' => 'bar',
8179
'value' => 'foo',
8280
),
8381
));
8482
}
8583

86-
function it_should_parse_array_values (
87-
QueryObjectModelFactoryInterface $qomf,
88-
ChildNodeJoinConditionInterface $joinCondition,
89-
JoinInterface $join,
90-
SourceInterface $source,
91-
PropertyValueInterface $tagsValue,
92-
LiteralInterface $literalValue,
93-
ComparisonInterface $comparison,
94-
QueryInterface $query
95-
)
96-
{
97-
$qomf->selector('a', 'dtl:article')->willReturn($source);
98-
$qomf->createQuery($source, null)->willReturn($query);
99-
100-
101-
$sql = <<<EOT
102-
UPDATE [dtl:article] AS a SET a.tags = ['one', 'two', 'three']
103-
EOT;
104-
$res = $this->parse($sql);
105-
106-
$res->offsetGet(0)->shouldHaveType('PHPCR\Query\QueryInterface');
107-
$res->offsetGet(1)->shouldReturn(array(
108-
array(
109-
'array_op' => null,
110-
'selector' => 'a',
111-
'name' => 'tags',
112-
'value' => array('one', 'two', 'three'),
113-
),
114-
));
115-
}
116-
117-
function it_should_parse_array_addition (
118-
QueryObjectModelFactoryInterface $qomf,
119-
SourceInterface $source,
120-
QueryInterface $query
121-
)
122-
{
123-
$qomf->selector('a', 'dtl:article')->willReturn($source);
124-
$qomf->createQuery($source, null)->willReturn($query);
125-
126-
127-
$sql = <<<EOT
128-
UPDATE [dtl:article] AS a SET a.tags[] = 'asd'
129-
EOT;
130-
$res = $this->parse($sql);
131-
132-
$res->offsetGet(0)->shouldHaveType('PHPCR\Query\QueryInterface');
133-
$res->offsetGet(1)->shouldReturn(array(
134-
array(
135-
'array_op' => 'add',
136-
'selector' => 'a',
137-
'name' => 'tags',
138-
'value' => 'asd',
139-
),
140-
));
141-
}
142-
14384
function it_should_parse_functions (
14485
QueryObjectModelFactoryInterface $qomf,
14586
SourceInterface $source,
@@ -151,7 +92,7 @@ function it_should_parse_functions (
15192

15293

15394
$sql = <<<EOT
154-
UPDATE [dtl:article] AS a SET a.tags[] = array_replace(a.tags, 'asd', 'dsa')
95+
UPDATE [dtl:article] AS a SET a.tags = array_replace(a.tags, 'asd', 'dsa')
15596
EOT;
15697
$res = $this->parse($sql);
15798

src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ public function execute(InputInterface $input, OutputInterface $output)
6161

6262
$currentNode = $session->getNodeByPathOrIdentifier($path);
6363

64-
echo $currentNode->getIndex()."\n";
65-
6664
if (!$this->showChildren && !$this->showProperties) {
6765
$this->showChildren = true;
6866
$this->showProperties = true;

src/PHPCR/Shell/Console/Command/Phpcr/QueryUpdateCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ protected function configure()
3232
You can also manipulate multivalue fields:
3333
3434
# Delete index
35-
UPDATE [nt:unstructured] SET a.tags[0] = NULL
3635
37-
# Set index
38-
UPDATE [nt:unstructured] SET a.tags[0] = 'foo'
3936
4037
And you have access to a set of functions when assigning a value:
4138
39+
# Delete a multivalue index
40+
UPDATE [nt:unstructured] SET a.tags = array_set(a.tags, 0, NULL)
41+
42+
# Set a multivalue index
43+
UPDATE [nt:unstructured] SET a.tags = array_set(a.tags, 0, 'foo')
44+
4245
# Replace the multivalue value "Planes" with "Trains"
4346
UPDATE [nt:unstructured] AS a SET a.tags[] = array_replace(a.tags, 'Planes', 'Trains')
4447

src/PHPCR/Shell/Query/FunctionOperand.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public function __construct($functionName, $arguments)
2222
$this->arguments = $arguments;
2323
}
2424

25+
/**
26+
* Replace the Operand objects with their evaluations
27+
*
28+
* @param array Array of function closures
29+
* @param RowInterface $row
30+
*/
2531
private function replaceColumnOperands($functionMap, RowInterface $row)
2632
{
2733
foreach ($this->arguments as $key => $value) {
@@ -35,11 +41,17 @@ private function replaceColumnOperands($functionMap, RowInterface $row)
3541
}
3642
}
3743

38-
public function execute($functionMap, $row, $value)
44+
/**
45+
* Evaluate the result of the function
46+
*
47+
* @param array Array of function closures
48+
* @param RowInterface $row
49+
*/
50+
public function execute($functionMap, $row)
3951
{
4052
$this->replaceColumnOperands($functionMap, $row);
4153

42-
$functionName = $value->getFunctionName();
54+
$functionName = $this->getFunctionName();
4355
if (!isset($functionMap[$functionName])) {
4456
throw new InvalidQueryException(sprintf('Unknown function "%s", known functions are "%s"',
4557
$functionName,
@@ -48,13 +60,19 @@ public function execute($functionMap, $row, $value)
4860
}
4961

5062
$callable = $functionMap[$functionName];
51-
$args = $value->getArguments();
63+
$args = $this->getArguments();
5264
array_unshift($args, $this);
5365
$value = call_user_func_array($callable, $args);
5466

5567
return $value;
5668
}
5769

70+
/**
71+
* Used as callback for closure functions
72+
*
73+
* @param array Array of values which must be scalars
74+
* @throws InvalidArgumentException
75+
*/
5876
public function validateScalarArray($array)
5977
{
6078
if (!is_array($array)) {
@@ -74,12 +92,21 @@ public function validateScalarArray($array)
7492
}
7593
}
7694

77-
95+
/**
96+
* Return the name of the function to execute
97+
*
98+
* @return string
99+
*/
78100
public function getFunctionName()
79101
{
80102
return $this->functionName;
81103
}
82104

105+
/**
106+
* Return the functions arguments
107+
*
108+
* @return mixed
109+
*/
83110
public function getArguments()
84111
{
85112
return $this->arguments;

src/PHPCR/Shell/Query/UpdateParser.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
*/
1919
class UpdateParser extends Sql2ToQomQueryConverter
2020
{
21-
// Instruction for update operations to add array values
22-
const ARRAY_OPERATION_ADD = 'add';
23-
24-
// Instruction for update operations to subsitute values
25-
const ARRAY_OPERATION_SUB = 'sub';
26-
2721
public function parse($sql2)
2822
{
2923
$this->scanner = new Sql2Scanner($sql2);
@@ -96,7 +90,6 @@ private function parseUpdates()
9690

9791
while (true) {
9892
$property = array(
99-
'array_op' => null,
10093
'selector' => null,
10194
'name' => null,
10295
'value' => null

src/PHPCR/Shell/Query/UpdateProcessor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class UpdateProcessor
1717
*
1818
* @var \Closure[]
1919
*/
20-
protected $functionMap = array();
20+
private $functionMap = array();
2121

2222
public function __construct()
2323
{
@@ -95,7 +95,7 @@ public function updateNode(RowInterface $row, $propertyData)
9595
$node->setProperty($propertyData['name'], $value);
9696
}
9797

98-
protected function handleExisting($row, $node, $propertyData)
98+
private function handleExisting($row, $node, $propertyData)
9999
{
100100
$phpcrProperty = $node->getProperty($propertyData['name']);
101101
$value = $propertyData['value'];
@@ -107,12 +107,12 @@ protected function handleExisting($row, $node, $propertyData)
107107
return $value;
108108
}
109109

110-
protected function handleFunction($row, $node, $phpcrProperty, $propertyData)
110+
private function handleFunction($row, $node, $phpcrProperty, $propertyData)
111111
{
112112
$currentValue = $phpcrProperty->getValue();
113113
$value = $propertyData['value'];
114114

115-
$value = $value->execute($this->functionMap, $row, $value);
115+
$value = $value->execute($this->functionMap, $row);
116116

117117
if ($phpcrProperty->isMultiple()) {
118118
// do not allow updating multivalue with scalar

0 commit comments

Comments
 (0)