Skip to content

Commit d6437f2

Browse files
committed
removing array cast & testing serialized, safe object to confirm serialization was successful
1 parent 6ff1d6b commit d6437f2

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

features/search-replace.feature

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,6 @@ Feature: Do global search/replace
11071107
"""
11081108

11091109
Scenario: Warn and ignore type-hinted objects that have some error in deserialization
1110-
11111110
Given a WP install
11121111
And I run `wp db query "INSERT INTO wp_options (option_name,option_value) VALUES ('cereal_isation','O:13:\"mysqli_result\":5:{s:13:\"current_field\";N;s:11:\"field_count\";N;s:7:\"lengths\";N;s:8:\"num_rows\";N;s:4:\"type\";N;}')"`
11131112
And I run `wp db query "INSERT INTO wp_options (option_name,option_value) VALUES ('cereal_isation_2','O:8:\"mysqli_result\":5:{s:13:\"current_field\";i:1;s:11:\"field_count\";i:2;s:7:\"lengths\";a:1:{i:0;s:4:\"blah\";}s:8:\"num_rows\";i:1;s:4:\"type\";i:2;}')"`
@@ -1122,11 +1121,30 @@ Feature: Do global search/replace
11221121
Success: Made 1 replacement.
11231122
"""
11241123

1125-
When I run `wp db query "SELECT option_value from wp_options where option_name='cereal_isation_2'"`
1124+
When I run `wp db query "SELECT option_value from wp_options where option_name='cereal_isation_2'" --skip-column-names`
11261125
Then STDOUT should contain:
11271126
"""
11281127
O:8:"stdClass":5:{s:13:"current_field";i:1;s:11:"field_count";i:2;s:7:"lengths";a:1:{i:0;s:4:"blah";}s:8:"num_rows";i:1;s:4:"type";i:2;}
11291128
"""
1129+
Then save STDOUT as {SERIALIZED_RESULT}
1130+
And a test_php.php file:
1131+
"""
1132+
<?php print_r(unserialize('{SERIALIZED_RESULT}'));
1133+
"""
1134+
1135+
When I try `wp eval-file test_php.php`
1136+
Then STDOUT should contain:
1137+
"""
1138+
stdClass Object
1139+
"""
1140+
Then STDOUT should contain:
1141+
"""
1142+
[current_field] => 1
1143+
"""
1144+
Then STDOUT should contain:
1145+
"""
1146+
[field_count] => 2
1147+
"""
11301148

11311149
Scenario: Regex search/replace with `--regex-limit=1` option
11321150
Given a WP install

src/WP_CLI/SearchReplacer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private function run_recursively( $data, $serialised, $recursion_level = 0, $vis
119119
)
120120
);
121121
} else {
122-
foreach ( (array) $data as $key => $value ) {
122+
foreach ( $data as $key => $value ) {
123123
$data->$key = $this->run_recursively( $value, false, $recursion_level + 1, $visited_data );
124124
}
125125
}

0 commit comments

Comments
 (0)