Skip to content

Commit a353d96

Browse files
Add test cases for object modification behavior
1 parent 4c5c736 commit a353d96

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

features/option-pluck-patch.feature

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,33 @@ Feature: Option commands have pluck and patch.
269269
"""
270270
[ "new", "bar" ]
271271
"""
272+
273+
@patch @pluck
274+
Scenario: An object value can be updated
275+
Given a WP install
276+
And a setup.php file:
277+
"""
278+
<?php
279+
$option = new stdClass;
280+
$option->test_mode = 0;
281+
$ret = update_option( 'wp_cli_test', $option );
282+
"""
283+
And I run `wp eval-file setup.php`
284+
285+
When I run `wp option pluck wp_cli_test test_mode`
286+
Then STDOUT should be:
287+
"""
288+
0
289+
"""
290+
291+
When I run `wp option patch update wp_cli_test test_mode 1`
292+
Then STDOUT should be:
293+
"""
294+
Success: Updated 'wp_cli_test' option.
295+
"""
296+
297+
When I run `wp option pluck wp_cli_test test_mode`
298+
Then STDOUT should be:
299+
"""
300+
1
301+
"""

tests/RecursiveDataStructureTraverserTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ function it_can_set_a_nested_object_value() {
8686
$this->assertEquals( 'new', $object->foo->bar );
8787
}
8888

89+
/** @test */
90+
function it_can_update_an_integer_object_value() {
91+
$object = (object) array(
92+
'test_mode' => 0,
93+
);
94+
$this->assertEquals( 0, $object->test_mode );
95+
96+
$traverser = new RecursiveDataStructureTraverser( $object );
97+
$traverser->update( array( 'test_mode' ), 1 );
98+
99+
$this->assertEquals( 1, $object->test_mode );
100+
}
101+
89102
/** @test */
90103
function it_can_delete_a_nested_array_value() {
91104
$array = array(

0 commit comments

Comments
 (0)