Skip to content

Commit

Permalink
Split into two separate tests per PHP version
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Dec 18, 2023
1 parent 251042b commit b3a1734
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion features/search-replace.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,49 @@ Feature: Do global search/replace
a:1:{i:0;O:10:"CornFlakes":0:{}}
"""

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

When I try `wp search-replace mysqli_result stdClass`
Then STDERR should contain:
"""
Warning: Warning: Skipping an inconvertible serialized object of type "mysqli_result", replacements might not be complete. Reason: mysqli_result object is already closed.
"""
And STDOUT should contain:
"""
Success: Made 1 replacement.
"""

When I run `wp db query "SELECT option_value from wp_options where option_name='cereal_isation_2'" --skip-column-names`
Then STDOUT should contain:
"""
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;}
"""
Then save STDOUT as {SERIALIZED_RESULT}
And a test_php.php file:
"""
<?php print_r(unserialize('{SERIALIZED_RESULT}'));
"""

When I try `wp eval-file test_php.php`
Then STDOUT should contain:
"""
stdClass Object
"""
Then STDOUT should contain:
"""
[current_field] => 1
"""
Then STDOUT should contain:
"""
[field_count] => 2
"""

@require-php-8.1
Scenario: Warn and ignore type-hinted objects that have some error in deserialization (PHP 8.1+)
Given a WP install
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;}')"`
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;}')"`
Expand Down

0 comments on commit b3a1734

Please sign in to comment.