Skip to content

Renamed array_set to array_replace_at #108

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 1 commit into from
Oct 25, 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
10 changes: 5 additions & 5 deletions features/phpcr_query_update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Feature: Execute a a raw UPDATE query in JCR_SQL2
And the node at "/cms/articles/article1" should have the property "tags" with value "Automobiles" at index "1"

Scenario: Remove single multivalue by index
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = array_set(a.tags, 0, NULL) WHERE a.tags = 'Planes'" command
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = array_replace_at(a.tags, 0, NULL) WHERE a.tags = 'Planes'" command
And I save the session
Then the command should not fail
And I should see the following:
Expand All @@ -85,7 +85,7 @@ Feature: Execute a a raw UPDATE query in JCR_SQL2
And the node at "/cms/articles/article1" should have the property "tags" with value "Kite" at index "3"

Scenario: Replace a multivalue property by index
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = array_set(a.tags, 1, 'Kite'), a.tags = array_set(a.tags, 2, 'foobar') WHERE a.tags = 'Planes'" command
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = array_replace_at(a.tags, 1, 'Kite'), a.tags = array_replace_at(a.tags, 2, 'foobar') WHERE a.tags = 'Planes'" command
And I save the session
Then the command should not fail
And I should see the following:
Expand All @@ -97,23 +97,23 @@ Feature: Execute a a raw UPDATE query in JCR_SQL2
And the node at "/cms/articles/article1" should have the property "tags" with value "foobar" at index "2"

Scenario: Replace a multivalue property by invalid index
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = array_set(a.tags, 10, 'Kite') WHERE a.tags = 'Planes'" command
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = array_replace_at(a.tags, 10, 'Kite') WHERE a.tags = 'Planes'" command
Then the command should fail
And I should see the following:
"""
Multivalue index "10" does not exist
"""

Scenario: Attempt to update a numerically named property (must use a selector)
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = array_set(a.tags, a.10, 'Kite') WHERE a.tags = 'Planes'" command
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = array_replace_at(a.tags, a.10, 'Kite') WHERE a.tags = 'Planes'" command
Then the command should fail
And I should see the following:
"""
[PHPCR\PathNotFoundException] Property 10
"""

Scenario: Replace a multivalue property by invalid index with array (invalid)
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = array_set(a.tags, 0, array('Kite')) WHERE a.tags = 'Planes'" command
Given I execute the "UPDATE [nt:unstructured] AS a SET a.tags = array_replace_at(a.tags, 0, array('Kite')) WHERE a.tags = 'Planes'" command
Then the command should fail
And I should see the following:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/PHPCR/Shell/Query/UpdateProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct()
array_shift($values);
return $values;
},
'array_set' => function ($operand, $current, $index, $value) {
'array_replace_at' => function ($operand, $current, $index, $value) {
if (!isset($current[$index])) {
throw new \InvalidArgumentException(sprintf(
'Multivalue index "%s" does not exist',
Expand Down