Skip to content

Commit 42ef6c2

Browse files
committed
Fully form forwarded exception
1 parent b3a1734 commit 42ef6c2

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

features/search-replace.feature

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,16 +1106,57 @@ Feature: Do global search/replace
11061106
a:1:{i:0;O:10:"CornFlakes":0:{}}
11071107
"""
11081108

1109-
@less-than-php-8.1
1110-
Scenario: Warn and ignore type-hinted objects that have some error in deserialization (PHP < 8.1)
1109+
@less-than-php-8.0
1110+
Scenario: Warn and ignore type-hinted objects that have some error in deserialization (PHP < 8.0)
11111111
Given a WP install
11121112
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;}')"`
11131113
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;}')"`
11141114

11151115
When I try `wp search-replace mysqli_result stdClass`
11161116
Then STDERR should contain:
11171117
"""
1118-
Warning: Warning: Skipping an inconvertible serialized object of type "mysqli_result", replacements might not be complete. Reason: mysqli_result object is already closed.
1118+
Warning: Skipping an inconvertible serialized object of type "mysqli_result", replacements might not be complete. Reason: mysqli_result object is already closed.
1119+
"""
1120+
And STDOUT should contain:
1121+
"""
1122+
Success: Made 1 replacement.
1123+
"""
1124+
1125+
When I run `wp db query "SELECT option_value from wp_options where option_name='cereal_isation_2'" --skip-column-names`
1126+
Then STDOUT should contain:
1127+
"""
1128+
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;}
1129+
"""
1130+
Then save STDOUT as {SERIALIZED_RESULT}
1131+
And a test_php.php file:
1132+
"""
1133+
<?php print_r(unserialize('{SERIALIZED_RESULT}'));
1134+
"""
1135+
1136+
When I try `wp eval-file test_php.php`
1137+
Then STDOUT should contain:
1138+
"""
1139+
stdClass Object
1140+
"""
1141+
Then STDOUT should contain:
1142+
"""
1143+
[current_field] => 1
1144+
"""
1145+
Then STDOUT should contain:
1146+
"""
1147+
[field_count] => 2
1148+
"""
1149+
1150+
@requires-php-8.0 @less-than-php-8.1
1151+
Scenario: Warn and ignore type-hinted objects that have some error in deserialization (PHP 8.0)
1152+
Given a WP install
1153+
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;}')"`
1154+
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;}')"`
1155+
1156+
When I try `wp search-replace mysqli_result stdClass`
1157+
Then STDERR should contain:
1158+
"""
1159+
Warning: Skipping an inconvertible serialized object of type "mysqli_result", replacements might not be complete. Reason: mysqli_result object is already closed.
11191160
"""
11201161
And STDOUT should contain:
11211162
"""

src/WP_CLI/SearchReplacer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private function run_recursively( $data, $serialised, $recursion_level = 0, $vis
133133
)
134134
);
135135

136-
throw new Exception();
136+
throw new Exception( $exception->getMessage(), $exception->getCode(), $exception );
137137
}
138138
}
139139
} elseif ( is_string( $data ) ) {

0 commit comments

Comments
 (0)