Skip to content

Commit 28a4234

Browse files
committed
Using property aliases when generating JSON Patch representation.
1 parent 49d5ed8 commit 28a4234

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/OpenCloud/Common/Resource/PersistentResource.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ protected function generateJsonPatch($updatedProperties)
375375
}
376376
}
377377

378+
// Recursively alias current and updated properties
379+
$currentProperties = $this->recursivelyAliasPropertyValue($currentProperties);
380+
$updatedProperties = $this->recursivelyAliasPropertyValue($updatedProperties);
381+
378382
// Generate JSON Patch representation
379383
$json = json_encode(JsonPatch::diff($currentProperties, $updatedProperties));
380384
$this->checkJsonError();

tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public function testGenerateJsonPatch()
165165
array('origin' => 'origin1.phpopencloud.com')
166166
);
167167
$this->persistentResource->status = array('message' => 'Creation in progress');
168+
$this->persistentResource->baz = (object) array( 'fooBar' => 'barbar');
168169

169170
$updateParams = array(
170171
'tags' => array('foo', 'qux', 'baz'),
@@ -174,10 +175,12 @@ public function testGenerateJsonPatch()
174175
'origins' => array(
175176
array('origin' => 'origin1.phpopencloud.com'),
176177
array('origin' => 'origin2.phpopencloud.com')
177-
)
178+
),
179+
'baz' => array('fooBar' => 'barbarbar')
178180
);
179181

180182
$expectedJsonPatch = json_encode(array(
183+
array('op' => 'replace', 'path' => '/baz/foo_bar', 'value' => 'barbarbar'),
181184
array('op' => 'add', 'path' => '/tags/2', 'value' => 'baz'),
182185
array('op' => 'replace', 'path' => '/tags/1', 'value' => 'qux'),
183186
array('op' => 'remove', 'path' => '/domains/1'),

0 commit comments

Comments
 (0)